Exemplo n.º 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)
        backup = await handler.save(max_chatlog)
        id = self.random_id()
        await self.bot.db.table("backups").insert({
            "id":
            id,
            "creator":
            str(guild.owner.id),
            "guild_id":
            str(guild_id),
            "timestamp":
            datetime.now(pytz.utc),
            "backup":
            backup
        }).run(self.bot.db.con)

        embed = self.bot.em(
            f"Created **automated** backup of **{guild.name}** with the Backup id `{id}`\n",
            type="info")["embed"]
        embed.add_field(
            name="Usage",
            value=
            f"```{self.bot.config.prefix}backup load {id}```\n```{self.bot.config.prefix}backup info {id}```"
        )
        await guild.owner.send(embed=embed)
Exemplo n.º 2
0
    async def create(self, ctx):
        """
        Create a backup
        """
        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(chatlog=0)
        id = await self._save_backup(ctx.author.id, backup)

        await status.edit(
            **ctx.em("Successfully **created backup**.", type="success"))
        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:
            traceback.print_exc()
            await status.edit(**ctx.em(
                "I was **unable to send you the backup-id**. Please make sure you have dm's enabled.",
                type="error"))
Exemplo n.º 3
0
    async def run_backup(self, guild_id):
        guild = self.bot.get_guild(guild_id)
        if guild is None:
            raise ValueError

        handler = BackupSaver(self.bot, self.bot.session, guild)
        data = await handler.save(0)
        await self._save_backup(guild.owner.id, data, id=str(guild_id))
Exemplo n.º 4
0
    async def create(self, ctx, chatlog: int = 45):
        """
        Create a backup


        chatlog ::      The count of messages to save per channel (max. 45) (default 45)
        """
        chatlog = chatlog if chatlog < max_chatlog and chatlog >= 0 else max_chatlog
        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(chatlog)
        id = self.random_id()
        await ctx.db.table("backups").insert({
            "id":
            id,
            "creator":
            str(ctx.author.id),
            "guild_id":
            str(ctx.guild.id),
            "timestamp":
            datetime.now(pytz.utc),
            "backup":
            backup
        }).run(ctx.db.con)

        await status.edit(
            **ctx.em("Successfully **created backup**.", type="success"))
        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:
            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.channel.send(embed=embed)
Exemplo n.º 5
0
    async def create(self, ctx, chatlog: int = 0):
        f"""
        Create a backup


        chatlog ::      The count of messages to save per channel (max. {max_chatlog}) (default 0)
        """
        try:
            await checks.check_role_on_support_guild("Xenon Pro")(ctx)
        except:
            if chatlog > 0:
                raise cmd.CommandError(
                    "You need **Xenon Pro** to save messages. Use `x!pro` for more information.")
        else:
            chatlog = chatlog if chatlog < max_chatlog and chatlog >= 0 else max_chatlog

        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(chatlog)
        id = self.random_id()
        await ctx.db.table("backups").insert({
            "id": id,
            "creator": str(ctx.author.id),
            "timestamp": datetime.now(pytz.utc),
            "backup": backup
        }).run(ctx.db.con)

        await status.edit(**ctx.em("Successfully **created backup**.", type="success"))
        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:
            traceback.print_exc()
            await status.edit(**ctx.em("I was **unable to send you the backup-id**. Please make sure you have dm's enabled.", type="error"))
Exemplo n.º 6
0
    async def create(self, ctx):
        """
        Create a backup
        """
        backup_count = await ctx.db.backups.count_documents(
            {"creator": ctx.author.id})
        if backup_count >= max_backups:
            raise cmd.CommandError(
                "You already **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(chatlog=0)
        id = await self._save_backup(ctx.author.id, backup)

        await status.edit(
            **ctx.em("Successfully **created backup**.", type="success"))
        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:
            traceback.print_exc()
            await status.edit(**ctx.em(
                "I was **unable to send you the backup-id**. Please make sure you have dm's enabled.",
                type="error"))
Exemplo n.º 7
0
    async def backup_loop(self):
        db = self.bot.db
        while True:
            try:
                await sleep(60)

                to_backup = self.to_backup.copy()
                self.to_backup = []
                for guild_id in to_backup:
                    guild = self.bot.get_guild(guild_id)
                    if guild is None:
                        continue

                    handler = BackupSaver(self.bot, self.bot.session, guild)
                    backup = await handler.save(max_chatlog)
                    id = self.random_id()
                    await db.table("backups").insert({
                        "id":
                        id,
                        "creator":
                        str(guild.owner.id),
                        "timestamp":
                        datetime.now(pytz.utc),
                        "backup":
                        backup
                    }).run(db.con)

                    embed = self.bot.em(
                        f"Created **automated** backup of **{guild.name}** with the Backup id `{id}`\n",
                        type="info")["embed"]
                    embed.add_field(
                        name="Usage",
                        value=
                        f"```{self.bot.config.prefix}backup load {id}```\n```{self.bot.config.prefix}backup info {id}```"
                    )
                    await guild.owner.send(embed=embed)
            except:
                traceback.print_exc()