Пример #1
0
    async def load(self, ctx, backup_id, *options):
        """
        Load a backup


        __Arguments__

        **backup_id**: The id of the backup or the guild id of the latest automated backup
        **options**: A list of options (See examples)


        __Examples__

        Default options: ```{c.prefix}backup load oj1xky11871fzrbu```
        Only roles: ```{c.prefix}backup load oj1xky11871fzrbu !* roles```
        Everything but bans: ```{c.prefix}backup load oj1xky11871fzrbu !bans```
        """
        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 deleted** and reconstructed from the backup!\n"
            "**Messages will not get loaded** and will be lost, use "
            "[Xenon Pro](https://www.patreon.com/merlinfuchs) to load up to 25 messages per channel.",
            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** to load the backup."
            )

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

        handler = BackupLoader(self.bot, self.bot.session, backup["backup"])
        await handler.load(
            ctx.guild, ctx.author,
            types.BooleanArgs(
                ["channels", "roles", "bans", "members", "settings"] +
                list(options)))
        await ctx.guild.text_channels[0].send(
            **ctx.em("Successfully loaded backup.", type="success"))
Пример #2
0
    async def load(self, ctx, template_name, *options):
        """
        Load a template
        You can find templates in the #template-list and #featured-templates channels on the support discord.
        The template name is always the first line of the message (e.g. "starter"), you don't need the backup id!
        You can also use `{c.prefix}backup search <search-term>` to find templates.


        __Arguments__

        **template_name**: The name of the template


        __Examples__

        Default options ```{c.prefix}template load starter```
        Only roles ```{c.prefix}template load starter !* roles```
        """
        template_name = template_name.lower().replace(" ", "_")
        template = await ctx.db.templates.find_one(template_name)
        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:
            await warning.delete()
            raise cmd.CommandError(
                "Please make sure to **click the ✅ reaction** in order to load the template."
            )

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

        await ctx.db.templates.update_one({"_id": template_name},
                                          {"$inc": {
                                              "used": 1
                                          }})
        handler = BackupLoader(self.bot, self.bot.session,
                               template["template"])
        await handler.load(
            ctx.guild, ctx.author,
            types.BooleanArgs(["channels", "roles"] + list(options)))
Пример #3
0
    async def load(self, ctx, *, template_name):
        """
        Load a template


        __Arguments__

        **template_name**: The name of the template


        __Examples__

        ```{c.prefix}template load starter```
        """
        template_name = template_name.lower().replace(" ", "_")
        template = await ctx.db.templates.find_one(template_name)
        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:
            await warning.delete()
            raise cmd.CommandError(
                "Please make sure to **click the ✅ reaction** in order to load the template."
            )

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

        await ctx.db.templates.update_one({"_id": template_name}, {"$inc": {"used": 1}})
        handler = BackupLoader(self.bot, self.bot.session, template["template"])
        await handler.load(ctx.guild, ctx.author, types.BooleanArgs(
            ["channels", "roles"]
        ))