Skip to content
24 changes: 24 additions & 0 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,30 @@ async def logs_closed_by(self, ctx, *, user: User = None):
session = EmbedPaginatorSession(ctx, *embeds)
await session.run()

@logs.command(name="key", aliases=["id"])
@checks.has_permissions(PermissionLevel.SUPPORTER)
async def logs_key(self, ctx, key: str):
"""
Get the log link for the specified log key
"""
icon_url = ctx.author.avatar.url

logs = await self.bot.api.find_log_entry(key)

if not logs:
embed = discord.Embed(
color=self.bot.error_color,
description=f"Log entry `{key}` not found.",
)
return await ctx.send(embed=embed)

logs = list(reversed(logs))

embeds = self.format_log_embeds(logs, avatar_url=icon_url)

session = EmbedPaginatorSession(ctx, *embeds)
await session.run()

@logs.command(name="delete", aliases=["wipe"])
@checks.has_permissions(PermissionLevel.OWNER)
async def logs_delete(self, ctx, key_or_link: str):
Expand Down
10 changes: 10 additions & 0 deletions core/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ async def validate_database_connection(self):
async def get_user_logs(self, user_id: Union[str, int]) -> list:
return NotImplemented

async def find_log_entry(self, key: str) -> list:
return NotImplemented

async def get_latest_user_logs(self, user_id: Union[str, int]):
return NotImplemented

Expand Down Expand Up @@ -529,6 +532,13 @@ async def get_user_logs(self, user_id: Union[str, int]) -> list:

return await self.logs.find(query, projection).to_list(None)

async def find_log_entry(self, key: str) -> list:
query = {"key": key}
projection = {"messages": {"$slice": 5}}
logger.debug(f"Retrieving log ID {key}.")

return await self.logs.find(query, projection).to_list(None)

async def get_latest_user_logs(self, user_id: Union[str, int]):
query = {"recipient.id": str(user_id), "guild_id": str(self.bot.guild_id), "open": False}
projection = {"messages": {"$slice": 5}}
Expand Down