Skip to content

Commit

Permalink
logs id command (#3196)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Cordila and Taaku18 authored Jul 15, 2023
1 parent 5ddb4e0 commit b1f3645
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s

### Added
- New .env config option: `REGISTRY_PLUGINS_ONLY`, restricts to only allow adding registry plugins. ([PR #3247](https://github.com/modmail-dev/modmail/pull/3247))
- `?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))

### Changed
- 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))
Expand Down
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

0 comments on commit b1f3645

Please sign in to comment.