Esempio n. 1
0
        async def _run_interval_backups(interval):
            try:
                try:
                    guild = await self.bot.fetch_full_guild(interval["guild"])
                except (wkr.NotFound, wkr.Forbidden):
                    await self.bot.db.intervals.delete_many(
                        {"guild": interval["guild"]})
                    return

                backup = BackupSaver(self.bot, guild)
                await backup.save()

                await self.bot.db.backups.delete_one({
                    "creator":
                    interval["user"],
                    "data.id":
                    guild.id,
                    "interval":
                    True
                })
                await self.bot.db.backups.insert_one({
                    "_id":
                    utils.unique_id(),
                    "creator":
                    interval["user"],
                    "timestamp":
                    datetime.utcnow(),
                    "interval":
                    True,
                    "data":
                    backup.data
                })
            finally:
                semaphore.release()
Esempio n. 2
0
    async def create(self, ctx):
        """
        Create a backup
        
        Get more help on the [wiki](https://wiki.xenon.bot/backups#creating-a-backup).


        __Examples__

        ```{b.prefix}backup create```
        """
        backup_count = await ctx.bot.db.backups.count_documents(
            {"creator": ctx.author.id})
        if backup_count >= MAX_BACKUPS:
            raise ctx.f.ERROR(
                f"You have **exceeded the maximum count** of backups. (`{backup_count}/{MAX_BACKUPS}`)\n"
                f"You need to **delete old backups** with `{ctx.bot.prefix}backup delete <id>` or **buy "
                f"[Xenon Premium](https://www.patreon.com/merlinfuchs)** to create new backups.\n\n"
                f"*You can view your current backups by doing `{ctx.bot.prefix}backup list`.*"
            )

        status_msg = await ctx.f_send("**Creating Backup** ...",
                                      f=ctx.f.WORKING)
        guild = await ctx.fetch_full_guild()
        backup = BackupSaver(ctx.client, guild)
        await backup.save()

        backup_id = utils.unique_id()
        try:
            await ctx.bot.db.backups.insert_one({
                "_id": backup_id,
                "creator": ctx.author.id,
                "timestamp": datetime.utcnow(),
                "data": backup.data
            })
        except mongoerrors.DocumentTooLarge:
            raise ctx.f.ERROR(
                f"This backups **exceeds** the maximum size of **16 Megabyte**. Your server probably has a lot of "
                f"members and channels containing messages. Try to create a new backup with less messages (chatlog)."
            )

        embed = ctx.f.format(
            f"Successfully **created backup** with the id `{backup_id.upper()}`.",
            f=ctx.f.SUCCESS)["embed"]
        embed.setdefault("fields", []).append({
            "name":
            "Usage",
            "value":
            f"```{ctx.bot.prefix}backup load {backup_id.upper()}```\n"
            f"```{ctx.bot.prefix}backup info {backup_id.upper()}```"
        })
        await ctx.client.edit_message(status_msg, embed=embed)
        await ctx.bot.create_audit_log(utils.AuditLogType.BACKUP_CREATE,
                                       [ctx.guild_id], ctx.author.id)
Esempio n. 3
0
    async def create(self, ctx, name, *, description):
        """
        Create a **PUBLIC** template from this server
        Use `{b.prefix}backup create` if you simply want to save or clone your server.


        __Examples__

        ```{b.prefix}template create starter A basic template for new servers```
        """
        if len(description) < 30:
            raise ctx.f.ERROR(
                "The template **description** must be at least **30 characters** long."
            )

        name = name.lower().replace(" ", "-").replace("_", "-")
        status_msg = await ctx.f_send("**Creating Template** ...",
                                      f=ctx.f.WORKING)

        guild = await ctx.get_full_guild()
        backup = BackupSaver(ctx.client, guild)
        await backup.save()

        template = {
            "_id": name,
            "description": description,
            "creator": ctx.author.id,
            "timestamp": datetime.utcnow(),
            "uses": 0,
            "approved": False,
            "featured": False,
            "data": backup.data
        }

        try:
            await ctx.bot.db.templates.insert_one(template)
        except pymongo.errors.DuplicateKeyError:
            await ctx.client.edit_message(
                status_msg,
                **ctx.f.format(
                    f"There is **already a template** with the **name `{name}`**.",
                    f=ctx.f.ERROR))
            return

        await ctx.client.edit_message(
            status_msg,
            **ctx.f.format(
                f"Successfully **created template** with the name `{name}`.\n"
                f"The template will **not appear in the template list until it was approved** by a moderator.",
                f=ctx.f.SUCCESS))

        await self._send_to_approval(template)
Esempio n. 4
0
    async def run_interval_backups(self, guild_id):
        guild = await self.bot.get_full_guild(guild_id)
        if guild is None:
            return

        backup = BackupSaver(self.bot, guild)
        await backup.save()

        await self.bot.db.backups.replace_one({"_id": guild_id}, {
            "_id": guild_id,
            "creator": guild.owner_id,
            "timestamp": datetime.utcnow(),
            "interval": True,
            "data": backup.data
        }, upsert=True)
Esempio n. 5
0
        async def _run_interval_backups(interval):
            guild = await self.bot.get_full_guild(interval["guild"])
            if guild is None:
                return

            backup = BackupSaver(self.bot, guild)
            await backup.save()

            await self.bot.db.backups.delete_one({"creator": interval["user"], "data.id": guild.id, "interval": True})
            await self.bot.db.backups.insert_one({
                "_id": utils.unique_id(),
                "creator": interval["user"],
                "timestamp": datetime.utcnow(),
                "interval": True,
                "data": backup.data
            })
Esempio n. 6
0
    async def create(self, ctx):
        """
        Create a backup


        __Examples__

        ```{b.prefix}backup create```
        """
        backup_count = await ctx.bot.db.backups.count_documents({"creator": ctx.author.id})
        if backup_count >= MAX_BACKUPS:
            raise ctx.f.ERROR(
                f"You have **exceeded the maximum count** of backups. (`{backup_count}/{MAX_BACKUPS}`)\n"
                f"You need to **delete old backups** with `{ctx.bot.prefix}backup delete <id>` or **buy "
                f"[Xenon Premium](https://www.patreon.com/merlinfuchs)** to create new backups.."
            )

        status_msg = await ctx.f_send("**Creating Backup** ...", f=ctx.f.WORKING)
        guild = await ctx.get_full_guild()
        backup = BackupSaver(ctx.client, guild)
        await backup.save()

        backup_id = utils.unique_id()
        await ctx.bot.db.backups.insert_one({
            "_id": backup_id,
            "creator": ctx.author.id,
            "timestamp": datetime.utcnow(),
            "data": backup.data
        })

        embed = ctx.f.format(f"Successfully **created backup** with the id `{backup_id}`.", f=ctx.f.SUCCESS)["embed"]
        embed.setdefault("fields", []).append({
            "name": "Usage",
            "value": f"```{ctx.bot.prefix}backup load {backup_id}```\n"
                     f"```{ctx.bot.prefix}backup info {backup_id}```"
        })
        await ctx.client.edit_message(status_msg, embed=embed)