the basics of rsudo

This commit is contained in:
Luna Mendes 2017-12-02 12:53:47 -03:00
parent d725403509
commit 49c4aa4e7b
4 changed files with 23 additions and 9 deletions

View File

@ -8,7 +8,8 @@ log = logging.getLogger(__name__)
exts = [
'basic',
'admin'
'admin',
'rsudo'
]
@ -45,12 +46,13 @@ def schedule_bot(loop, config, db):
)
bot.db = db
bot.config = config
try:
for ext in exts:
bot.load_extension(f'bot.ext.{ext}')
log.info('loaded %s', ext)
loop.create_task(bot.start(config.bot_token))
return bot
except:
log.exception('failed to load %s', ext)

View File

@ -10,20 +10,28 @@ log = logging.getLogger(__name__)
class Rsudo(Cog):
def __init__(self, bot):
super().__init__(bot)
self.command_channel = None
async def create_request(self, message):
if not self.command_channel:
self.command_channel = self.bot.get_channel(
self.bot.config.command_channel)
if not self.command_channel:
log.warning('command channel not found')
return
# parse it, follows format command,uid
uid = message.split(',')[-1]
command = ','.join(message.split(',')[:-1])
log.info(f'[rsudo] {uid!r} {command!r}')
if not self.command_channel:
return
e = discord.Embed(title=f'rsudo from uid {uid}')
e.add_field(name='command', value=f'`{command}`')
await self.command_channel.send(embed=e)
m = await self.command_channel.send(embed=e)
await m.add_reaction('\N{WHITE HEAVY CHECK MARK}')
await m.add_reaction('\N{CROSS MARK}')
def setup(bot):

View File

@ -8,4 +8,4 @@ db = {
bot_token = 'Mzg2Mjc1MDc3MzY2NDgwODk4.DQNi9A.BnyE5MnKaIaVMBbWiW9rVDwkrSs'
owner_id = 162819866682851329
bot_token = None
command_channel = 385653662724259840

View File

@ -86,6 +86,7 @@ async def process(reader, writer, op: int, message: str):
INSERT INTO logs (uid, cwd, cmd) VALUES ($1, $2, $3)
""", uid, cwd, command)
elif op == 2:
log.debug(bot.cogs)
rsudo = bot.get_cog('Rsudo')
if not rsudo:
return await send_msg(writer, 1, 'no rsudo cog')
@ -123,7 +124,10 @@ if __name__ == '__main__':
server = loop.run_until_complete(coro)
if config.bot_token:
schedule_bot(loop, config, db)
bot = schedule_bot(loop, config, db)
if bot:
loop.create_task(bot.start(config.bot_token))
log.info(f'Serving on {server.sockets[0].getsockname()}')
try: