async def log_dump(self, ctx, *, condition: str = None): """ Dump previous journal events that match the given conditions to JSON. The condition is a Python expression with no variables but the following attributes: path: str ppath: PurePath guild: discord.Guild content: str attributes: dict """ events, error_embeds = self.log_filter(ctx.guild, condition, 50) if error_embeds: await ctx.send(embed=error_embeds[0]) buffer = StringBuilder() obj = [event.to_dict() for event in reversed(events)] json.dump(obj, buffer, ensure_ascii=True) file = discord.File(buffer.bytes_io(), filename="journal-events.json") embed = discord.Embed(colour=discord.Colour.dark_teal()) embed.description = ( "Uploaded journal events as JSON, see attached file. " "\N{WHITE UP POINTING BACKHAND INDEX}" ) await ctx.send(embed=embed, file=file)
def dump_messages(messages): buffer = StringBuilder() obj = list(map(message_dict, reversed(messages))) json.dump(obj, buffer, ensure_ascii=True, indent=4) return obj, discord.File(buffer.bytes_io(), filename="deleted-messages.json")