improved thing

This commit is contained in:
randomuser 2021-04-04 01:25:01 +00:00
parent 74bba6969b
commit 1a49460545
2 changed files with 108 additions and 177 deletions

231
bot.py
View File

@ -2,7 +2,6 @@
import asyncio
import time
import sys
from irctokens import build, Line
from ircrobots import Bot as BaseBot
@ -10,82 +9,20 @@ from ircrobots import Server as BaseServer
from ircrobots import ConnectionParams
from ircrobots.glob import compile as gcompile
SERVERS = [
("tilde", "localhost")
]
SPAMSERVERS = [
("0", "localhost"),
("1", "localhost"),
("2", "localhost"),
("3", "localhost"),
("4", "localhost"),
("5", "localhost"),
("6", "localhost"),
("7", "localhost"),
("8", "localhost"),
("9", "localhost"),
("10", "localhost"),
("11", "localhost"),
("12", "localhost"),
("13", "localhost"),
("14", "localhost"),
("15", "localhost"),
("16", "localhost"),
("17", "localhost"),
("18", "localhost"),
("19", "localhost"),
]
KICKEES = []
KICKEES_HOSTMASK = []
EXEMPT = []
MESSAGES = {
"revenge": "no u",
"kick": "error 418",
"quit": "bonk",
"kickadd": "user added to kicklist",
"kickadderr": "adding failed: user on exemption list",
"kicklist": "kickees: ",
"kickrm": "user removed from kicklist",
"kickrmerr": "error removing user from kicklist",
"exemptadd": "user added to exemptlist",
"exemptlist": "exempt: ",
"exemptrm": "user removed from exemptlist",
"exemptrmerr": "error removing user from exemptlist",
"writeexempt": "writing exempt data",
"writekickee": "writing kickee data",
"writekickeehostmask": "writing kickee_hostmask data",
"writedone": "done!",
"writeerr": "error writing files"
}
from nicklist import Nicklist
import text
kickees = Nicklist()
exempt = Nicklist()
CHANNEL = "#chaos"
PASSWORD = "hellothereperson"
BOTNAME = "rndbot"
BOTNAME = "rndbotmerp"
OWNER = "rndusr"
TOPIC = "rule one: you are now a duck. ・゜゜・。。・゜゜\\_o< QUACK!"
SPAMUSER = ""
LOGFILE = open(CHANNEL + ".log", "w")
class SpamServer(BaseServer):
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
if line.command == "001":
asyncio.create_task(self.send(build("JOIN", [CHANNEL])))
if line.command == "PRIVMSG" and line.params[0] == CHANNEL:
if "quit" in line.params[1] and line.hostmask.nickname == OWNER:
asyncio.create_task(self.send(build("PRIVMSG", [CHANNEL, "merp"])))
asyncio.create_task(self.send(build("PART", [CHANNEL, "merp"])))
asyncio.create_task(self.send(build("QUIT")))
else:
asyncio.create_task(self.send(build("PRIVMSG", [CHANNEL, "ALL HAIL IRES"])))
if line.command == "KICK":
if line.params[1] == BOTNAME:
time.sleep(1)
asyncio.create_task(self.send(build("JOIN", [CHANNEL])))
# asyncio.create_task(build('KICK', [CHANNEL, line.params[2], MESSAGES['revenge']]))
async def line_send(self, line: Line):
print(f"{self.name} > {line.format()}")
class Server(BaseServer):
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
@ -103,51 +40,44 @@ class Server(BaseServer):
if line.hostmask.nickname == OWNER:
if BOTNAME + ": quit" == line.params[1]:
await self.send(build('PART', [CHANNEL, MESSAGES['quit']]))
exit(100)
if BOTNAME + ": kickadd" in line.params[1]:
if gcompile("*!*@*").match(line.params[1].split(' ')[2]):
KICKEES_HOSTMASK.append(line.params[1].split(' ')[2])
exit(1)
if BOTNAME + ": add" in line.params[1]:
if "kickees" == line.params[1].split(' ')[2]:
if kickees.append(line.params[1].split(' ')[3]):
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['kickadd']]))
else:
if not line.params[1].split(' ')[1] in EXEMPT:
KICKEES.append(line.params[1].split(' ')[2])
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['kickadd']]))
MESSAGES['kickadd']]))
else:
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['kickadderr']]))
if BOTNAME + ": kicklist" in line.params[1]:
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['kicklist'] + ' '.join(KICKEES)]))
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['kicklist'] + ' '.join(KICKEES_HOSTMASK)]))
if BOTNAME + ": kickrm" in line.params[1]:
try:
if gcompile("*!*@*").match(line.params[1].split(' ')[2]):
KICKEES_HOSTMASK.remove(line.params[1].split(' ')[2])
MESSAGES['kickadderr']]))
if "exempt" == line.params[1].split(' ')[2]:
if exempt.append(line.params[1].split(' ')[3]):
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['exemptadd']]))
else:
KICKEES.remove(line.params[1].split(' ')[2])
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['exemptadderr']]))
if BOTNAME + ": list" in line.params[1]:
if "kickees" == line.params[1].split(' ')[2]:
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['kickrm']]))
except ValueError:
MESSAGES['kicklist'] + str(kickees)]))
if "exempt" == line.params[1].split(' ')[2]:
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['kickrmerr']]))
if BOTNAME + ": exemptadd" in line.params[1]:
EXEMPT.append(line.params[1].split(' ')[2])
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['exemptadd']]))
if BOTNAME + ": exemptlist" in line.params[1]:
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['exemptlist'] + ' '.join(EXEMPT)]))
if BOTNAME + ": exemptrm" in line.params[1]:
try:
EXEMPT.remove(line.params[1].split(' ')[2])
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['exemptrm']]))
except ValueError:
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['exemptrmerr']]))
MESSAGES['exemptlist'] + str(exempt)]))
if BOTNAME + ": rm" in line.params[1]:
if "kickees" == line.params[1].split(' ')[2]:
if kickees.remove(line.params[1].split(' ')[3]):
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['kickrm']]))
else:
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['kickrmerr']]))
if "exempt" == line.params[1].split(' ')[2]:
if exempt.remove(line.params[1].split(' ')[3]):
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['exemptrm']]))
else:
await self.send(build('PRIVMSG', [CHANNEL, \
MESSAGES['exemptrmerr']]))
if BOTNAME + ": ping" in line.params[1]:
tmp = ""
for i in self.channels[CHANNEL].users.keys():
@ -159,51 +89,28 @@ class Server(BaseServer):
tmp = ""
await self.send(build('PRIVMSG', [CHANNEL, \
tmp]))
if BOTNAME + ": savestate" in line.params[1]:
try:
fd = open("kickees", "w")
if BOTNAME + ": writestate" in line.params[1]:
if kickees.write('kickee'):
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writekickee']]))
fd.writelines(i + '\n' for i in KICKEES)
fd.close()
fd = open("kickees_mask", "w")
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writekickeehostmask']]))
fd.writelines(i + '\n' for i in KICKEES_HOSTMASK)
fd.close()
if exempt.write('exempt'):
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writeexempt']]))
fd = open("exempt", "w")
fd.writelines(i + '\n' for i in EXEMPT)
fd.close()
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writedone']]))
except:
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writeerr']]))
if BOTNAME + ": bots" in line.params[1]:
bot = SpamBot()
for name, host in SPAMSERVERS:
await bot.add_server(name, \
ConnectionParams(BOTNAME + name, host, 6667, False, BOTNAME))
asyncio.create_task(bot.run())
if BOTNAME + ": kick" in line.params[1]:
if BOTNAME + ": readstate" in line.params[1]:
if kickees.read('kickee'):
pass
if exempt.read('exempt'):
pass
if BOTNAME + ": kickall" in line.params[1]:
for i in self.channels[CHANNEL].users:
if i != OWNER:
asyncio.create_task(self.send(build('KICK', [CHANNEL, i, 'nope'])))
if line.command == "JOIN":
if line.hostmask.nickname in KICKEES:
if line.hostmask.nickname in kickees:
await self.send(build('KICK', [CHANNEL, line.hostmask.nickname, MESSAGES['kick']]))
else:
for i in KICKEES_HOSTMASK:
if gcompile(i).match(str(line.hostmask)):
await self.send(build('KICK', [CHANNEL, line.hostmask.nickname, MESSAGES['kick']]))
break
if line.hostmask.nickname == "bot":
global TASKCACHE
TASKCACHE = asyncio.create_task(self.julian())
if line.command == "PART":
if line.hostmask.nickname == 'bot' and 'TASKCACHE' in globals():
TASKCACHE.cancel()
if line.command == "QUIT":
if line.hostmask.nickname == 'bot' and 'TASKCACHE' in globals():
TASKCACHE.cancel()
return
for i in kickees.host():
if gcompile(i).match(str(line.hostmask)):
await self.send(build('KICK', [CHANNEL, line.hostmask.nickname, MESSAGES['kick']]))
if line.command == "MODE":
try:
if 'l' in self.channels[CHANNEL].modes:
@ -220,8 +127,6 @@ class Server(BaseServer):
await self.send(build("PRIVMSG", ["ChanServ", "unban " + CHANNEL + " " + BOTNAME]))
if not 'q' in self.channels[CHANNEL].users[BOTNAME].modes:
await self.send(build("PRIVMSG", ["ChanServ", "owner " + CHANNEL + " " + BOTNAME]))
else:
print(self.channels[CHANNEL].modes)
except KeyError:
pass
if line.command == "KICK" and line.params[0] == CHANNEL:
@ -245,42 +150,14 @@ class Server(BaseServer):
print(f"{self.name} > {line.format()}")
LOGFILE.write(f"{self.name} > {line.format()}")
async def julian(self):
while True:
self.send(build('PRIVMSG', [CHANNEL, "hi"]))
class Bot(BaseBot):
def create_server(self, name: str):
return Server(self, name)
class SpamBot(BaseBot):
def create_server(self, name: str):
return SpamServer(self, name)
async def main():
try:
fd = open("kickees", "r")
for i in fd.readlines():
if not i in EXEMPT:
KICKEES.append(i.rstrip('\n'))
fd.close()
fd = open("kickees_mask", "r")
for i in fd.readlines():
if not i in EXEMPT:
KICKEES_HOSTMASK.append(i.rstrip('\n'))
fd.close()
fd = open("exempt", "r")
for i in fd.readlines():
EXEMPT.append(i.rstrip('\n'))
fd.close()
except FileNotFoundError:
print("warning: save state files are missing")
print("proceeding without save state files")
bot = Bot()
for name, host in SERVERS:
params = ConnectionParams(BOTNAME, host, 6667, False, BOTNAME, "totally not rndusr's bot lol")
await bot.add_server(name, params)
params = ConnectionParams(BOTNAME, 'localhost', 6667, False, BOTNAME, "totally not rndusr's bot lol")
await bot.add_server('tilde', params)
await bot.run()
if __name__ == "__main__":

54
nicklist.py Normal file
View File

@ -0,0 +1,54 @@
from ircrobots.glob import compile as gcompile
class Nicklist:
def __init__(self):
self.nick = []
self.hostnick = []
def __str__(self):
return ' '.join(self.nick + self.hostnick)
def __len__(self):
return len(self.nick) + len(self.hostnick)
def __contains__(self, item):
if gcompile("*!*@*").match(item):
return item in self.hostnick
else:
return item in self.nick
def append(self, mask):
if gcompile("*!*@*").match(mask):
self.hostnick.append(mask)
elif not mask in self.nick:
self.nick.append(mask)
return 1
def remove(self, mask):
try:
if gcompile("*!*@*").match(mask):
self.hostnick.remove(mask)
else:
self.nick.remove(mask)
return 1
except ValueError:
return 0
def host(self):
return self.hostnick
def nick(self):
return nick
def write(self, name):
fd = open(name + "nick", "w")
fd.writelines(i + "\n" for i in self.nick)
fd.close()
fd = open(name + "mask", "w")
fd.writelines(i + "\n" for i in self.hostnick)
fd.close()
return 1
def read(self, name):
fd = open(name + "nick", "r")
for i in fd.readlines():
self.nick.append(i.rstrip("\n"))
fd.close()
fd = open(name + "mask", "r")
for i in fd.readlines():
self.hostnick.append(i.rstrip("\n"))
fd.close()
return 1