Exemplo n.º 1
0
 async def _rename_cmd(self, context, cmd_name: cmd_name_converter,
                       new_name: cmd_name_converter):
     parent, child, cmd = await analyze_existing_cmd(
         self.bot, context.guild, cmd_name, context)
     cmd_name = cmd["cmdname"]
     if cmd["lock"]:
         raise LookupError(
             f"Custom command '{cmd_name}' is locked and canot be edited.")
     attributes = json_load_dict(cmd["attributes"])
     permission = json_load_dict(cmd["perm"])
     guild = None if cmd["glob"] else context.guild
     old_cmd = parent.remove_command(child)
     try:
         new_parent, new_child, new_name = await analyze_new_cmd(
             self.bot, context.guild, new_name)
         new_cmd = set_new_cmd(guild, new_parent, new_child, cmd["message"],
                               attributes, cmd["isgroup"], permission)
     except Exception as e:
         parent.add_command(old_cmd)
         raise e
     # move all subcommands and update the names of commands in db
     self.move_subcommands(context.guild, new_cmd, old_cmd)
     await self.log_cmd_update(context, new_name, cmd["message"],
                               attributes, cmd["isgroup"],
                               "Renamed Command", cmd["glob"], permission)
Exemplo n.º 2
0
 async def _perm_cmd(self, context, cmd_name: cmd_name_converter,
                     groups: commands.Greedy[typing.Union[discord.Member,
                                                          discord.Role]]):
     parent, child, cmd = await analyze_existing_cmd(
         self.bot, context.guild, cmd_name, context)
     if not groups:
         permission = None
     else:
         permission = {"members": [], "roles": []}
         for group in groups:
             if isinstance(group, discord.Member):
                 permission["members"].append(group.id)
             elif isinstance(group, discord.Role):
                 permission["roles"].append(group.id)
     cmd_name = cmd["cmdname"]
     guild = None if cmd["glob"] else context.guild
     set_new_cmd(guild, parent, child, cmd["message"],
                 json_load_dict(cmd["attributes"]), cmd["isgroup"],
                 permission)
     self.bot.db[context.guild.id].query(
         f"UPDATE user_commands SET perm='{json.dumps(permission)}' WHERE cmdname='{cmd_name}'"
     )
     await context.send(f"Updated command '{cmd_name}' permission.")
     fields = {
         "Permission to":
         " ".join([group.mention for group in groups])
         if groups else str(context.guild.default_role)
     }
     await self.bot.log_message(context.guild,
                                "ADMIN_LOG",
                                user=context.author,
                                action="updated a command's permission",
                                description=f"Command:\n {cmd_name}",
                                fields=fields,
                                timestamp=context.message.created_at)
Exemplo n.º 3
0
 async def _rm_cmd(self, context, cmd_name: cmd_name_converter):
     parent, child, cmd = await analyze_existing_cmd(self.bot,
                                                     context.guild,
                                                     cmd_name,
                                                     context,
                                                     remove=True)
     cmd_name = cmd["cmdname"]
     if cmd["lock"]:
         raise LookupError(
             f"Custom command '{cmd_name}' is locked and canot be edited.")
     parent.remove_command(child)
     self.bot.db[context.guild.id].delete_row("user_commands", cmd_name)
     await self.log_cmd_update(context, cmd_name, cmd["message"],
                               json_load_dict(cmd["attributes"]),
                               cmd["isgroup"], "Removed Command",
                               cmd["glob"], json_load_dict(cmd["perm"]))
Exemplo n.º 4
0
 async def _rename_cmd(self, context, cmd_name: cmd_name_converter,
                       new_name: cmd_name_converter):
     parent, child, cmd_name = get_cmd_attributes(self.bot, cmd_name, True)
     new_parent, new_child, new_name = get_cmd_attributes(
         self.bot, new_name, False)
     cmd = self.bot.db[context.guild.id].select("user_commands", cmd_name)
     if cmd is not None:
         if cmd["lock"]:
             raise LookupError(
                 f"Custom command '{cmd_name}' is locked and canot be edited."
             )
         attributes = json_load_dict(cmd["attributes"])
         old_cmd = parent.remove_command(child)
         try:
             new_cmd = set_new_cmd(new_parent, new_child, cmd["message"],
                                   attributes, cmd["isgroup"])
             # move the commands
             if isinstance(old_cmd, commands.Group) and isinstance(
                     new_cmd, commands.Group):
                 for command in old_cmd.commands:  # move the commands from the old one to the new one
                     new_cmd.add_command(command)
                     self.bot.db[context.guild.id].query(
                         f"UPDATE user_commands SET cmdname='{new_name} {command.name}' WHERE cmdname='{cmd_name} {command.name}'"
                     )
             self.bot.db[context.guild.id].query(
                 f"UPDATE user_commands SET cmdname='{new_name}' WHERE cmdname='{cmd_name}' "
             )
             await self.log_cmd_update(context, new_name, cmd["message"],
                                       attributes, cmd["isgroup"],
                                       "Renamed Command")
         except Exception as e:
             parent.add_command(old_cmd)
             raise e
     else:
         raise LookupError(f"Custom command '{cmd_name}' not found.")
Exemplo n.º 5
0
 async def _global_cmd(self, context, cmd_name: cmd_name_converter):
     parent, child, cmd = await analyze_existing_cmd(
         self.bot, context.guild, cmd_name, context)
     cmd_name = cmd["cmdname"]
     if cmd["glob"]:
         await context.send(f"Command '{cmd_name}' is already global.")
         return
     set_new_cmd(None, parent, child, cmd["message"],
                 json_load_dict(cmd["attributes"]), cmd["isgroup"],
                 json_load_dict(cmd["perm"]))
     self.bot.db[context.guild.id].query(
         f'UPDATE user_commands SET glob=1 WHERE cmdname="{cmd_name}"')
     await context.send(f"Command '{cmd_name}' has become global.")
     await self.bot.log_message(context.guild,
                                "ADMIN_LOG",
                                user=context.author,
                                action="made a command global",
                                description=f"Command:\n {cmd_name}",
                                timestamp=context.message.created_at)
Exemplo n.º 6
0
 async def _update_cmd(self, context, cmd_name: cmd_name_converter, *,
                       cmd_args: cmd_arg_converter):
     attributes_new, cmd_text = cmd_args
     parent, child, cmd = await analyze_existing_cmd(
         self.bot, context.guild, cmd_name, context)
     cmd_name = cmd["cmdname"]
     if cmd["lock"]:
         raise LookupError(
             f"Custom command '{cmd_name}' is locked and canot be edited.")
     if not cmd_text and not cmd["isgroup"]:
         cmd_text = cmd["message"]
     attributes = json_load_dict(cmd["attributes"])
     permission = json_load_dict(cmd["perm"])
     attributes.update(attributes_new)
     guild = None if cmd["glob"] else context.guild
     set_new_cmd(guild, parent, child, cmd_text, attributes, cmd["isgroup"],
                 permission)
     await self.after_cmd_update(context, cmd_name, cmd_text, attributes,
                                 cmd["isgroup"], "Updated Command",
                                 cmd["glob"], permission)
Exemplo n.º 7
0
 async def _alias_cmd(self, context, cmd_name: cmd_name_converter,
                      *aliases):
     if len(aliases) == 0:
         raise commands.UserInputError(
             "aliases is a required argument that is missing.")
     parent, child, cmd = await analyze_existing_cmd(
         self.bot, context.guild, cmd_name, context)
     cmd_name = cmd["cmdname"]
     if cmd["lock"]:
         raise LookupError(
             f"Custom command '{cmd_name}' is locked and canot be edited.")
     attributes = json_load_dict(cmd["attributes"])
     permission = json_load_dict(cmd["perm"])
     if "aliases" not in attributes:
         attributes["aliases"] = []
     attributes["aliases"].extend(aliases)
     guild = None if cmd["glob"] else context.guild
     set_new_cmd(guild, parent, child, cmd["message"], attributes,
                 cmd["isgroup"], permission)
     await self.after_cmd_update(context, cmd_name, cmd["message"],
                                 attributes, cmd["isgroup"],
                                 "Added Aliases", cmd["glob"], permission)
Exemplo n.º 8
0
 async def _update_cmd(self, context, cmd_name: cmd_name_converter, *,
                       cmd_args: cmd_add_converter):
     attributes_new, cmd_text = cmd_args
     parent, child, cmd_name = get_cmd_attributes(self.bot, cmd_name, True)
     cmd = self.bot.db[context.guild.id].select("user_commands", cmd_name)
     if cmd is not None:
         if cmd["lock"]:
             raise LookupError(
                 f"Custom command '{cmd_name}' is locked and canot be edited."
             )
         if not cmd_text and not cmd["isgroup"]:
             cmd_text = cmd["message"]
         attributes = json_load_dict(cmd["attributes"])
         attributes.update(attributes_new)
         set_new_cmd(parent, child, cmd_text, attributes, cmd["isgroup"])
         await self.after_cmd_update(context, cmd_name, cmd_text,
                                     attributes, cmd["isgroup"],
                                     "Updated Command")
     else:
         raise LookupError(f"Custom command '{cmd_name}' not found.")
Exemplo n.º 9
0
 async def _alias_cmd(self, context, cmd_name: cmd_name_converter,
                      *aliases):
     if len(aliases) == 0:
         raise commands.UserInputError(
             "aliases is a required argument that is missing.")
     parent, child, cmd_name = get_cmd_attributes(self.bot, cmd_name, True)
     cmd = self.bot.db[context.guild.id].select("user_commands", cmd_name)
     if cmd is not None:
         if cmd["lock"]:
             raise LookupError(
                 f"Custom command '{cmd_name}' is locked and canot be edited."
             )
         attributes = json_load_dict(cmd["attributes"])
         if "aliases" not in attributes:
             attributes["aliases"] = []
         attributes["aliases"].extend(aliases)
         set_new_cmd(parent, child, cmd["message"], attributes,
                     cmd["isgroup"])
         await self.after_cmd_update(context, cmd_name, cmd["message"],
                                     attributes, cmd["isgroup"],
                                     "Added Aliases")
     else:
         raise LookupError(f"Custom command '{cmd_name}' not found.")