merge bot.py from upstream oirc

This commit is contained in:
vulpine 2022-04-28 13:45:08 -04:00 committed by GitHub
parent f67b269b1b
commit fd3174b1fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

17
bot.py
View file

@ -7,7 +7,7 @@ from ircrobots import Bot as BaseBot
from ircrobots import Server as BaseServer from ircrobots import Server as BaseServer
from ircrobots import ConnectionParams, SASLUserPass, SASLSCRAM from ircrobots import ConnectionParams, SASLUserPass, SASLSCRAM
from auth import username, password, channel from auth import username, password
import shared import shared
@ -19,9 +19,7 @@ def is_admin(func):
): ):
await func(self, channel, nick, msg) await func(self, channel, nick, msg)
else: else:
await message( await message(self, channel, "you do not have permission to do that")
self, "core", channel, "you do not have permission to do that"
)
return decorator return decorator
@ -54,7 +52,7 @@ def rawm(rname):
async def message(self, channel, msg): 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}"])) await self.send(build("PRIVMSG", [channel, f"[\x036{modname}\x0f] {msg}"]))
@ -68,10 +66,10 @@ class Server(BaseServer):
if listener[0] == line.command: if listener[0] == line.command:
asyncio.create_task(listener[1](self, line)) 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()}") 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()}") print(f"{self.name} > {line.format()}")
async def on_001(self, line): async def on_001(self, line):
@ -84,9 +82,9 @@ class Server(BaseServer):
asyncio.create_task(m.init(self)) asyncio.create_task(m.init(self))
shared.modules[i] = m shared.modules[i] = m
# depricated, to support old modules
async def message(self, channel, msg): 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): async def on_privmsg(self, line):
if line.tags and "batch" in line.tags and line.tags["batch"] == "1": 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): def create_server(self, name: str):
return Server(self, name) return Server(self, name)
async def main(): async def main():
bot = Bot() bot = Bot()