Exemple #1
0
    async def load(self, ctx, backup_id, chatlog: int = 20, *load_options):
        """
        Load a backup


        backup_id ::    The id of the backup

        chatlog   ::    The count of messages to load per channel (max. 20) (default 20)
        """
        chatlog = chatlog if chatlog < max_chatlog and chatlog >= 0 else max_chatlog
        backup = await ctx.db.table("backups").get(backup_id).run(ctx.db.con)
        if backup is None or backup.get("creator") != str(ctx.author.id):
            raise cmd.CommandError(
                f"You have **no backup** with the id `{backup_id}`.")

        warning = await ctx.send(**ctx.em(
            "Are you sure you want to load this backup? **All channels and roles will get replaced!**",
            type="warning"))
        await warning.add_reaction("✅")
        await warning.add_reaction("❌")
        try:
            reaction, user = await self.bot.wait_for(
                "reaction_add",
                check=lambda r, u: r.message.id == warning.id and u.id == ctx.
                author.id,
                timeout=60)
        except TimeoutError:
            raise cmd.CommandError(
                "Please make sure to **click the ✅ reaction** in order to load the backup."
            )
            await warning.delete()

        if str(reaction.emoji) != "✅":
            ctx.command.reset_cooldown(ctx)
            await warning.delete()
            return

        if len(load_options) == 0:
            options = {
                "channels": True,
                "roles": True,
                "bans": True,
                "members": True,
                "settings": True
            }

        else:
            options = {}
            for opt in load_options:
                options[opt.lower()] = True

        handler = BackupLoader(self.bot, self.bot.session, backup["backup"])
        await handler.load(ctx.guild, ctx.author, chatlog, **options)
        await ctx.guild.text_channels[0].send(
            **ctx.em("Successfully loaded backup.", type="success"))
Exemple #2
0
    async def load(self, ctx, backup_id, *load_options):
        """
        Load a backup


        backup_id ::    The id of the backup or the guild id to for latest automated backup
        """
        backup_id = str(
            ctx.guild.id) if backup_id.lower() == "interval" else backup_id
        backup = await self._get_backup(backup_id)
        if backup is None or backup.get("creator") != ctx.author.id:
            raise cmd.CommandError(
                f"You have **no backup** with the id `{backup_id}`.")

        warning = await ctx.send(**ctx.em(
            "Are you sure you want to load this backup? **All channels and roles will get replaced!**",
            type="warning"))
        await warning.add_reaction("✅")
        await warning.add_reaction("❌")
        try:
            reaction, user = await self.bot.wait_for(
                "reaction_add",
                check=lambda r, u: r.message.id == warning.id and u.id == ctx.
                author.id,
                timeout=60)
        except TimeoutError:
            await warning.delete()
            raise cmd.CommandError(
                "Please make sure to **click the ✅ reaction** in order to load the backup."
            )

        if str(reaction.emoji) != "✅":
            ctx.command.reset_cooldown(ctx)
            await warning.delete()
            return

        if len(load_options) == 0:
            options = {
                "channels": True,
                "roles": True,
                "bans": True,
                "members": False,
                "settings": True
            }

        else:
            options = {}
            for opt in load_options:
                options[opt.lower()] = True

        handler = BackupLoader(self.bot, self.bot.session, backup["backup"])
        await handler.load(ctx.guild, ctx.author, chatlog=0, **options)
        await ctx.guild.text_channels[0].send(
            **ctx.em("Successfully loaded backup.", type="success"))
Exemple #3
0
    async def load(self, ctx, *, template_name):
        """
        Load a template


        template_name ::    The name of the template
        """
        template_name = template_name.lower().replace(" ", "_")
        template = await ctx.db.table("templates").get(template_name).run(
            ctx.db.con)
        if template is None:
            raise cmd.CommandError(
                f"There is **no template** with the name `{template_name}`.")

        warning = await ctx.send(**ctx.em(
            "Are you sure you want to load this template? **All channels and roles will get replaced!**",
            type="warning"))
        await warning.add_reaction("✅")
        await warning.add_reaction("❌")
        try:
            reaction, user = await self.bot.wait_for(
                "reaction_add",
                check=lambda r, u: r.message.id == warning.id and u.id == ctx.
                author.id,
                timeout=60)
        except TimeoutError:
            raise cmd.CommandError(
                "Please make sure to **click the ✅ reaction** in order to load the template."
            )
            await warning.delete()

        if str(reaction.emoji) != "✅":
            ctx.command.reset_cooldown(ctx)
            await warning.delete()
            return

        await ctx.db.table("templates").get(template_name).update({
            "loaded":
            ctx.db.row["loaded"] + 1
        }).run(ctx.db.con)
        handler = BackupLoader(self.bot, self.bot.session,
                               template["template"])
        await handler.load(ctx.guild, ctx.author, 0)