try to auto-reconnect when disconnected (not crashed), and don't break when there's no MOTD?

hopefully this stuff works, lol
This commit is contained in:
jan6 2022-05-13 22:27:11 +03:00
parent 7d48fa6889
commit 7c966381fe
2 changed files with 9 additions and 2 deletions

7
bot.py
View File

@ -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...")

View File

@ -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 == []: