Exemplo n.º 1
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)}"
         )
Exemplo n.º 2
0
def gen_command_listing(bot, cog, command, code):
    try:
        perm_lvl = Permissioncheckers.get_perm_dict(
            command.qualified_name.split(' '), cog.permissions)['required']
        listing = f"| | | {Translator.translate_by_code(command.short_doc, code)} |\n"
        listing += f"|{command.qualified_name}|{Translator.translate_by_code(f'perm_lvl_{perm_lvl}', code)} ({perm_lvl})| |\n"
        signature = bot.help_command.get_command_signature(command).replace(
            "|", "ǀ")
        listing += f"| | |{Translator.translate_by_code('example', code)}: ``{signature}``|\n"
    except Exception as ex:
        GearbotLogging.error(command.qualified_name)
        raise ex
    return listing
Exemplo n.º 3
0
 async def remove_command_override(self, ctx, command:str):
     command = command.lower()
     command_object = self.bot.get_command(command)
     if command_object is not None:
         cog_name = command_object.cog_name
         overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES")
         found = False
         if cog_name in overrides:
             override = Permissioncheckers.get_perm_dict(command_object.qualified_name.split(" "), overrides[cog_name], True)
             if override is not None:
                 found = True
                 override["required"] = -1
                 Configuration.save(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)}")
Exemplo n.º 4
0
 async def remove_lvl4(self, ctx, command: str, person: discord.Member):
     command_object = self.bot.get_command(command)
     if command_object is not None:
         cog_name = command_object.cog_name
         overrides = Configuration.get_var(ctx.guild.id, "PERM_OVERRIDES")
         found = False
         if cog_name in overrides:
             lvl4_list = Permissioncheckers.get_perm_dict(command.split(" "), overrides[cog_name], strict=True)
             if lvl4_list is not None and person.id in lvl4_list["people"]:
                 found = True
         if found:
             lvl4_list["people"].remove(person.id)
             await ctx.send(f"{Emoji.get_chat_emoji('YES')} {Translator.translate('lvl4_removed', ctx, member=person, command=command)}")
             Configuration.save(ctx.guild.id)
         else:
             await ctx.send(
                 f"{Emoji.get_chat_emoji('NO')} {Translator.translate('did_not_have_lvl4', ctx, member=person, command=command)}")
Exemplo n.º 5
0
def gen_command_listing2(bot, cog, command):
    command_listing = dict()
    try:
        perm_lvl = Permissioncheckers.get_perm_dict(
            command.qualified_name.split(' '), cog.permissions)['required']
        command_listing["commandlevel"] = perm_lvl
        command_listing["description"] = command.short_doc
        command_listing["aliases"] = command.aliases
        example = bot.help_command.get_command_signature(command).strip()
        parts = str(example).split(' ')
        parts[0] = ''.join(parts[0][1:])
        for i in range(0, len(parts)):
            if "[" == parts[i][0] and "|" in parts[i]:
                parts[i] = ''.join(parts[i].split('|')[0][1:])
        command_listing["example"] = '!' + ' '.join(parts)
        command_listing["subcommands"] = {}
        return command_listing
    except Exception as ex:
        GearbotLogging.error(command.qualified_name)
        raise ex