async def info(self, ctx, backup_id): """ Get information about a backup backup_id:: The id of the backup """ 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}`.") handler = BackupInfo(self.bot, backup["backup"]) embed = ctx.em("")["embed"] embed.title = handler.name embed.set_thumbnail(url=handler.icon_url) embed.add_field(name="Creator", value=f"<@{backup['creator']}>") embed.add_field(name="Members", value=handler.member_count, inline=True) embed.add_field(name="Created At", value=helpers.datetime_to_string(backup["timestamp"]), inline=False) embed.add_field(name="Channels", value=handler.channels(), inline=True) embed.add_field(name="Roles", value=handler.roles(), inline=True) await ctx.send(embed=embed)
def template_info(self, ctx, name, template): handler = BackupInfo(ctx.bot, template["template"]) embed = ctx.em("")["embed"] embed.title = name embed.description = template["description"] embed.add_field(name="Creator", value=f"<@{template['creator']}>") embed.add_field(name="Channels", value=handler.channels(), inline=True) embed.add_field(name="Roles", value=handler.roles(), inline=True) return embed
def _template_info(self, template): handler = BackupInfo(self.bot, template["template"]) embed = Embed(color=0x36393e) embed.title = template["_id"] embed.description = template["description"] embed.add_field(name="Creator", value=f"<@{template['creator']}>") embed.add_field(name="Channels", value=handler.channels(), inline=True) embed.add_field(name="Roles", value=handler.roles(), inline=True) return embed
async def info(self, ctx, backup_id): """ Get information about a backup backup_id:: The id of the backup """ 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}`.") handler = BackupInfo(self.bot, backup["backup"]) embed = ctx.em("")["embed"] embed.title = handler.name embed.set_thumbnail(url=handler.icon_url) embed.add_field(name="Creator", value=f"<@{backup['creator']}>") embed.add_field(name="Members", value=handler.member_count, inline=True) embed.add_field(name="Created At", value=helpers.datetime_to_string( backup["timestamp"]), inline=False ) embed.add_field(name="Channels", value=handler.channels(), inline=True) embed.add_field(name="Roles", value=handler.roles(), inline=True) try: if backup.get("paste") is None: await checks.check_role_on_support_guild("Xenon Pro")(ctx) response = await self.bot.session.post( url="https://api.paste.ee/v1/pastes", headers={"X-Auth-Token": ctx.config.pasteee_key}, json={ "description": f"Additional information for backup with the id '{backup_id}'", "expiration": "never", "sections": [ { "name": "Bans", "contents": "\n".join([f"{ban['user']}\t{ban['reason']}" for ban in backup["backup"]["bans"]]) }, { "name": "Members", "contents": "\n".join([f"{member['name']}#{member['discriminator']}\t({member['id']})" for member in backup["backup"]["members"]]) } ] } ) paste_url = (await response.json())["link"] await ctx.db.table("backups").get(backup_id).update({"paste": paste_url}).run(ctx.db.con) else: paste_url = backup.get("paste") except: pass else: embed.url = paste_url embed.set_footer(text="Click the title for more information and a list of members") await ctx.send(embed=embed)
async def list(self, ctx): """ Get a list of recent backups """ backups = await ctx.db.table("backups").get_all( str(ctx.guild.id), index='guild_id').order_by(ctx.db.desc('timestamp')).filter({ "creator": str(ctx.author.id) }).limit(10).run(ctx.db.con) embed = ctx.em("")["embed"] embed.title = "Your most recent backups for this guild" description = "" for backup in backups: handler = BackupInfo(self.bot, backup["backup"]) description += ('**' + handler.name + '** (`' + backup["id"] + '`) **Created at: ** `' + helpers.datetime_to_string(backup["timestamp"]) + '`\n') if description == "": raise cmd.CommandError( "You've not made any backups of this server!") embed.description = description embed.set_footer(text="All times are in UTC") await ctx.send(embed=embed)