This commit is contained in:
Julian Marcos 2022-01-09 13:17:55 +00:00
parent 354b7e028e
commit 970283845a
2 changed files with 32 additions and 16 deletions

47
bot.py
View File

@ -20,14 +20,18 @@ def nslogin():
_send(f"PRIVMSG NickServ@services.tilde.chat :IDENTIFY {NICK} {SERVICES_PW}", log=False)
print("Logged into services")
_send(f"MODE {NICK} +B")
_send(f"JOIN {CHANNELS}")
for i in db['chan'].all():
_send(f"JOIN {[i['name']]}")
def joinchannel(channel):
_send(f"JOIN {channel}")
db['chan'].insert(dict(name=i))
Chan.joins()
class Chan:
def joins():
for i in db['chan'].all():
_send(f"JOIN {','.join([i['name']])}")
def join(channel):
_send(f"JOIN {channel}")
db['chan'].insert(dict(name=channel))
def leave(channel, msg="", kick=False):
if not kick: _send(f"PART {channel} :{msg}")
db['chan'].delete(name=channel)
srv = ircstates.Server(NETNAME)
s = socket.socket()
@ -46,24 +50,37 @@ try:
for line in recv_lines:
srv.parse_tokens(line)
if not line.command == "PING": print(f"< {line.format()}")
if line.command == "PING": _send(f"PONG :{line.params[0]}", log=False)
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): joinchannel(line.params[1])
elif line.command == "!botlist": _send(f"PRIVMSG {line.source} :I am a utility bot. Public commands *.echo | Ran by ~julian@~team/~jmjl@{~town,~club}")
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 == "!botlist": _send(f"PRIVMSG {line.source} :I am a utility bot. Public commands *.echo | Ran by ~julian@~team/~jmjl@~town/~jmjl@~club")
elif line.command == "PRIVMSG" and line.params[1].startswith('%') and is_admin(line.source):
cmdargs = line.params[1].split(' ')
cmd = ''.join(commandargs[0].split('%')[1:])
args = commandargs[1:]
usernick = line.source.split('!')[0]
chan = line.params[0]
if cmd == "mode": _send(f"MODE {chan} {' '.join(args)}")
elif cmd == "quit": _send(f"QUIT :{' '.join(args)}")
elif cmd == "msg": _send(f"PRIVMSG {args[0] :{' '.join(args[1:])}")
elif cmd == "raw": _send(f"{' '.join(args)}")
elif cmd == "join": Chan.join(args[0])
elif cmd == "part": Chan.leave(args[0])
elif (line.command == "PRIVMSG" and line.params[1].startswith('*.') ):
commandargs = line.params[1].split(' ')
command = ''.join(commandargs[0].split('*.')[1:])
args = commandargs[1:]
usernick = line.source.split('!')[0]
chan = line.params[0]
if command == "join" and is_admin(line.source): joinchannel(args[0])
elif command == "help": _send(f"PRIVMSG {chan} :I am a utility bot. Ran by ~julian@~team/~jmjl@{~town,~club}")
if command == "help": _send(f"PRIVMSG {chan} :I am a utility bot. Ran by ~julian@~team/~jmjl@~town/~jmjl@~club")
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 {usernick} :Sorry, you aren't allowed to make public service anouncements.")
elif command == "psa" and not args[0].startswith('#'): _send(f"PRIVMSG {usernick} :Sorry, the syntax for PSA is: *.psa <channel> <MESSAGE>")
elif ('o' in usermodes(chan, usernick) or 'q' in usermodes(chan, usernick)) or is_admin(line.source):
if command == "part": _send(f"PART {args[0]} :Leaving per request of {usernick}")
else: _send(f"PRIVMSG {chan} :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):
if command == "part": Chan.leave(chan, msg=f"Leaving per request of {usernick}")
if command == "topic": _send(f"TOPIC {chan} :{' '.join(args[0:])}")
except KeyboardInterrupt: _send("QUIT :^C")

View File

@ -8,7 +8,6 @@ PORT = int(fileload('conf/port'))
NICK = fileload('conf/nick')
REALNAME = fileload('conf/realname')
SERVICES_PW = fileload('conf/pw')
CHANNELS = fileload('conf/chans')
NETNAME = fileload('conf/net')
SERVICES_HOSTMASK = fileload('conf/services')
tls = fileload('conf/port') == '6697'