Skip to content

Commit b1f3645

Browse files
CordilaTaaku18
Cordila
andauthored
logs id command (#3196)
* Update modmail.py * Update clients.py * Formatting * Change log id to log key, added id as an alias * Print the log even if it is closed and fix bug * Update modmail.py * Added a missing period * Updated changelog --------- Co-authored-by: Taku <45324516+Taaku18@users.noreply.github.com>
1 parent 5ddb4e0 commit b1f3645

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s
1515

1616
### Added
1717
- New .env config option: `REGISTRY_PLUGINS_ONLY`, restricts to only allow adding registry plugins. ([PR #3247](https://github.com/modmail-dev/modmail/pull/3247))
18+
- `?log key <key>` to retrieve the log link and view a preview using a log key. ([PR #3196](https://github.com/modmail-dev/Modmail/pull/3196))
1819

1920
### Changed
2021
- Guild icons in embed footers and author urls now have a fixed size of 128. ([PR #3261](https://github.com/modmail-dev/modmail/pull/3261))

cogs/modmail.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,28 @@ async def logs_closed_by(self, ctx, *, user: User = None):
12121212
session = EmbedPaginatorSession(ctx, *embeds)
12131213
await session.run()
12141214

1215+
@logs.command(name="key", aliases=["id"])
1216+
@checks.has_permissions(PermissionLevel.SUPPORTER)
1217+
async def logs_key(self, ctx, key: str):
1218+
"""
1219+
Get the log link for the specified log key.
1220+
"""
1221+
icon_url = ctx.author.avatar.url
1222+
1223+
logs = await self.bot.api.find_log_entry(key)
1224+
1225+
if not logs:
1226+
embed = discord.Embed(
1227+
color=self.bot.error_color,
1228+
description=f"Log entry `{key}` not found.",
1229+
)
1230+
return await ctx.send(embed=embed)
1231+
1232+
embeds = self.format_log_embeds(logs, avatar_url=icon_url)
1233+
1234+
session = EmbedPaginatorSession(ctx, *embeds)
1235+
await session.run()
1236+
12151237
@logs.command(name="delete", aliases=["wipe"])
12161238
@checks.has_permissions(PermissionLevel.OWNER)
12171239
async def logs_delete(self, ctx, key_or_link: str):

core/clients.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ async def validate_database_connection(self):
356356
async def get_user_logs(self, user_id: Union[str, int]) -> list:
357357
return NotImplemented
358358

359+
async def find_log_entry(self, key: str) -> list:
360+
return NotImplemented
361+
359362
async def get_latest_user_logs(self, user_id: Union[str, int]):
360363
return NotImplemented
361364

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

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

535+
async def find_log_entry(self, key: str) -> list:
536+
query = {"key": key}
537+
projection = {"messages": {"$slice": 5}}
538+
logger.debug(f"Retrieving log ID {key}.")
539+
540+
return await self.logs.find(query, projection).to_list(None)
541+
532542
async def get_latest_user_logs(self, user_id: Union[str, int]):
533543
query = {"recipient.id": str(user_id), "guild_id": str(self.bot.guild_id), "open": False}
534544
projection = {"messages": {"$slice": 5}}

0 commit comments

Comments
 (0)