Skip to content

Commit d777ab2

Browse files
Cordilakhakers
authored andcommitted
logs id command (modmail-dev#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> (cherry picked from commit b1f3645) Signed-off-by: Khakers <22665282+khakers@users.noreply.github.com>
1 parent 3b97d12 commit d777ab2

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ however, insignificant breaking changes do not guarantee a major version bump, s
1717

1818
### Added
1919
- Added `content_type` to attachments stored in the database.
20+
- `?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))
21+
2022

2123
### Changed
2224
- Changing a threads title or NSFW status immediately updates the status in the database.

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

@@ -538,6 +541,13 @@ async def get_user_logs(self, user_id: Union[str, int]) -> list:
538541

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

544+
async def find_log_entry(self, key: str) -> list:
545+
query = {"key": key}
546+
projection = {"messages": {"$slice": 5}}
547+
logger.debug(f"Retrieving log ID {key}.")
548+
549+
return await self.logs.find(query, projection).to_list(None)
550+
541551
async def get_latest_user_logs(self, user_id: Union[str, int]):
542552
query = {"recipient.id": str(user_id), "guild_id": str(self.bot.guild_id), "open": False}
543553
projection = {"messages": {"$slice": 5}}

0 commit comments

Comments
 (0)