detecting stuff

This commit is contained in:
vulpine 2020-10-16 17:57:51 -04:00
commit 7e0f6ad939
3 changed files with 97 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
auth.py
*.pyc
__pycache__
__pycache__/*

58
bot.py Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env python3
logchan = "#xfnwtest"
import asyncio, importlib
from irctokens import build, Line
from ircrobots import Bot as BaseBot
from ircrobots import Server as BaseServer
from ircrobots import ConnectionParams
import filts
SERVERS = [
("freenode", "chat.freenode.net"),
("tilde","irc.tilde.chat"),
]
class Server(BaseServer):
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
if line.command == "001":
self.lc = "#" *(self.name == "freenode") + logchan
print(f"connected to {self.name}")
await self.send(build("JOIN", [self.lc]))
if line.command == "PRIVMSG":
if 'batch' in line.tags and line.tags['batch'] == '1':
return
if line.params[1] == '!reload':
importlib.reload(filts)
await self.linelog('reloaded')
if line.command == "INVITE":
await self.send(build("JOIN",[line.params[1]]))
asyncio.create_task(filts.line_read(self,line))
async def line_send(self, line: Line):
print(f"{self.name} > {line.format()}")
async def linelog(self,string):
await self.send(build("NOTICE",[self.lc,string]))
class Bot(BaseBot):
def create_server(self, name: str):
return Server(self, name)
async def main():
bot = Bot()
for name, host in SERVERS:
params = ConnectionParams("Sifakis", host, 6697, True)
await bot.add_server(name, params)
await bot.run()
if __name__ == "__main__":
asyncio.run(main())

34
filts.py Normal file
View File

@ -0,0 +1,34 @@
import asyncio
from irctokens import build, Line
async def line_read(self,line):
# line tags command params source
if line.command == "JOIN":
await on_join(self,line)
async def on_join(self,line):
reason = []
if not line.tags or 'account' not in line.tags:
reason.append('NO_NS_ACCOUNT')
if line.tags and 'account' in line.tags:
account = line.tags['account']
reason += [f'NS_ACCOUNT ({ac})' for ac in ['lickthecheese'] if ac == account]
host = line.source.split('@')[1]
reason += [f'BAD_HOST ({host})' for ac in ['hot-chilli'] if ac in host]
if len(reason) > 0:
await self.linelog(f'{line.source} caught in {line.params[0]} because of {", ".join(reason)}')