소스 검색

darkirc/script/bots: fix accidentally messed up telegram bot

dasman 1 년 전
부모
커밋
012f5dec23
1개의 변경된 파일17개의 추가작업 그리고 20개의 파일을 삭제
  1. 17 20
      bin/darkirc/script/bots/telegram-mirror-bot.py

+ 17 - 20
bin/darkirc/script/bots/telegram-mirror-bot.py

@@ -15,7 +15,7 @@ MAX_NICK_LENGTH = 10
 MAX_MESSAGE_LENGTH = MessageLimit.MAX_TEXT_LENGTH - (MAX_CHANNEL_LENGTH + MAX_NICK_LENGTH + 16)
 MAX_MESSAGE_LENGTH = MessageLimit.MAX_TEXT_LENGTH - (MAX_CHANNEL_LENGTH + MAX_NICK_LENGTH + 16)
 
 
 SERVER = "127.0.0.1"
 SERVER = "127.0.0.1"
-PORT = 22025
+PORT = 6645
 CHANNELS = ["#dev","#memes","#philosophy","#markets","#math","#random",]
 CHANNELS = ["#dev","#memes","#philosophy","#markets","#math","#random",]
 BOTNICK = "tgbridge"
 BOTNICK = "tgbridge"
 
 
@@ -60,8 +60,6 @@ ircc.connect(SERVER, PORT, CHANNELS, BOTNICK)
 async def main():
 async def main():
     while True:
     while True:
         text = ircc.get_response()
         text = ircc.get_response()
-        # print("loop")
-        print("text: " + text)
         if not len(text) > 0:
         if not len(text) > 0:
             print("Error: disconnected from server")
             print("Error: disconnected from server")
             exit(-1)
             exit(-1)
@@ -94,7 +92,7 @@ async def main():
                 message = nick + message[7:]
                 message = nick + message[7:]
                 nick = "*"
                 nick = "*"
 
 
-            # append_log(channel, nick, message)
+            append_log(channel, nick, message)
 
 
             # Pad and left/right justify channel and nickname
             # Pad and left/right justify channel and nickname
             channel = channel[:MAX_CHANNEL_LENGTH].ljust(MAX_CHANNEL_LENGTH)
             channel = channel[:MAX_CHANNEL_LENGTH].ljust(MAX_CHANNEL_LENGTH)
@@ -104,22 +102,21 @@ async def main():
             while len(message) > 0:
             while len(message) > 0:
                 string_to_telegram = f"<code>{channel} {nick} |</code> {message[:MAX_MESSAGE_LENGTH]}"
                 string_to_telegram = f"<code>{channel} {nick} |</code> {message[:MAX_MESSAGE_LENGTH]}"
 
 
-                print("tele: " + string_to_telegram)
-                # # Keep retrying until the fucker is sent
-                # while True:
-                #     try:
-                #         async with Bot(TOKEN) as bot:
-                #             await bot.send_message("@darkfi_darkirc", string_to_telegram,
-                #                                 parse_mode="HTML",
-                #                                 disable_notification=True,
-                #                                 disable_web_page_preview=True)
-                #         break
-                #     #except telegram.error.BadRequest:
-                #     #    pass
-                #     except:
-                #         print(channel, string_to_telegram)
-                #         print(traceback.format_exc())
-                #         await asyncio.sleep(3)
+                # Keep retrying until the fucker is sent
+                while True:
+                    try:
+                        async with Bot(TOKEN) as bot:
+                            await bot.send_message("@darkfi_darkirc", string_to_telegram,
+                                                parse_mode="HTML",
+                                                disable_notification=True,
+                                                disable_web_page_preview=True)
+                        break
+                    #except telegram.error.BadRequest:
+                    #    pass
+                    except:
+                        print(channel, string_to_telegram)
+                        print(traceback.format_exc())
+                        await asyncio.sleep(3)
 
 
                 message = message[MAX_MESSAGE_LENGTH:]
                 message = message[MAX_MESSAGE_LENGTH:]