Exemple #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.")
Exemple #2
0
    async def bugscore_increment(self, ctx, user, increment):
        if discord.utils.get(ctx.author.roles,
                             id=Config().BOTMASTER_ROLE_ID) is None:
            await ctx.message.add_reaction(Lang.CMDNOPERMISSIONS)
            return

        # find user
        try:
            user = await commands.MemberConverter().convert(ctx, user)
        except (commands.CommandError, IndexError):
            await ctx.send(Lang.lang(self, "bugscore_user_not_found", user))
            await ctx.message.add_reaction(Lang.CMDERROR)
            return

        try:
            increment = int(increment)
        except (ValueError, TypeError):
            await ctx.send(Lang.lang(self, "bugscore_nan", increment))
            await ctx.message.add_reaction(Lang.CMDERROR)
            return

        if user.id in self.storage["bugscore"]:
            self.storage["bugscore"][user.id] += increment
        else:
            self.storage["bugscore"][user.id] = increment
        if self.storage["bugscore"][user.id] <= 0:
            del self.storage["bugscore"][user.id]
        Storage.save(self)
        await ctx.message.add_reaction(Lang.CMDSUCCESS)
Exemple #3
0
 def write(self):
     r = {}
     for el in self.complaints:
         complaint = self.complaints[el]
         r[complaint.id] = complaint.serialize()
     Storage.get(self)["complaints"] = r
     Storage.save(self)
Exemple #4
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)
Exemple #5
0
    def save(self):
        """Saves the current ignorelist to json"""
        full_list = []
        full_list.extend(self.users)
        full_list.extend(self.cmds)
        full_list.extend(self.user_cmds)

        jsondata = []
        for el in full_list:
            jsondata.append(el.serialize())
        Storage.set(self, jsondata)
        Storage.save(self)
Exemple #6
0
    async def bugscore_del(self, ctx, user):
        if discord.utils.get(ctx.author.roles,
                             id=Config().BOTMASTER_ROLE_ID) is None:
            await ctx.message.add_reaction(Lang.CMDNOPERMISSIONS)
            return
        try:
            user = await commands.MemberConverter().convert(ctx, user)
        except (commands.CommandError, IndexError):
            await ctx.send(Lang.lang(self, "bugscore_user_not_found", user))
            await ctx.message.add_reaction(Lang.CMDERROR)
            return

        if user.id in self.storage["bugscore"]:
            del self.storage["bugscore"][user.id]
            Storage.save(self)
            await ctx.message.add_reaction(Lang.CMDSUCCESS)
        else:
            await ctx.message.add_reaction(Lang.CMDNOCHANGE)
Exemple #7
0
    def __init__(self, bot):
        super().__init__(bot)
        bot.register(self)

        self.storage = Storage.get(self)
        self.complaints = {}
        self.highest_id = None

        # Load complaints from storage
        if self.storage is None:
            self.storage = deepcopy(self.default_storage())
        else:
            print("Feedback storage: {}".format(self.storage))
            str_keys_to_int(self.storage["complaints"])
        for cid in self.storage["complaints"]:
            self.complaints[cid] = Complaint.deserialize(
                self.bot, cid, self.storage["complaints"][cid])

        # Migration 1.7 -> 1.8
        if "bugscore" not in self.storage:
            self.storage["bugscore"] = {}
            Storage.save(self)

        self.get_new_id(init=True)