Sfoglia il codice sorgente

darkirc/script/bots: all bots exit on empty buffer

dasman 1 anno fa
parent
commit
1b3454dd29

+ 2 - 1
bin/darkirc/script/bots/mirror-bot.py

@@ -48,7 +48,8 @@ signal.signal(signal.SIGINT, signal_handler)
 while True:
 while True:
     darkirc_text = darkirc.get_response()
     darkirc_text = darkirc.get_response()
     if not len(darkirc_text.strip()) > 0:
     if not len(darkirc_text.strip()) > 0:
-        continue
+        print("Error: disconnected from server")
+        exit(-1)
     
     
     print(darkirc_text)
     print(darkirc_text)
     text_list = darkirc_text.split(' ')
     text_list = darkirc_text.split(' ')

+ 22 - 18
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 = 6645
+PORT = 22025
 CHANNELS = ["#dev","#memes","#philosophy","#markets","#math","#random",]
 CHANNELS = ["#dev","#memes","#philosophy","#markets","#math","#random",]
 BOTNICK = "tgbridge"
 BOTNICK = "tgbridge"
 
 
@@ -60,8 +60,11 @@ 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:
-            continue
+            print("Error: disconnected from server")
+            exit(-1)
         text_list = text.split(' ')
         text_list = text.split(' ')
         nick = text_list[0].split('!')[0][1:]
         nick = text_list[0].split('!')[0][1:]
         if text_list[1] == "PRIVMSG":
         if text_list[1] == "PRIVMSG":
@@ -91,7 +94,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)
@@ -101,21 +104,22 @@ 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]}"
 
 
-                # 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)
+                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)
 
 
                 message = message[MAX_MESSAGE_LENGTH:]
                 message = message[MAX_MESSAGE_LENGTH:]
 
 

+ 2 - 1
bin/darkirc/script/bots/test-bot.py

@@ -22,7 +22,8 @@ signal.signal(signal.SIGINT, signal_handler)
 while True:
 while True:
     text = ircc.get_response().strip()
     text = ircc.get_response().strip()
     if not len(text) > 0:
     if not len(text) > 0:
-        continue
+        print("Error: disconnected from server")
+        exit(-1)
     # print(text)
     # print(text)
     text_list = text.split(' ')
     text_list = text.split(' ')
     #print(text_list)
     #print(text_list)

+ 2 - 1
bin/darkirc/script/bots/titlebot.py

@@ -26,7 +26,8 @@ signal.signal(signal.SIGINT, signal_handler)
 while True:
 while True:
     text = ircc.get_response()
     text = ircc.get_response()
     if not len(text) > 0:
     if not len(text) > 0:
-        continue
+        print("Error: disconnected from server")
+        exit(-1)
     print(text)
     print(text)
     text_list = text.split(' ')
     text_list = text.split(' ')
     if text_list[1] == "PRIVMSG":
     if text_list[1] == "PRIVMSG":

+ 2 - 1
bin/darkirc/script/bots/tweetifier.py

@@ -25,7 +25,8 @@ signal.signal(signal.SIGINT, signal_handler)
 while True:
 while True:
     text = ircc.get_response().strip()
     text = ircc.get_response().strip()
     if not len(text) > 0:
     if not len(text) > 0:
-        continue
+        print("Error: disconnected from server")
+        exit(-1)
     print(text)
     print(text)
     text_list = text.split(' ')
     text_list = text.split(' ')
     if text_list[1] == "PRIVMSG":
     if text_list[1] == "PRIVMSG":