show exceptions

This commit is contained in:
Julian Marcos 2022-01-21 16:49:30 +00:00
parent 3aa6f72c9f
commit afea6b8595
2 changed files with 28 additions and 13 deletions

4
bot.py
View File

@ -33,8 +33,8 @@ if __name__ == '__main__':
try:
prs = importlib.reload(Parse)
Parse = prs
except Exception:
_send(f"PRIVMSG {line.source.split('!')[0]} :Error reloading")
except Exception as e:
_send(f"PRIVMSG {line.source.split('!')[0]} :Error reloading: Exception({e})")
Parse = oldprs
Parse.Parse(_send=_send, srv=srv, line=line)
except KeyboardInterrupt: _send("QUIT :^C")

View File

@ -6,9 +6,9 @@ def _send(msg: str, log=True):
shared.sock.send(f"{msg}\n".encode('utf-8'))
if log == True: print(f"> {msg}")
def usermodes(chan, user):
def usermodes(chan, user, srv):
try: return srv.channels[chan].users[user].modes
except NameError: return []
except KeyError: return []
#def _send(msg: str, log=True):
#s.send(f"{msg}\n".encode('utf-8'))
@ -50,7 +50,7 @@ class Chan:
db['chan'].delete(name=channel)
class Command:
def ExplicitCommandParser(line):
def ExplicitCommandParser(line, srv):
commandargs = line.params[1].split(' ')
command = ''.join(commandargs[0].split('*.')[1:])
args = commandargs[1:]
@ -59,14 +59,22 @@ class Command:
if command == "help": _send(f"PRIVMSG {chan} :{botdesc()}")
elif command == "echo": _send(f"PRIVMSG {chan} :\x033[Echo]\x0F \x032{usernick}\x0F said: \x039{' '.join(args[0:])}")
elif command == "psa" and args[0].startswith('#'):
if 'o' in usermodes(args[0], usernick) or 'q' in usermodes(args[0], usernick): _send(f"PRIVMSG {args[0]} :\x0307**PSA:\x0F {' '.join(args[1:])}")
else: _send(f"PRIVMSG {chan} :Sorry, you aren't allowed to make public service anouncements.")
if 'o' in usermodes(args[0], usernick, srv) or 'q' in usermodes(args[0], usernick, srv): _send(f"PRIVMSG {args[0]} :\x0307**PSA:\x0F {' '.join(args[1:])}")
else: _send(f"PRIVMSG {chan} :{usernick}: Sorry, you aren't allowed to make public service anouncements.")
elif command == "psa" and not args[0].startswith('#'): _send(f"PRIVMSG {chan} :Sorry, the syntax for PSA is: *.psa <channel> <MESSAGE>")
elif 'o' in usermodes(chan, usernick) or 'q' in usermodes(chan, usernick):
elif 'o' in usermodes(chan, usernick, srv) or 'q' in usermodes(chan, usernick, srv):
if command == "part": Chan.leave(chan, msg=f"Leaving per request of {usernick}")
if command == "topic": _send(f"TOPIC {chan} :{' '.join(args[0:])}")
if command.endswith("op"):
cmd = command.split("op")[0]
if cmd == 'de': _send("MODE {} -vhoaq {}".format(chan, 5*f"{usernick} "))
elif command == "op": _send("MODE {} +vhoa {}".format(chan, 4*f"{usernick} "))
elif cmd == "deh": _send("MODE {} -h {}".format(chan, 1*f"{usernick} "))
elif cmd == "dev": _send("MODE {} -v {}".format(chan, 1*f"{usernick} "))
elif cmd == "dea": _send("MODE {} -a {}".format(chan, 1*f"{usernick} "))
elif cmd == "deo": _send("MODE {} -o {}".format(chan, 1*f"{usernick} "))
def AdminCommandParser(line):
def AdminCommandParser(line, srv):
cmdargs = line.params[1].split(' ')
cmd = ''.join(cmdargs[0].split('%')[1:])
args = cmdargs[1:]
@ -78,12 +86,19 @@ class Command:
elif cmd == "raw": _send(f"{' '.join(args)}")
elif cmd == "join": Chan.join(args[0])
elif cmd == "part": Chan.leave(args[0])
elif cmd == "regdrop":
_send(f"PRIVMSG ChanServ :REGISTER {chan}")
_send(f"PRIVMSG ChanServ :DROP {chan} {chan}")
_send(f"MODE -o {usernick}")
elif cmd == "eval":
try: _send(f"PRIVMSG {chan} :{eval(' '.join(args))}")
except Exception as e: _send(f"PRIVMSG {chan} :Exception({e})")
def privmsg(line):
if line.params[1].startswith('%') and is_admin(line.source): Command.AdminCommandParser(line)
def privmsg(line, srv):
if line.params[1].startswith('%') and is_admin(line.source): Command.AdminCommandParser(line, srv)
elif line.params[0] != NICK and line.params[1] == "!botlist": _send(f"PRIVMSG {line.params[0]} :{botdesc()}")
elif line.params[0] == NICK and line.params[1] == "!botlist": _send(f"PRIVMSG {line.source.split('!')[0]} :{botdesc()}")
elif line.params[1].startswith('*.'): Command.ExplicitCommandParser(line)
if line.params[1].startswith('*.'): Command.ExplicitCommandParser(line, srv)
def Parse(_send=None, srv=None, line=None):
if not line.command == "PING": print(f"< {line.format()}")
@ -94,4 +109,4 @@ def Parse(_send=None, srv=None, line=None):
elif (line.source == f"NickServ!{SERVICES_HOSTMASK}" and line.command == 'NOTICE' and line.params == ['util','If you do not change within 1 minute, I will change your nick.']): nslogin()
elif (line.command == "INVITE" and line.params[0] == NICK): Chan.join(line.params[1])
elif line.command == "KICK" and line.params[1] == NICK: Chan.leave(line.params[0], kick=True)
elif line.command == "PRIVMSG": Command.privmsg(line)
elif line.command == "PRIVMSG": Command.privmsg(line, srv)