fix error handling during connect

This commit is contained in:
jkhsjdhjs 2024-01-30 23:37:58 +00:00
parent f449305ccd
commit e3cdce4f12

60
bert.py
View File

@ -72,10 +72,7 @@ def safeexit():
def connect(host, port): def connect(host, port):
print("Connecting to "+host+":"+str(port)) print("Connecting to "+host+":"+str(port))
try: irc.connect((host, port))
irc.connect((host, port))
except Exception as err:
print("Connection failed! "+str(err))
def sendRaw(data): def sendRaw(data):
@ -84,26 +81,17 @@ def sendRaw(data):
def register(nick, host): def register(nick, host):
print("Registering User...") print("Registering User...")
try: sendRaw("USER "+nick+" "+host+" "+nick+" "+nick+"\n")
sendRaw("USER "+nick+" "+host+" "+nick+" "+nick+"\n")
except Exception as err:
print("Failed! "+str(err))
def name(nick): def name(nick):
print("Setting Nickname to "+nick) print("Setting Nickname to "+nick)
try: sendRaw("NICK "+nick+"\n")
sendRaw("NICK "+nick+"\n")
except Exception as err:
print("Failed! "+str(err))
def auth(nick, password): def auth(nick, password):
print("Authenticating...") print("Authenticating...")
try: sendRaw("PRIVMSG NickServ :IDENTIFY "+nick+" "+password+"\n")
sendRaw("PRIVMSG NickServ :IDENTIFY "+nick+" "+password+"\n")
except Exception as err:
print(err)
def join(chan): def join(chan):
@ -116,10 +104,7 @@ def join(chan):
def mode(nick): def mode(nick):
print("Setting modes +B-x") print("Setting modes +B-x")
try: sendRaw("MODE "+nick+" +B-x\n")
sendRaw("MODE "+nick+" +B-x\n")
except Exception as err:
print("Failed! "+str(err))
def part(chan): def part(chan):
@ -254,22 +239,19 @@ def ping(msg):
def start(host, port, nick, password, chans): def start(host, port, nick, password, chans):
try: connect(host, port)
connect(host, port) sleep(2)
sleep(2) register(nick, host)
register(nick, host) sleep(2)
sleep(2) name(nick)
name(nick) sleep(6)
sleep(6) auth(nick, password)
auth(nick, password) sleep(2)
sleep(2) mode(nick)
mode(nick) sleep(2)
sleep(2) for chan in chans:
for chan in chans: join(chan)
join(chan) sleep(2)
sleep(2)
except Exception as err:
print("FAIL: "+str(err))
def command_loop(): def command_loop():
@ -509,7 +491,11 @@ class fefe_thread(threading.Thread):
fefe_check() fefe_check()
def main(): def main():
start(host, port, nick, password, set(join_chans + fefe_chans)) try:
start(host, port, nick, password, set(join_chans + fefe_chans))
except Exception as err:
print("FAIL: "+str(err))
sys.exit(1)
thread_command = command_thread(1) thread_command = command_thread(1)
#thread_fefe = fefe_thread(2) #thread_fefe = fefe_thread(2)
thread_command.start() thread_command.start()