admin detection decorator

This commit is contained in:
vulpine 2020-11-21 17:29:12 -05:00
parent a0377a9035
commit 755560ce65
3 changed files with 55 additions and 2 deletions

28
bot.py
View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import asyncio
import asyncio, os, importlib
from irctokens import build, Line
from ircrobots import Bot as BaseBot
@ -12,14 +12,38 @@ from auth import username, password
class Server(BaseServer):
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
if 'on_'+line.command.lower() in dir(self):
await self.__getattribute__('on_'+line.command.lower())(line)
async def line_send(self, line: Line):
print(f"{self.name} > {line.format()}")
async def on_001(self, line):
asyncio.create_task(self.load_modules())
async def load_modules(self):
self.modules = {}
self.listeners = []
self.commands = {}
for i in [s for s in os.listdir('modules') if '.py' in s and '.swp' not in s]:
i = i[:-3]
m = __import__('modules.' + i)
m = eval('m.' + i)
asyncio.create_task(m.init(self))
self.modules[i] = m
class Bot(BaseBot):
def create_server(self, name: str):
return Server(self, name)
async def main():
bot = Bot()

16
modules/core.py Normal file
View File

@ -0,0 +1,16 @@
def is_admin(func):
async def decorator(self,channel,nick,message):
if nick.lower() in self.users and self.users[nick.lower()].account in self.admins:
await self.send_raw("PRIVMSG #bots :test")
return decorator
#def is_chanop(func):
async def init(self):
self.admins = ['xfnw','lickthecheese']

13
modules/test.py Normal file
View File

@ -0,0 +1,13 @@
import asyncio
import modules.core as core
@core.is_admin
async def testy(self,channel,nick,message):
pass
async def init(self):
await self.send_raw("join #bots")
await asyncio.sleep(5)
await testy(self,'#bots','xfnw','hi')