async def disablemodule(cmd: SigmaCommand, message: discord.Message,
                        args: list):
    if args:
        if not message.author.permissions_in(message.channel).manage_guild:
            response = permission_denied('Manage Server')
        else:
            mdl_name = args[0].lower()
            if mdl_name in cmd.bot.modules.categories:
                perms = await get_all_perms(cmd.db, message)
                disabled_modules = perms['disabled_modules']
                if mdl_name in disabled_modules:
                    response = discord.Embed(
                        color=0xFFCC4D, title='⚠ Module already disabled.')
                else:
                    disabled_modules.append(mdl_name)
                    perms.update({'disabled_modules': disabled_modules})
                    await cmd.db[cmd.db.db_nam].Permissions.update_one(
                        {'server_id': message.guild.id}, {'$set': perms})
                    scp_cache.del_cache(message.guild.id)
                    response = discord.Embed(
                        color=0x77B255,
                        title=f'βœ… `{mdl_name.upper()}` disabled.')
            else:
                response = discord.Embed(color=0x696969,
                                         title='πŸ” Module not found.')
    else:
        response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.')
    await message.channel.send(embed=response)
Esempio n. 2
0
async def enablecommand(cmd: SigmaCommand, message: discord.Message,
                        args: list):
    if args:
        if not message.author.permissions_in(message.channel).manage_guild:
            response = permission_denied('Manage Server')
        else:
            cmd_name = args[0].lower()
            if cmd_name in cmd.bot.modules.alts:
                cmd_name = cmd.bot.modules.alts[cmd_name]
            if cmd_name in cmd.bot.modules.commands:
                perms = await get_all_perms(cmd.db, message)
                disabled_commands = perms['DisabledCommands']
                if cmd_name in disabled_commands:
                    disabled_commands.remove(cmd_name)
                    perms.update({'DisabledCommands': disabled_commands})
                    await cmd.db[cmd.db.db_nam].Permissions.update_one(
                        {'ServerID': message.guild.id}, {'$set': perms})
                    scp_cache.del_cache(message.guild.id)
                    response = discord.Embed(
                        color=0x77B255,
                        title=f'βœ… `{cmd_name.upper()}` enabled.')
                else:
                    response = discord.Embed(color=0xFFCC4D,
                                             title='⚠ Command not disabled.')
            else:
                response = discord.Embed(color=0x696969,
                                         title='πŸ” Command not found.')
    else:
        response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.')
    await message.channel.send(embed=response)
Esempio n. 3
0
async def unpermituser(cmd: SigmaCommand, message: discord.Message, args: list):
    if args:
        if len(args) >= 2:
            if not message.author.permissions_in(message.channel).manage_guild:
                response = permission_denied('Manage Server')
            else:
                if message.mentions:
                    targets = message.mentions
                    error_response = discord.Embed(color=0xBE1931, title='❗ Bad input.')
                    try:
                        perm_mode, cmd_name = args[0].split(':')
                    except ValueError:
                        await message.channel.send(embed=error_response)
                        return
                    cmd_name = cmd_name.lower()
                    perm_mode = perm_mode.lower()
                    if perm_mode == 'c':
                        exception_group = 'CommandExceptions'
                        check_group = cmd.bot.modules.commands
                        check_alts = True
                    elif perm_mode == 'm':
                        exception_group = 'ModuleExceptions'
                        check_group = cmd.bot.modules.categories
                        check_alts = False
                    else:
                        await message.channel.send(embed=error_response)
                        return
                    if check_alts:
                        if cmd_name in cmd.bot.modules.alts:
                            cmd_name = cmd.bot.modules.alts[cmd_name]
                    if cmd_name in check_group:
                        perms = await get_all_perms(cmd.db, message)
                        cmd_exc = perms[exception_group]
                        if cmd_name in perms[exception_group]:
                            inner_exc = cmd_exc[cmd_name]
                        else:
                            inner_exc = generate_cmd_data(cmd_name)[cmd_name]
                        exc_usrs = inner_exc['Users']
                        bad_item = False
                        for target in targets:
                            if target.id in exc_usrs:
                                exc_usrs.remove(target.id)
                                inner_exc.update({'Users': exc_usrs})
                                cmd_exc.update({cmd_name: inner_exc})
                                perms.update({exception_group: cmd_exc})
                            else:
                                bad_item = target
                                break
                        if not bad_item:
                            await cmd.db[cmd.db.db_cfg.database].Permissions.update_one(
                                {'ServerID': message.guild.id}, {'$set': perms})
                            scp_cache.del_cache(message.guild.id)
                            if len(targets) > 1:
                                response_title = f'βœ… {len(targets)} users can no longer use `{cmd_name}`.'
                            else:
                                response_title = f'βœ… {targets[0].name} can no longer use `{cmd_name}`.'
                            response = discord.Embed(color=0x77B255, title=response_title)
                        else:
                            response_title = f'⚠ {bad_item.name} is not able to use `{cmd_name}`.'
                            response = discord.Embed(color=0xFFCC4D, title=response_title)
                    else:
                        perm_type = 'Command' if perm_mode == 'c' else 'Module'
                        response = discord.Embed(color=0x696969, title=f'πŸ” {perm_type} not found.')
                else:
                    response = discord.Embed(color=0x696969, title=f'πŸ” No user targeted.')
        else:
            response = discord.Embed(color=0xBE1931, title='❗ Not enough arguments.')
    else:
        response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.')
    await message.channel.send(embed=response)
async def unpermitrole(cmd: SigmaCommand, message: discord.Message,
                       args: list):
    if args:
        if len(args) >= 2:
            if not message.author.permissions_in(message.channel).manage_guild:
                response = permission_denied('Manage Server')
            else:
                target_name = ' '.join(args[1:])
                target = discord.utils.find(
                    lambda x: x.name.lower() == target_name.lower(),
                    message.guild.roles)
                if target:
                    error_response = discord.Embed(color=0xBE1931,
                                                   title='❗ Bad input.')
                    try:
                        perm_mode, cmd_name = args[0].split(':')
                    except ValueError:
                        await message.channel.send(embed=error_response)
                        return
                    cmd_name = cmd_name.lower()
                    perm_mode = perm_mode.lower()
                    if perm_mode == 'c':
                        exception_group = 'command_exceptions'
                        check_group = cmd.bot.modules.commands
                        check_alts = True
                    elif perm_mode == 'm':
                        exception_group = 'module_exceptions'
                        check_group = cmd.bot.modules.categories
                        check_alts = False
                    else:
                        await message.channel.send(embed=error_response)
                        return
                    if check_alts:
                        if cmd_name in cmd.bot.modules.alts:
                            cmd_name = cmd.bot.modules.alts[cmd_name]
                    if cmd_name in check_group:
                        perms = await get_all_perms(cmd.db, message)
                        cmd_exc = perms[exception_group]
                        if cmd_name in perms[exception_group]:
                            inner_exc = cmd_exc[cmd_name]
                        else:
                            inner_exc = generate_cmd_data(cmd_name)[cmd_name]
                        exc_usrs = inner_exc['roles']
                        if target.id in exc_usrs:
                            exc_usrs.remove(target.id)
                            inner_exc.update({'roles': exc_usrs})
                            cmd_exc.update({cmd_name: inner_exc})
                            perms.update({exception_group: cmd_exc})
                            await cmd.db[cmd.db.db_nam].Permissions.update_one(
                                {'server_id': message.guild.id},
                                {'$set': perms})
                            scp_cache.del_cache(message.guild.id)
                            response = discord.Embed(
                                color=0x77B255,
                                title=
                                f'βœ… {target.name} can no longer use `{cmd_name}`.'
                            )
                        else:
                            response = discord.Embed(
                                color=0xFFCC4D,
                                title=
                                f'⚠ {target.name} is not able to use `{cmd_name}`.'
                            )
                    else:
                        perm_type = 'Command' if perm_mode == 'c' else 'Module'
                        response = discord.Embed(
                            color=0x696969, title=f'πŸ” {perm_type} not found.')
                else:
                    response = discord.Embed(
                        color=0x696969, title=f'πŸ” {target_name} not found.')
        else:
            response = discord.Embed(color=0xBE1931,
                                     title='❗ Not enough arguments.')
    else:
        response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.')
    await message.channel.send(embed=response)