blezz-tech 1 月之前
父節點
當前提交
f5ecdecd46
共有 2 個文件被更改,包括 11 次插入10 次删除
  1. 2 2
      handlers/EchoBot.py
  2. 9 8
      handlers/main.py

+ 2 - 2
handlers/EchoBot.py

@@ -14,8 +14,8 @@ class JabberBot(slixmpp.ClientXMPP):
 
     def run(self):
         # TODO: Нужно ли
-        self.send_presence()
-        self.get_roster()
+        # self.send_presence()
+        # self.get_roster()
 
         # Register plugins
         self.register_plugin('xep_0030') # Service Discovery

+ 9 - 8
handlers/main.py

@@ -3,6 +3,8 @@ from EchoBot import JabberBot
 import sys
 import logging
 from argparse import ArgumentParser
+import importlib
+import asyncio
 
 if __name__ == '__main__':
     # Setup the command line arguments.
@@ -28,22 +30,21 @@ if __name__ == '__main__':
 
 
     if args.bot and args.bot in config.BOTLIST:
-        module = __import__("handlers." + args.bot)
-
-        print(module.JID)
+        module = importlib.import_module("handlers." + args.bot)
 
         JID = module.JID
         PASSWORD = module.PASSWORD
 
-        fn_start_handler = module.start_handler
-        fn_message = module.message        
+        start_handler = module.start_handler
+        message_handler = module.message_handler        
 
 
         bot = JabberBot(JID, PASSWORD)
-        bot.add_event_handler("message", fn_message)
+        bot.add_event_handler("message", message_handler)
         bot.run()
-        fn_start_handler(bot)
-        bot.stop()
+        start_handler(bot)
+        # bot.stop()
+        asyncio.get_event_loop().run_forever()
     else:
         print("Select using -n flag for select availible bot from botlist:\n")
         for botname in config.BOTLIST: