From 7e0f6ad93948a06f3a0caf4a74616724a6ce99d3 Mon Sep 17 00:00:00 2001 From: xfnw Date: Fri, 16 Oct 2020 17:57:51 -0400 Subject: [PATCH] detecting stuff --- .gitignore | 5 +++++ bot.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ filts.py | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 .gitignore create mode 100755 bot.py create mode 100644 filts.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f97fcce --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +auth.py +*.pyc +__pycache__ +__pycache__/* + diff --git a/bot.py b/bot.py new file mode 100755 index 0000000..20d1308 --- /dev/null +++ b/bot.py @@ -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()) diff --git a/filts.py b/filts.py new file mode 100644 index 0000000..2661e07 --- /dev/null +++ b/filts.py @@ -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)}') + + + + +