Beispiel #1
0
    async def run_backup(self, guild_id):
        guild = self.bot.get_guild(guild_id)
        if guild is None:
            return

        handler = BackupSaver(self.bot, self.bot.session, guild)
        data = await handler.save()
        await self._save_backup(guild.owner_id, data, id=str(guild_id))
Beispiel #2
0
    async def create(self, ctx):
        """
        Create a backup


        __Examples__

        ```{c.prefix}backup create```
        """
        backup_count = await ctx.db.backups.count_documents(
            {"creator": ctx.author.id})
        if backup_count >= max_backups:
            raise cmd.CommandError(
                "You have **exceeded the maximum count** of backups.\n\n"
                f"Upgrade to Pro (`x!pro`) to be able to create more than **{max_backups}**. "
                f"backups **or delete one of your old backups** (`x!backup list` "
                f"& `x!backup delete <id>`).")

        status = await ctx.send(
            **ctx.em("**Creating backup** ... Please wait", type="working"))
        handler = BackupSaver(self.bot, self.bot.session, ctx.guild)
        backup = await handler.save()
        id = await self._save_backup(ctx.author.id, backup)

        embed = ctx.em(
            f"Successfully **created backup** with the id `{id}`.\n",
            type="success")["embed"]
        embed.add_field(
            name="Usage",
            value=
            f"```{ctx.prefix}backup load {id}```\n```{ctx.prefix}backup info {id}```"
        )
        await status.edit(embed=embed)
        try:
            if ctx.author.is_on_mobile():
                await ctx.author.send(f"{ctx.prefix}backup load {id}")

            else:
                embed = ctx.em(
                    f"Created backup of **{ctx.guild.name}** with the backup id `{id}`\n",
                    type="info")["embed"]
                embed.add_field(
                    name="Usage",
                    value=
                    f"```{ctx.prefix}backup load {id}```\n```{ctx.prefix}backup info {id}```"
                )
                await ctx.author.send(embed=embed)

        except Exception:
            pass