Last active
June 22, 2018 19:03
-
-
Save nea89o/0ccbd66033f2a55f67e5a808f161be11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@bot_modules.bot_command("modules", "Allows the server admins to toggle modules like dice or poll", ["list", "<activate|deactivate> <module name>"], admin=True) | |
async def modules_command(ctx: bot_modules.CommandContext): | |
try: | |
commands = [] | |
for i in bot_modules.commands.values(): | |
commands.append(i.cmd) | |
commands.remove("eval") | |
commands.remove("modules") | |
if ctx.args[1] == "activate": | |
if len(ctx.args) < 3: | |
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)) | |
else: | |
settings = config.load_settings(ctx.discord.message.guild.id) | |
if ctx.args[2] in commands: | |
if ctx.args[2] in settings["disabled_plugins"]: | |
settings["disabled_plugins"].remove(ctx.args[2]) | |
config.change_settings(ctx.discord.message.guild.id, settings) | |
await ctx.succeed(title="Activated", description="The module **{}** has been activated!".format(ctx.args[2])) | |
else: | |
await ctx.fail(title="Error", description="**{}** is already active".format(ctx.args[2])) | |
else: | |
await ctx.fail(title="Error", description="**{}** is not a module or is not changeable, like modules itself or eval".format(ctx.args[2])) | |
elif ctx.args[1] == "deactivate": | |
if len(ctx.args) < 3: | |
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)) | |
else: | |
settings = config.load_settings(ctx.discord.message.guild.id) | |
if ctx.args[2] in commands: | |
if ctx.args[2] in settings["disabled_plugins"]: | |
await ctx.fail(title="Error", description="**{}** is already deactivated".format(ctx.args[2])) | |
else: | |
settings["disabled_plugins"].append(ctx.args[2]) | |
config.change_settings(ctx.discord.message.guild.id, settings) | |
await ctx.succeed(title="Activated", description="The module **{}** has been deactivated!".format(ctx.args[2])) | |
else: | |
await ctx.fail(title="Error", description="**{}** is not a module or is not changeable, like modules itself or eval".format(ctx.args[2])) | |
elif ctx.args[1] == "list": | |
settings = config.load_settings(ctx.discord.message.guild.id) | |
_list = "" | |
for i in commands: | |
if i in settings["disabled_plugins"]: | |
_list += ":x: " + i + "\n" | |
else: | |
_list += ":white_check_mark: " + i + "\n" | |
await ctx.succeed(title="List of all commands:", description=_list) | |
else: | |
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)) | |
except IndexError: | |
await ctx.fail(title="Error", description="You need to specify what to do,\nuse **{}help modules** to see how to use.".format(ctx.prefix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment