Add service command
This commit is contained in:
parent
e772367f2e
commit
b83e91539a
22
main.py
22
main.py
@ -13,7 +13,7 @@ import config
|
||||
def login_required(fn):
|
||||
async def decorated_fn(ctx, *args):
|
||||
if str(ctx.author.id) not in config.allowed_users:
|
||||
await ctx.reply("Vous n'êtes pas autorisé à exécuter cette fonction.")
|
||||
await ctx.reply("Vous n'êtes pas autorisé à exécuter cette commande.")
|
||||
return None
|
||||
return await fn(ctx, *args)
|
||||
|
||||
@ -74,4 +74,24 @@ async def status(ctx):
|
||||
await ctx.reply(embed=embed)
|
||||
|
||||
|
||||
@bot.command(name="service")
|
||||
@login_required
|
||||
async def status(ctx, *args):
|
||||
"""Exécute une commande systemd"""
|
||||
error = None
|
||||
commands = ["start", "stop", "enable", "disable"]
|
||||
if len(args) < 2:
|
||||
error = "Paramètres manquants."
|
||||
elif args[0] not in commands:
|
||||
error = f"Commande invalide `{args[0]}`"
|
||||
elif args[1] not in config.services:
|
||||
error= f"Service inconnu `{args[1]}`"
|
||||
|
||||
if error is not None:
|
||||
await ctx.reply(error)
|
||||
return None
|
||||
os.system(f"systemctl {args[0]} {args[1]}")
|
||||
await ctx.message.add_reaction("🆗")
|
||||
|
||||
|
||||
bot.run(config.TOKEN)
|
||||
|
Loading…
Reference in New Issue
Block a user