rsudo: add shell support
This commit is contained in:
parent
84c1c09903
commit
655a70b61b
2 changed files with 32 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
@ -7,6 +8,17 @@ from .common import Cog
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
async def shell(command: str):
|
||||||
|
process = await asyncio.create_subprocess_shell(
|
||||||
|
command,
|
||||||
|
stderr=asyncio.subprocess.PIPE,
|
||||||
|
stdout=asyncio.subprocess.PIPE,
|
||||||
|
)
|
||||||
|
|
||||||
|
out, err = map(lambda s: s.decode('utf-8'), await process.communicate())
|
||||||
|
return f'{out}{err}'.strip()
|
||||||
|
|
||||||
|
|
||||||
class Rsudo(Cog):
|
class Rsudo(Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
|
@ -33,10 +45,25 @@ class Rsudo(Cog):
|
||||||
await m.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await m.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
await m.add_reaction('\N{CROSS MARK}')
|
await m.add_reaction('\N{CROSS MARK}')
|
||||||
|
|
||||||
# wait for the check reaction and
|
emotes = ['\N{WHITE HEAVY CHECK MARK}',
|
||||||
# execute the command
|
'\N{CROSS MARK}']
|
||||||
|
|
||||||
# TODO: this
|
def check(reaction, user):
|
||||||
|
return user and \
|
||||||
|
reaction.emoji in emotes and \
|
||||||
|
any(x.id == self.bot.config.admin_role for x in user.roles)
|
||||||
|
|
||||||
|
reaction, user = await self.bot.wait_for('reaction_add', check=check)
|
||||||
|
|
||||||
|
if reaction.emoji == emotes[0]:
|
||||||
|
# do
|
||||||
|
await self.command_channel.send('executing')
|
||||||
|
out = await shell(command)
|
||||||
|
fmt = f'```\n{out}\n```'
|
||||||
|
await self.command_channel.send(fmt)
|
||||||
|
else:
|
||||||
|
# dont do
|
||||||
|
await self.command_channel.send('denied with success')
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|
|
@ -9,3 +9,5 @@ bot_token = 'Mzg2Mjc1MDc3MzY2NDgwODk4.DQNi9A.BnyE5MnKaIaVMBbWiW9rVDwkrSs'
|
||||||
owner_id = 162819866682851329
|
owner_id = 162819866682851329
|
||||||
|
|
||||||
command_channel = 385653662724259840
|
command_channel = 385653662724259840
|
||||||
|
|
||||||
|
admin_role = 386566510803681280
|
||||||
|
|
Loading…
Reference in a new issue