Ejemplo n.º 1
0
    def update_config_from_1_to_2(self, old_config):
        """
        Updates the configuration from version 1 (indicator: contains '_prefix') to version 2

        :param old_config: the old config dict
        """
        logging.info("Update Custom CMD config from version 1 to version 2")

        new_config = self.default_config()
        new_config['prefix'] = old_config['_prefix']

        logging.info(f"Converting {len(old_config) - 1} custom commands...")
        new_cmds = {}
        for cmd in old_config.keys():
            if cmd == '_prefix':
                continue
            cmd_name = cmd.lower()

            if cmd_name in new_cmds:
                new_cmds[cmd_name]['texts'].append(old_config[cmd])
            else:
                new_cmds[cmd_name] = Cmd(cmd_name, 0,
                                         [old_config[cmd]]).serialize()

        Storage.set(self, new_cmds)  #
        Config.save(self)
        Storage.save(self)
        logging.info("Converting finished.")
Ejemplo n.º 2
0
    def save(self):
        """Saves the commands to the storage and the plugin config"""
        cmd_dict = {}
        for k in self.commands:
            cmd_dict[k] = self.commands[k].serialize()

        Storage.set(self, cmd_dict)
        Storage.save(self)

        Config.save(self)
Ejemplo n.º 3
0
    async def dsc_set_config(self, ctx, key="", value=""):
        if not key and not value:
            await ctx.invoke(self.bot.get_command("configdump"), self.get_name())
            return

        if key and not value:
            key_value = Config.get(self).get(key, None)
            if key_value is None:
                await ctx.message.add_reaction(Lang.CMDERROR)
                await ctx.send(Lang.lang(self, 'key_not_exists', key))
            else:
                await ctx.message.add_reaction(Lang.CMDSUCCESS)
                await ctx.send(key_value)
            return

        if key == "channel_id":
            channel = None
            int_value = Config.get(self)['channel_id']
            try:
                int_value = int(value)
                channel = self.bot.guild.get_channel(int_value)
            except ValueError:
                pass
            if channel is None:
                Lang.lang(self, 'channel_id_int')
                await ctx.message.add_reaction(Lang.CMDERROR)
                return
            else:
                Config.get(self)[key] = int_value

        elif key == "songmaster_role_id":
            role = None
            int_value = Config.get(self)['songmaster_role_id']
            try:
                int_value = int(value)
                role = self.bot.guild.get_role(int_value)
            except ValueError:
                pass
            if role is None:
                Lang.lang(self, 'songmaster_id')
                await ctx.message.add_reaction(Lang.CMDERROR)
                return
            else:
                Config.get(self)[key] = int_value

        else:
            Config.get(self)[key] = value

        Config.save(self)
        await ctx.message.add_reaction(Lang.CMDSUCCESS)