Advertisement
Guest User

Module manager

a guest
Jun 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.30 KB | None | 0 0
  1. @bot_modules.bot_command("modules", "Allows the server admins to toggle modules like dice or poll", ["list", "<activate|deactivate> <module name>"], admin=True)
  2. async def modules_command(ctx: bot_modules.CommandContext):
  3.     try:
  4.         commands = []
  5.         for i in bot_modules.commands.values():
  6.             commands.append(i.cmd)
  7.         commands.remove("eval")
  8.         commands.remove("modules")
  9.         if ctx.args[1] == "activate":
  10.             if len(ctx.args) < 3:
  11.                 await ctx.fail(title="Error", description="You need to specify wich module to activate!\nFor a list of modules, use **{}modules list**!".format(ctx.prefix))
  12.             else:
  13.                 settings = config.load_settings(ctx.discord.message.guild.id)
  14.                 if ctx.args[2] in commands:
  15.                     if ctx.args[2] in settings["disabled_plugins"]:
  16.                         settings["disabled_plugins"].remove(ctx.args[2])
  17.                         config.change_settings(ctx.discord.message.guild.id, settings)
  18.                         await ctx.succeed(title="Activated", description="The module **{}** has been activated!".format(ctx.args[2]))
  19.                     else:
  20.                         await ctx.fail(title="Error", description="**{}** is already active".format(ctx.args[2]))
  21.                 else:
  22.                     await ctx.fail(title="Error", description="**{}** is not a module or is not changeable, like modules itself or eval".format(ctx.args[2]))
  23.         elif ctx.args[1] == "deactivate":
  24.             if len(ctx.args) < 3:
  25.                 await ctx.fail(title="Error", description="You need to specify wich module to deactivate!\nFor a list of modules, use **{}modules list**!".format(ctx.prefix))
  26.             else:
  27.                 settings = config.load_settings(ctx.discord.message.guild.id)
  28.                 if ctx.args[2] in commands:
  29.                     if ctx.args[2] in settings["disabled_plugins"]:
  30.                         await ctx.fail(title="Error", description="**{}** is already deactivated".format(ctx.args[2]))
  31.                     else:
  32.                         settings["disabled_plugins"].append(ctx.args[2])
  33.                         config.change_settings(ctx.discord.message.guild.id, settings)
  34.                         await ctx.succeed(title="Activated", description="The module **{}** has been deactivated!".format(ctx.args[2]))
  35.                 else:
  36.                     await ctx.fail(title="Error", description="**{}** is not a module or is not changeable, like modules itself or eval".format(ctx.args[2]))
  37.         elif ctx.args[1] == "list":
  38.             settings = config.load_settings(ctx.discord.message.guild.id)
  39.             _list = ""
  40.             for i in commands:
  41.                 if i in settings["disabled_plugins"]:
  42.                     _list += ":x: " + i + "\n"
  43.                 else:
  44.                     _list += ":white_check_mark: " + i + "\n"
  45.             await ctx.succeed(title="List of all commands:", description=_list)
  46.         else:
  47.             await ctx.fail(title="Error", description="**{}** is not an available option, use **{}help modules** to see how to use.".format(ctx.args[1], ctx.prefix))
  48.     except IndexError:
  49.         await ctx.fail(title="Error", description="You need to specify what to do,\nuse **{}help modules** to see how to use.".format(ctx.prefix))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement