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:
parent
7d48fa6889
commit
7c966381fe
7
bot.py
7
bot.py
|
@ -4,6 +4,7 @@ import ircstates, socket, ssl
|
||||||
from config import *
|
from config import *
|
||||||
from stuff import stuff
|
from stuff import stuff
|
||||||
from util import Util
|
from util import Util
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
class bot:
|
class bot:
|
||||||
|
@ -24,6 +25,9 @@ class bot:
|
||||||
stuff(self, sock)
|
stuff(self, sock)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
util.quit("^C")
|
util.quit("^C")
|
||||||
|
except ircstates.server.ServerDisconnectedException:
|
||||||
|
sleep(3)
|
||||||
|
self.__init__()
|
||||||
else:
|
else:
|
||||||
with socket.create_connection((self.host, self.port)) as sock:
|
with socket.create_connection((self.host, self.port)) as sock:
|
||||||
try:
|
try:
|
||||||
|
@ -31,6 +35,9 @@ class bot:
|
||||||
stuff(self, sock)
|
stuff(self, sock)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
util.quit("^C")
|
util.quit("^C")
|
||||||
|
except ircstates.server.ServerDisconnectedException:
|
||||||
|
sleep(3)
|
||||||
|
self.__init__()
|
||||||
|
|
||||||
|
|
||||||
print("starting bot...")
|
print("starting bot...")
|
||||||
|
|
4
stuff.py
4
stuff.py
|
@ -86,9 +86,9 @@ def stuff(bot, sock):
|
||||||
f"IDENTIFY {config.self.nick} {config.server.nickserv_pass}",
|
f"IDENTIFY {config.self.nick} {config.server.nickserv_pass}",
|
||||||
line.source.split("!")[0],
|
line.source.split("!")[0],
|
||||||
)
|
)
|
||||||
if line.command == "433":
|
if line.command == "433": #433 is ERR_NICKNAMEINUSE
|
||||||
util.nick(config.self.nick + "_")
|
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())
|
send(irctokens.build("CAP", ["LS", "302"]).format())
|
||||||
elif line.command == "CAP" and line.params[1] == "LS":
|
elif line.command == "CAP" and line.params[1] == "LS":
|
||||||
if server_caps == []:
|
if server_caps == []:
|
||||||
|
|
Loading…
Reference in New Issue