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

View file

@ -10,20 +10,28 @@ log = logging.getLogger(__name__)
class Rsudo(Cog): class Rsudo(Cog):
def __init__(self, bot): def __init__(self, bot):
super().__init__(bot) super().__init__(bot)
self.command_channel = None
async def create_request(self, message): 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 # parse it, follows format command,uid
uid = message.split(',')[-1] uid = message.split(',')[-1]
command = ','.join(message.split(',')[:-1]) command = ','.join(message.split(',')[:-1])
log.info(f'[rsudo] {uid!r} {command!r}') log.info(f'[rsudo] {uid!r} {command!r}')
if not self.command_channel:
return
e = discord.Embed(title=f'rsudo from uid {uid}') e = discord.Embed(title=f'rsudo from uid {uid}')
e.add_field(name='command', value=f'`{command}`') 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): def setup(bot):

View file

@ -8,4 +8,4 @@ db = {
bot_token = 'Mzg2Mjc1MDc3MzY2NDgwODk4.DQNi9A.BnyE5MnKaIaVMBbWiW9rVDwkrSs' bot_token = 'Mzg2Mjc1MDc3MzY2NDgwODk4.DQNi9A.BnyE5MnKaIaVMBbWiW9rVDwkrSs'
owner_id = 162819866682851329 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) INSERT INTO logs (uid, cwd, cmd) VALUES ($1, $2, $3)
""", uid, cwd, command) """, uid, cwd, command)
elif op == 2: elif op == 2:
log.debug(bot.cogs)
rsudo = bot.get_cog('Rsudo') rsudo = bot.get_cog('Rsudo')
if not rsudo: if not rsudo:
return await send_msg(writer, 1, 'no rsudo cog') return await send_msg(writer, 1, 'no rsudo cog')
@ -123,7 +124,10 @@ if __name__ == '__main__':
server = loop.run_until_complete(coro) server = loop.run_until_complete(coro)
if config.bot_token: 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()}') log.info(f'Serving on {server.sockets[0].getsockname()}')
try: try: