Compare commits

...

5 Commits

6 changed files with 45 additions and 20 deletions

13
bot.py
View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import asyncio, os, importlib
import asyncio, os, importlib, inspect
from irctokens import build, Line
from ircrobots import Bot as BaseBot
@ -15,7 +15,7 @@ def is_admin(func):
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')
await message(self,channel,'you do not have permission to do that')
return decorator
#def is_chanop(func):
@ -41,7 +41,8 @@ def rawm(rname):
async def message(self,modname,channel,msg):
async def message(self,channel,msg):
modname = os.path.splitext(os.path.basename(inspect.stack()[1].filename))[0]
await self.send(build("PRIVMSG",[channel,f'[\x036{modname}\x0f] {msg}']))
@ -49,14 +50,14 @@ async def message(self,modname,channel,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):
asyncio.create_task(self.__getattribute__('on_'+line.command.lower())(line))
for listener in shared.listeners:
if listener[0] == line.command:
asyncio.create_task(listener[1](self,line))
async def line_send(self, line: Line):
async def line_preread(self, line: Line):
print(f"{self.name} < {line.format()}")
async def line_presend(self, line: Line):
print(f"{self.name} > {line.format()}")

View File

@ -74,7 +74,7 @@ async def send(self, c, n, m):
await self.message(c, '[\x036admin\x0f] sent')
async def shut(self, c, n, m):
self.qtime[c] = time.time()+(60*10)
shared.qtime[c] = time.time()+(60*10)
await self.message(c, '[\x036admin\x0f] Ok, il be back in 10 minutes')
async def schans(self, c, n, m):
@ -97,22 +97,31 @@ async def addalias(self,c,n,m):
async def addot(self,c,n,m):
al = m.split(' ')[0]
m = m[len(al)+1:] # dont use the list since i want trailing spaces
if al in self.rawm:
if al in shared.rawm:
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
return
self.rawm[al]=Ot(m,al).ot
shared.rawm[al]=Ot(m,al).ot
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
async def addspook(self,c,n,m):
al = m.split(' ')[0]
m = m[len(al)+1:] # dont use the list since i want trailing spaces
if al in shared.rawm:
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
return
shared.rawm[al]=Spook(m,al).spook
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
async def addtrigger(self,c,n,m):
al = m.split(' ')[0]
m = m[len(al)+1:] # dont use the list since i want trailing spaces
if al in self.rawm:
if al in shared.rawm:
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
return
self.rawm[al]=Trigger(m,al).trigger
shared.rawm[al]=Trigger(m,al).trigger
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
@ -124,10 +133,18 @@ class Ot():
self.al = str(al)
async def ot(alself,self,c,n,m):
if alself.al in m and n != self.nickname:
asyncio.create_task(self.on_message(c,n,alself.ms.format(m)))
self.rawm.pop(alself.al)
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
shared.rawm.pop(alself.al)
class Spook():
def __init__(self, ms, al):
self.ms = str(ms)
self.al = str(al)
async def spook(alself,self,c,n,m):
if alself.al in m and n != self.nickname:
asyncio.create_task(self.message(c,alself.ms.format(m)))
shared.rawm.pop(alself.al)
class Trigger():
@ -136,14 +153,14 @@ class Trigger():
self.al = str(al)
async def trigger(alself,self,c,n,m):
if alself.al in m:
asyncio.create_task(self.on_message(c,n,alself.ms.format(m)))
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
class Alias():
def __init__(self, ms):
self.ms = str(ms)
async def alias(alself,self,c,n,m):
asyncio.create_task(self.on_message(c,n,alself.ms.format(m)))
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
@ -160,6 +177,7 @@ commands = {
'addalias': addalias,
'addtrigger': addtrigger,
'addot': addot,
'addspook': addspook,
}
@command('admin')
@ -176,6 +194,7 @@ async def adminHandle(self, chan, source, msg):
async def init(self):
self.chandb = shared.db['chan']
self.admins = ['xfnw']
return
self.cmd['admin'] = adminHandle

View File

@ -18,11 +18,11 @@ async def coffeeup(self,c,n,m):
else:
self.coffee.insert(dict(name=c,value=1))
if c=='#CAPS':
await self.message(c, '[\x036drinks\x0f] ・゜゜・。。・゜゜c[~] {} UP!'.format(c[1:].upper()).upper())
await message(self, c, '・゜゜・。。・゜゜c[~] {} UP!'.format(c[1:].upper()).upper())
else:
await self.message(c, '[\x036drinks\x0f] ・゜゜・。。・゜゜c[~] {} UP!'.format(c[1:].upper()))
await message(self, c, '・゜゜・。。・゜゜c[~] {} UP!'.format(c[1:].upper()))
elif "cupcount" in m:
await self.message(c, '[\x036drinks\x0f] {} delicious cups of {}{} served so far!'.format(
await message(self, c, '{} delicious cups of {}{} served so far!'.format(
self.coffee.find_one(name=c)['value'], random.choice(self.coffeetypes), c[1:]
))

View File

@ -69,7 +69,7 @@ async def rmkeep(self,c,n,m):
else:
await self.message(c, '[\x036keep\x0f] did not remove any')
else:
await self.message(c,'[\x036keep\x0f] you must have +o in #balun')
await self.message(c,f'[\x036keep\x0f] you must have +o in {self.rmkeepchan}')
async def init(self):
self.keepdb = shared.db['keep']

View File

@ -5,7 +5,7 @@ import bot
@bot.command('test')
@bot.is_admin
async def testy(self,channel,nick,msg):
await bot.message(self,'test',channel,'hi there')
await bot.message(self,channel,'hi there')
async def init(self):

5
modules/usrinfo.py Normal file
View File

@ -0,0 +1,5 @@
from bot import *
async def init(self):
pass