From 7c966381fea173bcf0a3994a26f2ed2d06df9ce6 Mon Sep 17 00:00:00 2001 From: jan6 Date: Fri, 13 May 2022 22:27:11 +0300 Subject: [PATCH] try to auto-reconnect when disconnected (not crashed), and don't break when there's no MOTD? hopefully this stuff works, lol --- bot.py | 7 +++++++ stuff.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 7c1a7b5..75464cb 100755 --- a/bot.py +++ b/bot.py @@ -4,6 +4,7 @@ import ircstates, socket, ssl from config import * from stuff import stuff from util import Util +from time import sleep class bot: @@ -24,6 +25,9 @@ class bot: stuff(self, sock) except KeyboardInterrupt: util.quit("^C") + except ircstates.server.ServerDisconnectedException: + sleep(3) + self.__init__() else: with socket.create_connection((self.host, self.port)) as sock: try: @@ -31,6 +35,9 @@ class bot: stuff(self, sock) except KeyboardInterrupt: util.quit("^C") + except ircstates.server.ServerDisconnectedException: + sleep(3) + self.__init__() print("starting bot...") diff --git a/stuff.py b/stuff.py index 8edc5d5..02f52c2 100755 --- a/stuff.py +++ b/stuff.py @@ -86,9 +86,9 @@ def stuff(bot, sock): f"IDENTIFY {config.self.nick} {config.server.nickserv_pass}", line.source.split("!")[0], ) - if line.command == "433": + if line.command == "433": #433 is ERR_NICKNAMEINUSE util.nick(config.self.nick + "_") - if line.command == "376": + if line.command == "376" or line.command == "422": #376 is RPL_ENDOFMOTD and 422 is ERR_NOMOTD send(irctokens.build("CAP", ["LS", "302"]).format()) elif line.command == "CAP" and line.params[1] == "LS": if server_caps == []: