blezz-tech 1 month ago
parent
commit
b9f8213760
3 changed files with 16 additions and 12 deletions
  1. 0 10
      handlers/EchoBot.py
  2. 3 1
      handlers/handlers/open_basic_bot.py
  3. 13 1
      handlers/main.py

+ 0 - 10
handlers/EchoBot.py

@@ -18,16 +18,6 @@ class JabberBot(slixmpp.ClientXMPP):
         self.register_plugin('xep_0060') # PubSub
         self.register_plugin('xep_0199') # XMPP Ping
 
-    def run(self):
-        # TODO: Нужно ли
-        # self.send_presence()
-        # self.get_roster()
-
-        logging.info(f"Bot {self.jid} started!")
-
-        # Connect to the XMPP server and start processing XMPP stanzas.
-        self.connect()
-
     def log(self, message):
         # надо строчку лога сделать более информативной
         logfile = open("logs/" + datetime.now().strftime('%Y-%m-%d') + "-" + self.user + ".log", "a")

+ 3 - 1
handlers/handlers/open_basic_bot.py

@@ -24,7 +24,6 @@ proceed_to = [
 def message_handler(msg):
     """обработчик входящих сообщений"""
 
-
     print(msg)
     # text = msg.
     # if msg['type'] in ('chat', 'normal'):
@@ -39,6 +38,9 @@ def message_handler(msg):
 
 def start_handler(bot):
     """Событие запуска обработчика."""
+
+    print(JID, PASSWORD)
+
     bot.send_message(JID, f"message send: {datetime.now()}")
 
     # bot.proceed_status(listen_to[0], {'msg': 'some_info'})

+ 13 - 1
handlers/main.py

@@ -40,9 +40,21 @@ if __name__ == '__main__':
 
 
         bot = JabberBot(JID, PASSWORD)
+        
+        # Отправляет информацию о присутствии бота, чтобы показать,
+        # что он онлайн и готов к взаимодействию.
+        bot.send_presence()
+        # bot.get_roster() # TODO: Возможно не нужно
+
+        logging.info(f"Bot {bot.jid} started!")
+
         bot.add_event_handler("message", message_handler)
-        bot.run()
+
+        # Connect to the XMPP server and start processing XMPP stanzas.
+        bot.connect()
+        
         start_handler(bot)
+
         # bot.stop()
         asyncio.get_event_loop().run_forever()
     else: