use module name instead of allowing module to specify its own name

This commit is contained in:
xfnw 2021-07-13 12:04:09 -04:00
parent c87a1660be
commit a65086db60
3 changed files with 8 additions and 7 deletions

7
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}']))

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

@ -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):