From fd3174b1fe0d53bf82cf31e7e206a402b2b5b1bb Mon Sep 17 00:00:00 2001 From: vulpine Date: Thu, 28 Apr 2022 13:45:08 -0400 Subject: [PATCH] merge bot.py from upstream oirc --- bot.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index 4ad3b60..4a273c4 100755 --- a/bot.py +++ b/bot.py @@ -7,7 +7,7 @@ from ircrobots import Bot as BaseBot from ircrobots import Server as BaseServer from ircrobots import ConnectionParams, SASLUserPass, SASLSCRAM -from auth import username, password, channel +from auth import username, password import shared @@ -19,9 +19,7 @@ def is_admin(func): ): await func(self, channel, nick, msg) else: - await message( - self, "core", channel, "you do not have permission to do that" - ) + await message(self, channel, "you do not have permission to do that") return decorator @@ -54,7 +52,7 @@ def rawm(rname): async def message(self, channel, msg): - modname = os.path.splittext(os.path.basename(inspect.stack()[1].filename))[0] + modname = os.path.splitext(os.path.basename(inspect.stack()[:2][-1].filename))[0] await self.send(build("PRIVMSG", [channel, f"[\x036{modname}\x0f] {msg}"])) @@ -68,10 +66,10 @@ class Server(BaseServer): if listener[0] == line.command: asyncio.create_task(listener[1](self, line)) - def line_preread(self, line: Line): + async def line_preread(self, line: Line): print(f"{self.name} < {line.format()}") - def line_presend(self, line: Line): + async def line_presend(self, line: Line): print(f"{self.name} > {line.format()}") async def on_001(self, line): @@ -84,9 +82,9 @@ class Server(BaseServer): asyncio.create_task(m.init(self)) shared.modules[i] = m - # depricated, to support old modules async def message(self, channel, msg): - await self.send(build("PRIVMSG", [channel, msg])) + modname = os.path.splitext(os.path.basename(inspect.stack()[:2][-1].filename))[0] + await self.send(build("PRIVMSG", [channel, f"[\x036{modname}\x0f] {msg}"])) async def on_privmsg(self, line): if line.tags and "batch" in line.tags and line.tags["batch"] == "1": @@ -129,7 +127,6 @@ class Bot(BaseBot): def create_server(self, name: str): return Server(self, name) - async def main(): bot = Bot()