Example #1
0
 async def add_mod_role(self, ctx, role: discord.Role):
     roles = Configuration.getConfigVar(ctx.guild.id, "MOD_ROLES")
     if role.id in roles:
         await ctx.send(f"{Emoji.get_chat_emoji('NO')} `{role.name}` is already a mod role")
     else:
         roles.append(role.id)
         Configuration.saveConfig(ctx.guild.id)
         await ctx.send(f"{Emoji.get_chat_emoji('YES')} `{role.name}` is now a mod role")
Example #2
0
 async def remove_admin_role(self, ctx, *, role: discord.Role):
     roles = Configuration.getConfigVar(ctx.guild.id, "ADMIN_ROLES")
     if role.id not in roles:
         await ctx.send(f"{Emoji.get_chat_emoji('NO')} `{role.name}` was not an admin role so i cannot remove it")
     else:
         roles.remove(role.id)
         Configuration.saveConfig(ctx.guild.id)
         await ctx.send(f"{Emoji.get_chat_emoji('YES')} `{role.name}` is no longer an admin role")
Example #3
0
 async def remove_command_override(self, ctx, command:str):
     overrides = Configuration.getConfigVar(ctx.guild.id, "COMMAND_OVERRIDES")
     if command in overrides:
         del overrides[command]
         Configuration.saveConfig(ctx.guild.id)
         await ctx.send(f"{Emoji.get_chat_emoji('YES')} Command override for {command} has been removed.")
     else:
         await ctx.send(f"{Emoji.get_chat_emoji('NO')} I don't have a command override for {command} to remove.")
Example #4
0
 async def add_command_override(self, ctx, command: str, perm_lvl: int):
     command_object = self.bot.get_command(command)
     if command_object is not None:
         cog = command_object.instance
         cog_name = command_object.cog_name
         if not hasattr(cog, "permissions"):
             await ctx.send(
                 f"{Emoji.get_chat_emoji('NO')} {Translator.translate('command_core_cog_no_override', ctx, command=command, cog_name=cog_name)}"
             )
         elif perm_lvl in range(7):
             perm_dict = Permissioncheckers.get_perm_dict(
                 command.split(" "), cog.permissions)
             if perm_lvl < perm_dict["min"]:
                 lvl = cog.permissions['min']
                 await ctx.send(
                     f"{Emoji.get_chat_emoji('NO')} {Translator.translate('command_min_perm_violation', ctx, command=command, min_lvl=lvl, min_lvl_name=Translator.translate(f'perm_lvl_{lvl}', ctx))}"
                 )
             elif perm_lvl > perm_dict["max"]:
                 lvl = cog.permissions['max']
                 await ctx.send(
                     f"{Emoji.get_chat_emoji('NO')} {Translator.translate('command_max_perm_violation', ctx, command=command, max_lvl=lvl, max_lvl_name=Translator.translate(f'perm_lvl_{lvl}', ctx))}"
                 )
             else:
                 overrides = Configuration.getConfigVar(
                     ctx.guild.id, "PERM_OVERRIDES")
                 if cog_name not in overrides:
                     overrides[cog_name] = {
                         "required": perm_lvl,
                         "commands": {},
                         "people": []
                     }
                 override = overrides[cog_name]
                 parts = command.split(" ")
                 while len(parts) > 0:
                     part = parts.pop(0)
                     if not part in override["commands"]:
                         override["commands"][part] = override = {
                             "required": -1,
                             "commands": {},
                             "people": []
                         }
                     else:
                         override = override["commands"][part]
                 override["required"] = perm_lvl
                 Configuration.saveConfig(ctx.guild.id)
                 await ctx.send(
                     f"{Emoji.get_chat_emoji('YES')} {Translator.translate('command_override_confirmation', ctx, command=command, perm_lvl=perm_lvl, perm_lvl_name=Translator.translate(f'perm_lvl_{perm_lvl}', ctx))}"
                 )
         else:
             await ctx.send(
                 f"{Emoji.get_chat_emoji('NO')} {Translator.translate('invalid_override_lvl', ctx)}"
             )
     else:
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} {Translator.translate('command_not_found', ctx)}"
         )
Example #5
0
 def validate_configs(self):
     for guild in self.bot.guilds:
         for type in ("TRUSTED", "MOD", "ADMIN"):
             to_remove = []
             roles = Configuration.getConfigVar(guild.id, type + "_ROLES")
             for role in roles:
                 if discord.utils.get(guild.roles, id=role) is None:
                     to_remove.append(role)
             for role in to_remove:
                 roles.remove(role)
         Configuration.saveConfig(guild.id)
Example #6
0
 async def remove_cog_override(self, ctx, cog: str):
     overrides = Configuration.getConfigVar(ctx.guild.id, "PERM_OVERRIDES")
     if cog in overrides:
         overrides[cog]["required"] = -1
         Configuration.saveConfig(ctx.guild.id)
         await ctx.send(
             f"{Emoji.get_chat_emoji('YES')} {Translator.translate('cog_override_removed', ctx, cog=cog)}"
         )
     else:
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} {Translator.translate('cog_override_not_found', ctx, cog=cog)}"
         )
Example #7
0
async def remove_item(ctx, item, item_type, list_name="roles"):
    roles = Configuration.getConfigVar(ctx.guild.id,
                                       f"{item_type}_{list_name}".upper())
    sname = list_name[:-1] if list_name[-1:] == "s" else list_name
    if item.id not in roles:
        await ctx.send(
            f"{Emoji.get_chat_emoji('NO')} {Translator.translate(f'was_no_{item_type}_{sname}', ctx, item=item.name)}"
        )
    else:
        roles.remove(item.id)
        Configuration.saveConfig(ctx.guild.id)
        await ctx.send(
            f"{Emoji.get_chat_emoji('YES')} {Translator.translate(f'{item_type}_{sname}_removed', ctx, item=item.name)}"
        )
Example #8
0
 async def add_cog_override(self, ctx, cog:str, perm_lvl:int):
     if cog in ctx.bot.cogs:
         cogo = ctx.bot.cogs[cog]
         if cogo.critical:
             await ctx.send(f"{Emoji.get_chat_emoji('NO')} The {cog} cog is a core cog that does not allow permission overrides")
         elif perm_lvl in range(6):
             if perm_lvl < cogo.cog_perm:
                 await ctx.send(f"{Emoji.get_chat_emoji('NO')} The {cog} cog is has a minimum permission lvl of {cogo.cog_perm} ({self.perm_lvls[cogo.cog_perm]})")
             else:
                 overrides = Configuration.getConfigVar(ctx.guild.id, "COG_OVERRIDES")
                 overrides[cog] = perm_lvl
                 Configuration.saveConfig(ctx.guild.id)
                 await ctx.send(f"{Emoji.get_chat_emoji('YES')} The {cog} cog permission lvl is now set at {perm_lvl} ({self.perm_lvls[perm_lvl]})")
         else:
             await ctx.send(f"{Emoji.get_chat_emoji('NO')} Please specify a permissions value of 0 (public), 1 (trusted), 2 (mod), 3 (admin), 4 (server owner only) or 5 (disabled)")
     else:
         await ctx.send(f"{Emoji.get_chat_emoji('NO')} I can't find any cog by that name")
Example #9
0
async def add_item(ctx, item, item_type, list_name="roles"):
    roles = Configuration.getConfigVar(ctx.guild.id,
                                       f"{item_type}_{list_name}".upper())
    sname = list_name[:-1] if list_name[-1:] == "s" else list_name
    if item == ctx.guild.default_role:
        return await ctx.send(
            f"{Emoji.get_chat_emoji('NO')} {Translator.translate(f'default_role_forbidden', ctx)}"
        )
    if item.id in roles:
        await ctx.send(
            f"{Emoji.get_chat_emoji('NO')} {Translator.translate(f'already_{item_type}_{sname}', ctx, item=item.name)}"
        )
    else:
        roles.append(item.id)
        Configuration.saveConfig(ctx.guild.id)
        await ctx.send(
            f"{Emoji.get_chat_emoji('YES')} {Translator.translate(f'{item_type}_{sname}_added', ctx, item=item.name)}"
        )
Example #10
0
 async def add_command_override(self, ctx, command:str, perm_lvl:int):
     command_object = self.bot.get_command(command)
     if command_object is not None:
         cog = command_object.instance
         cog_name = command_object.cog_name
         if cog.critical:
             await ctx.send(f"{Emoji.get_chat_emoji('NO')} The {command} command is part of the {cog_name} core cog that does not allow permission overrides")
         elif perm_lvl in range(6):
             if perm_lvl < cog.cog_perm:
                 await ctx.send(f"{Emoji.get_chat_emoji('NO')} The {command} command is part of the {cog_name} cog that has a minimum permission lvl of {cog.cog_perm} ({self.perm_lvls[cog.cog_perm]})")
             else:
                 overrides = Configuration.getConfigVar(ctx.guild.id, "COMMAND_OVERRIDES")
                 overrides[command] = perm_lvl
                 Configuration.saveConfig(ctx.guild.id)
                 await ctx.send(f"{Emoji.get_chat_emoji('YES')} The {command} permission lvl is now set at {perm_lvl} ({self.perm_lvls[perm_lvl]})")
         else:
             await ctx.send(f"{Emoji.get_chat_emoji('NO')} Please specify a permissions value of 0 (public), 1 (trusted), 2 (mod), 3 (admin), 4 (server owner only) or 5 (disabled)")
     else:
         await ctx.send(f"{Emoji.get_chat_emoji('NO')} I can't find any command by that name")
Example #11
0
 async def add_cog_override(self, ctx, cog: str, perm_lvl: int):
     if cog in ctx.bot.cogs:
         cogo = ctx.bot.cogs[cog]
         if not hasattr(cogo, "permissions"):
             await ctx.send(
                 f"{Emoji.get_chat_emoji('NO')} {Translator.translate('core_cog_no_override', ctx, cog=cog)}"
             )
         elif perm_lvl in range(7):
             min_lvl = cogo.permissions["min"]
             max_lvl = cogo.permissions["max"]
             if perm_lvl < min_lvl:
                 await ctx.send(
                     f"{Emoji.get_chat_emoji('NO')} {Translator.translate('cog_min_perm_violation', ctx, cog=cog, min_lvl=min_lvl, min_lvl_name=Translator.translate(f'perm_lvl_{min_lvl}', ctx))}"
                 )
             elif perm_lvl > max_lvl:
                 await ctx.send(
                     f"{Emoji.get_chat_emoji('NO')} {Translator.translate('cog_max_perm_violation', ctx, cog=cog, max_lvl=max_lvl, max_lvl_name=Translator.translate(f'perm_lvl_{max_lvl}', ctx))}"
                 )
             else:
                 overrides = Configuration.getConfigVar(
                     ctx.guild.id, "PERM_OVERRIDES")
                 if cog not in overrides:
                     overrides[cog] = {
                         "required": perm_lvl,
                         "commands": {},
                         "people": []
                     }
                 else:
                     overrides[cog]["required"] = perm_lvl
                 Configuration.saveConfig(ctx.guild.id)
                 await ctx.send(
                     f"{Emoji.get_chat_emoji('YES')} {Translator.translate('cog_override_applied', ctx, cog=cog, perm_lvl=perm_lvl, perm_lvl_name=Translator.translate(f'perm_lvl_{perm_lvl}', ctx))}"
                 )
         else:
             await ctx.send(
                 f"{Emoji.get_chat_emoji('NO')} {Translator.translate('invalid_override_lvl', ctx)}"
             )
     else:
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} {Translator.translate('cog_not_found', ctx)}"
         )
Example #12
0
 async def remove_command_override(self, ctx, command: str):
     command_object = self.bot.get_command(command)
     if command_object is not None:
         cog = command_object.instance
         cog_name = command_object.cog_name
         overrides = Configuration.getConfigVar(ctx.guild.id,
                                                "PERM_OVERRIDES")
         found = False
         if cog_name in overrides:
             override = Permissioncheckers.get_perm_dict(
                 command.split(" "), overrides[cog_name], True)
             if override is not None:
                 found = True
                 override["required"] = -1
                 Configuration.saveConfig(ctx.guild.id)
                 await ctx.send(
                     f"{Emoji.get_chat_emoji('YES')} {Translator.translate('command_override_removed', ctx, command=command)}"
                 )
         if not found:
             await ctx.send(
                 f"{Emoji.get_chat_emoji('NO')} {Translator.translate('command_override_not_found', ctx, command=command)}"
             )
Example #13
0
 async def on_guild_role_delete(self, role: discord.Role):
     roles = Configuration.getConfigVar(role.guild.id, "SELF_ROLES")
     if role.id in roles:
         roles.remove(role.id)
         Configuration.saveConfig(role.guild.id)