From 71da85c9704ca1dc72363400bb2a770456962b3c Mon Sep 17 00:00:00 2001 From: Julian Marcos Date: Sat, 22 Jan 2022 12:25:31 +0000 Subject: [PATCH] add %r(join/part/egdrop)/%op(er/) --- parse.py | 75 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/parse.py b/parse.py index d328b80..f8d88f2 100644 --- a/parse.py +++ b/parse.py @@ -17,8 +17,6 @@ def usermodes(chan, user, srv): def botdesc(): return fileload('desc') -db['oper'].insert(dict(hostmask='julian!julian@envs.net')) - def is_admin(source): #return 'julian@envs.net' == source.split('!')[1] #db['oper'].insert(dict(hostmask='friend!good@person')) @@ -27,8 +25,8 @@ def is_admin(source): for i in db['oper'].all(): if source == i['hostmask']: return True else: continue - except: - _send(f"PRIVMSG julian :{source} isn't operator, permission denied for {source.split('!')[0]}.") + except Exception as e: + _send(f"PRIVMSG julian :{source} caused {e}") return False return False @@ -86,10 +84,43 @@ 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 == "rpart": _send(f"PART {chan} :~Bye") + elif cmd == "rjoin" and len(args) > 0: _send(f"JOIN {args[0]}") elif cmd == "regdrop": - _send(f"PRIVMSG ChanServ :REGISTER {chan}") - _send(f"PRIVMSG ChanServ :DROP {chan} {chan}") - _send(f"MODE -o {usernick}") + try: + if len(args) > 0: thatchan = args[0] + else: + thatchan = ["#"] + for i in range(0, 5): thatchan.append(importlib.import_module('random').choice(importlib.import_module('string').ascii_letters)) + thatchan = ''.join(thatchan) + _send(f"JOIN {thatchan}") + _send(f"PRIVMSG {chan} :{thatchan}") + _send(f"PRIVMSG ChanServ :REGISTER {thatchan}") + _send(f"PRIVMSG ChanServ :DROP {thatchan} {thatchan}") + if len(args) > 1: db['ops'].insert(dict(mask=line.source, chan=thatchan, delete=True, modes=args[1])) + else: db['ops'].insert(dict(mask=line.source, chan=thatchan, delete=True, modes='o')) + _send(f"INVITE {usernick} {thatchan}") + except Exception as e: print(e) + elif cmd == "oper": + try: + if args[0].startswith('-'): + db['oper'].delete(hostmask=args[0][1:]) + _send(f"PRIVMSG {chan} :Hostmask {args[0][1:]} is no longer oper") + elif args[0].startswith('+'): + db['oper'].insert(dict(hostmask=args[0][1:])) + _send(f"PRIVMSG {chan} :Hostmask {args[0][1:]} is now oper") + except Exception as e: _send(f"PRIVMSG {chan} :Exception({e})") + elif cmd == "op" and len(args) > 2: + #db['ops'].insert(dict(mask=line.source, chan=thatchan, delete=True, modes=args[1])) + try: + if args[1].startswith('-'): + db['ops'].delete(chan=args[0], modes=args[1][1:]) + _send(f"PRIVMSG {chan} :Mode {args[0]}:-{args[1][1:]} {args[2].split('!')[0]}") + elif args[1].startswith('+'): + if len(args) > 3: db['ops'].insert(dict(chan=args[0], modes=args[1][1:], mask=args[2], delete=True)) + else: db['ops'].insert(dict(chan=args[0], modes=args[1][1:], mask=args[2], delete=False)) + _send(f"PRIVMSG {chan} :Mode {args[0]}:+{args[1][1:]} {args[2].split('!')[0]}") + except Exception as e: _send(f"PRIVMSG {chan} :Exception({e})") elif cmd == "eval": try: _send(f"PRIVMSG {chan} :{eval(' '.join(args))}") except Exception as e: _send(f"PRIVMSG {chan} :Exception({e})") @@ -101,12 +132,24 @@ class Command: 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()}") - if line.command == "PING": - _send(f"PONG :{line.params[0]}", log=False) - if shared.nick_has_changed: _send(f"NICK {NICK}") - elif line.command == "433": _send(f"NICK {NICK}_"); shared.nick_has_changed = True - 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, srv) + try: Parser(_send, srv, line) + except Exception as e: print(e) + +def Parser(_send=None, srv=None, line=None): + if not line.command == "PING": print(f"< {line.format()}") + if line.command == "PING": + _send(f"PONG :{line.params[0]}", log=False) + if shared.nick_has_changed: _send(f"NICK {NICK}") + elif line.command == "433": _send(f"NICK {NICK}_"); shared.nick_has_changed = True + 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, srv) + elif line.command == "JOIN": + try: + for i in db['ops'].all(): + if line.command == "JOIN" and line.source == i['mask'] and line.params[0] == i['chan']: + nickspace = f"{i['mask'].split('!')[0]} " + _send(f"MODE {i['chan']} +{i['modes']} {len(i['modes'])*nickspace}") + if i['delete']: db['ops'].delete(mask=i['mask'], chan=i['chan'], modes=i['modes']) + except Exception as e: print(e)