improved thing
This commit is contained in:
parent
74bba6969b
commit
1a49460545
215
bot.py
215
bot.py
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import time
|
import time
|
||||||
import sys
|
|
||||||
|
|
||||||
from irctokens import build, Line
|
from irctokens import build, Line
|
||||||
from ircrobots import Bot as BaseBot
|
from ircrobots import Bot as BaseBot
|
||||||
|
@ -10,82 +9,20 @@ from ircrobots import Server as BaseServer
|
||||||
from ircrobots import ConnectionParams
|
from ircrobots import ConnectionParams
|
||||||
from ircrobots.glob import compile as gcompile
|
from ircrobots.glob import compile as gcompile
|
||||||
|
|
||||||
SERVERS = [
|
from nicklist import Nicklist
|
||||||
("tilde", "localhost")
|
import text
|
||||||
]
|
|
||||||
SPAMSERVERS = [
|
kickees = Nicklist()
|
||||||
("0", "localhost"),
|
exempt = Nicklist()
|
||||||
("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"
|
|
||||||
}
|
|
||||||
CHANNEL = "#chaos"
|
CHANNEL = "#chaos"
|
||||||
PASSWORD = "hellothereperson"
|
PASSWORD = "hellothereperson"
|
||||||
BOTNAME = "rndbot"
|
BOTNAME = "rndbotmerp"
|
||||||
OWNER = "rndusr"
|
OWNER = "rndusr"
|
||||||
TOPIC = "rule one: you are now a duck. ・゜゜・。。・゜゜\\_o< QUACK!"
|
TOPIC = "rule one: you are now a duck. ・゜゜・。。・゜゜\\_o< QUACK!"
|
||||||
SPAMUSER = ""
|
SPAMUSER = ""
|
||||||
|
|
||||||
LOGFILE = open(CHANNEL + ".log", "w")
|
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):
|
class Server(BaseServer):
|
||||||
async def line_read(self, line: Line):
|
async def line_read(self, line: Line):
|
||||||
print(f"{self.name} < {line.format()}")
|
print(f"{self.name} < {line.format()}")
|
||||||
|
@ -103,49 +40,42 @@ class Server(BaseServer):
|
||||||
if line.hostmask.nickname == OWNER:
|
if line.hostmask.nickname == OWNER:
|
||||||
if BOTNAME + ": quit" == line.params[1]:
|
if BOTNAME + ": quit" == line.params[1]:
|
||||||
await self.send(build('PART', [CHANNEL, MESSAGES['quit']]))
|
await self.send(build('PART', [CHANNEL, MESSAGES['quit']]))
|
||||||
exit(100)
|
exit(1)
|
||||||
if BOTNAME + ": kickadd" in line.params[1]:
|
if BOTNAME + ": add" in line.params[1]:
|
||||||
if gcompile("*!*@*").match(line.params[1].split(' ')[2]):
|
if "kickees" == line.params[1].split(' ')[2]:
|
||||||
KICKEES_HOSTMASK.append(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, \
|
await self.send(build('PRIVMSG', [CHANNEL, \
|
||||||
MESSAGES['kickadd']]))
|
MESSAGES['kickadd']]))
|
||||||
else:
|
else:
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, \
|
await self.send(build('PRIVMSG', [CHANNEL, \
|
||||||
MESSAGES['kickadderr']]))
|
MESSAGES['kickadderr']]))
|
||||||
if BOTNAME + ": kicklist" in line.params[1]:
|
if "exempt" == line.params[1].split(' ')[2]:
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, \
|
if exempt.append(line.params[1].split(' ')[3]):
|
||||||
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])
|
|
||||||
else:
|
|
||||||
KICKEES.remove(line.params[1].split(' ')[2])
|
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, \
|
|
||||||
MESSAGES['kickrm']]))
|
|
||||||
except ValueError:
|
|
||||||
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, \
|
await self.send(build('PRIVMSG', [CHANNEL, \
|
||||||
MESSAGES['exemptadd']]))
|
MESSAGES['exemptadd']]))
|
||||||
if BOTNAME + ": exemptlist" in line.params[1]:
|
else:
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, \
|
await self.send(build('PRIVMSG', [CHANNEL, \
|
||||||
MESSAGES['exemptlist'] + ' '.join(EXEMPT)]))
|
MESSAGES['exemptadderr']]))
|
||||||
if BOTNAME + ": exemptrm" in line.params[1]:
|
if BOTNAME + ": list" in line.params[1]:
|
||||||
try:
|
if "kickees" == line.params[1].split(' ')[2]:
|
||||||
EXEMPT.remove(line.params[1].split(' ')[2])
|
await self.send(build('PRIVMSG', [CHANNEL, \
|
||||||
|
MESSAGES['kicklist'] + str(kickees)]))
|
||||||
|
if "exempt" == line.params[1].split(' ')[2]:
|
||||||
|
await self.send(build('PRIVMSG', [CHANNEL, \
|
||||||
|
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, \
|
await self.send(build('PRIVMSG', [CHANNEL, \
|
||||||
MESSAGES['exemptrm']]))
|
MESSAGES['exemptrm']]))
|
||||||
except ValueError:
|
else:
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, \
|
await self.send(build('PRIVMSG', [CHANNEL, \
|
||||||
MESSAGES['exemptrmerr']]))
|
MESSAGES['exemptrmerr']]))
|
||||||
if BOTNAME + ": ping" in line.params[1]:
|
if BOTNAME + ": ping" in line.params[1]:
|
||||||
|
@ -159,51 +89,28 @@ class Server(BaseServer):
|
||||||
tmp = ""
|
tmp = ""
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, \
|
await self.send(build('PRIVMSG', [CHANNEL, \
|
||||||
tmp]))
|
tmp]))
|
||||||
if BOTNAME + ": savestate" in line.params[1]:
|
if BOTNAME + ": writestate" in line.params[1]:
|
||||||
try:
|
if kickees.write('kickee'):
|
||||||
fd = open("kickees", "w")
|
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writekickee']]))
|
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writekickee']]))
|
||||||
fd.writelines(i + '\n' for i in KICKEES)
|
if exempt.write('exempt'):
|
||||||
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()
|
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writeexempt']]))
|
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writeexempt']]))
|
||||||
fd = open("exempt", "w")
|
if BOTNAME + ": readstate" in line.params[1]:
|
||||||
fd.writelines(i + '\n' for i in EXEMPT)
|
if kickees.read('kickee'):
|
||||||
fd.close()
|
pass
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writedone']]))
|
if exempt.read('exempt'):
|
||||||
except:
|
pass
|
||||||
await self.send(build('PRIVMSG', [CHANNEL, MESSAGES['writeerr']]))
|
if BOTNAME + ": kickall" in line.params[1]:
|
||||||
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]:
|
|
||||||
for i in self.channels[CHANNEL].users:
|
for i in self.channels[CHANNEL].users:
|
||||||
if i != OWNER:
|
if i != OWNER:
|
||||||
asyncio.create_task(self.send(build('KICK', [CHANNEL, i, 'nope'])))
|
asyncio.create_task(self.send(build('KICK', [CHANNEL, i, 'nope'])))
|
||||||
|
|
||||||
if line.command == "JOIN":
|
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']]))
|
await self.send(build('KICK', [CHANNEL, line.hostmask.nickname, MESSAGES['kick']]))
|
||||||
else:
|
return
|
||||||
for i in KICKEES_HOSTMASK:
|
for i in kickees.host():
|
||||||
if gcompile(i).match(str(line.hostmask)):
|
if gcompile(i).match(str(line.hostmask)):
|
||||||
await self.send(build('KICK', [CHANNEL, line.hostmask.nickname, MESSAGES['kick']]))
|
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()
|
|
||||||
if line.command == "MODE":
|
if line.command == "MODE":
|
||||||
try:
|
try:
|
||||||
if 'l' in self.channels[CHANNEL].modes:
|
if 'l' in self.channels[CHANNEL].modes:
|
||||||
|
@ -220,8 +127,6 @@ class Server(BaseServer):
|
||||||
await self.send(build("PRIVMSG", ["ChanServ", "unban " + CHANNEL + " " + BOTNAME]))
|
await self.send(build("PRIVMSG", ["ChanServ", "unban " + CHANNEL + " " + BOTNAME]))
|
||||||
if not 'q' in self.channels[CHANNEL].users[BOTNAME].modes:
|
if not 'q' in self.channels[CHANNEL].users[BOTNAME].modes:
|
||||||
await self.send(build("PRIVMSG", ["ChanServ", "owner " + CHANNEL + " " + BOTNAME]))
|
await self.send(build("PRIVMSG", ["ChanServ", "owner " + CHANNEL + " " + BOTNAME]))
|
||||||
else:
|
|
||||||
print(self.channels[CHANNEL].modes)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
if line.command == "KICK" and line.params[0] == CHANNEL:
|
if line.command == "KICK" and line.params[0] == CHANNEL:
|
||||||
|
@ -245,42 +150,14 @@ class Server(BaseServer):
|
||||||
print(f"{self.name} > {line.format()}")
|
print(f"{self.name} > {line.format()}")
|
||||||
LOGFILE.write(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):
|
class Bot(BaseBot):
|
||||||
def create_server(self, name: str):
|
def create_server(self, name: str):
|
||||||
return Server(self, name)
|
return Server(self, name)
|
||||||
|
|
||||||
class SpamBot(BaseBot):
|
|
||||||
def create_server(self, name: str):
|
|
||||||
return SpamServer(self, name)
|
|
||||||
|
|
||||||
async def main():
|
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()
|
bot = Bot()
|
||||||
for name, host in SERVERS:
|
params = ConnectionParams(BOTNAME, 'localhost', 6667, False, BOTNAME, "totally not rndusr's bot lol")
|
||||||
params = ConnectionParams(BOTNAME, host, 6667, False, BOTNAME, "totally not rndusr's bot lol")
|
await bot.add_server('tilde', params)
|
||||||
await bot.add_server(name, params)
|
|
||||||
|
|
||||||
await bot.run()
|
await bot.run()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue