Skip to content

logs id command #3196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,28 @@ 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)

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