def archive(self, ctx, user: discord.User, amount: int, *, flags: converters.Flags={}):
"""
Fetches logged messages from a user.
Only Dogbot Moderators can do this.
The amount you specify is not equal to the amount of messages that will be shown to you.
Rather, it will be the amount of messages that are fetched from the bot's database.
Flags allow you to specify which messages you want to see, or how you want to see them.
For more information, see https://github.com/slice/dogbot/wiki/Message-Logging.
"""
async with ctx.acquire() as conn:
fetch_sql = """
SELECT * FROM messages WHERE author_id = $1 AND guild_id = $2 ORDER BY created_at DESC LIMIT $3
"""
messages = await conn.fetch(fetch_sql, user.id, ctx.guild.id, amount)
paginator = commands.Paginator()
flag_processors = {
'has-attachments': lambda value, msg: json.loads(msg['attachments']),
'contains': lambda value, msg: value in msg,
'edited': lambda value, msg: msg['edited'],
'deleted': lambda value, msg: msg['deleted'],
'channel': lambda value, msg: msg['channel_id'] == int(value),
'mentions': lambda value, msg: re.search(f'<@!?{value}>', content) is None
}
# add messages
for msg in messages:
content = msg['new_content'] or msg['original_content']
failed_flags = False
for flag_name, processor in flag_processors.items():
if flag_name in flags and not processor(flags[flag_name], msg):
failed_flags = True
if not failed_flags:
paginator.add_line(format_record(msg, flags))
# send pages
if not paginator.pages:
return await ctx.send('```No results.```')
for page in paginator.pages:
await ctx.send(page)
评论列表
文章目录