aaaa why wont the scope wok

This commit is contained in:
vulpine 2020-11-21 20:49:04 -05:00
parent 755560ce65
commit bf0c8e8481
3 changed files with 68 additions and 22 deletions

65
bot.py
View File

@ -9,11 +9,45 @@ from ircrobots import ConnectionParams, SASLUserPass, SASLSCRAM
from auth import username, password
prefix = '.'
modules = {}
listeners = []
commands = {}
rawm = {}
def is_admin(func):
async def decorator(self,channel,nick,msg):
if nick.lower() in self.users and self.users[nick.lower()].account in self.admins:
await func(self,channel,nick,msg)
else:
await message(self,'core',channel,'you do not have permission to do that')
return decorator
def command(commandname):
def decorator(func):
commands[commandname] = func
print(commands, 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')
return func
return decorator
#def is_chanop(func):
async def message(self,modname,channel,msg):
await self.send(build("PRIVMSG",[channel,f'[\x036{modname}\x0f] {msg}']))
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)
asyncio.create_task(self.__getattribute__('on_'+line.command.lower())(line))
for listener in listeners:
if listener[0] == line.command:
asyncio.create_task(listener[1](self,line))
async def line_send(self, line: Line):
print(f"{self.name} > {line.format()}")
@ -23,20 +57,39 @@ class Server(BaseServer):
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
modules[i] = m
async def on_privmsg(self, line):
channel = line.params[0]
nick = line.source.split('!')[0]
msg = line.params[1]
await self.handle_rawm(channel,nick,msg)
await self.handle_command(channel,nick,msg)
async def handle_rawm(self,channel,nick,msg):
for i in rawm:
await rawm[i](self,channel,nick,msg)
async def handle_command(self,channel,nick,msg):
if msg[:len(prefix)] == prefix:
msg = msg[len(prefix):]
cmd = msg.split(' ')[0]
msg = msg[len(cmd)+1:]
if len(cmd) < 1:
return
print(commands)
if cmd in commands:
await commands[cmd](self,channel,nick,msg)
return
results = [i for i in commands if i.startswith(cmd)]
if len(results) == 1:
await commands[results[0]](self,channel,nick,msg)
class Bot(BaseBot):

View File

@ -1,14 +1,6 @@
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):
from irctokens import build, Line
import bot
async def init(self):

View File

@ -1,13 +1,14 @@
import asyncio
import modules.core as core
from bot import *
@core.is_admin
async def testy(self,channel,nick,message):
pass
@command('test')
@is_admin
async def testy(self,channel,nick,msg):
await message(self,'test',channel,str(bot.hi))
bot.hi += 1
async def init(self):
await self.send_raw("join #bots")
await asyncio.sleep(5)
await testy(self,'#bots','xfnw','hi')