Skip to content

Commit f1d2f8a

Browse files
authored
Merge branch 'development' into discord-logger
2 parents 3b5b779 + b1f3645 commit f1d2f8a

File tree

6 files changed

+58
-15
lines changed

6 files changed

+58
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ 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
21+
- 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))
2022
- Repo moved to https://github.com/modmail-dev/modmail.
2123
- Discord.py internal logging is now enabled by default. ([PR #3216](https://github.com/modmail-dev/Modmail/pull/3216))
2224

bot.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,16 @@ def __init__(self):
9292
self.plugin_db = PluginDatabaseClient(self) # Deprecated
9393
self.startup()
9494

95-
def get_guild_icon(self, guild: typing.Optional[discord.Guild]) -> str:
95+
def get_guild_icon(
96+
self, guild: typing.Optional[discord.Guild], *, size: typing.Optional[int] = None
97+
) -> str:
9698
if guild is None:
9799
guild = self.guild
98100
if guild.icon is None:
99101
return "https://cdn.discordapp.com/embed/avatars/0.png"
100-
return guild.icon.url
102+
if size is None:
103+
return guild.icon.url
104+
return guild.icon.with_size(size).url
101105

102106
def _resolve_snippet(self, name: str) -> typing.Optional[str]:
103107
"""
@@ -891,7 +895,7 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
891895
)
892896
embed.set_footer(
893897
text=self.config["disabled_new_thread_footer"],
894-
icon_url=self.get_guild_icon(guild=message.guild),
898+
icon_url=self.get_guild_icon(guild=message.guild, size=128),
895899
)
896900
logger.info("A new thread was blocked from %s due to disabled Modmail.", message.author)
897901
await self.add_reaction(message, blocked_emoji)
@@ -907,7 +911,7 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
907911
)
908912
embed.set_footer(
909913
text=self.config["disabled_current_thread_footer"],
910-
icon_url=self.get_guild_icon(guild=message.guild),
914+
icon_url=self.get_guild_icon(guild=message.guild, size=128),
911915
)
912916
logger.info("A message was blocked from %s due to disabled Modmail.", message.author)
913917
await self.add_reaction(message, blocked_emoji)
@@ -1314,7 +1318,7 @@ async def handle_react_to_contact(self, payload):
13141318
)
13151319
embed.set_footer(
13161320
text=self.config["disabled_new_thread_footer"],
1317-
icon_url=self.get_guild_icon(guild=channel.guild),
1321+
icon_url=self.get_guild_icon(guild=channel.guild, size=128),
13181322
)
13191323
logger.info(
13201324
"A new thread using react to contact was blocked from %s due to disabled Modmail.",

cogs/modmail.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ async def snippet(self, ctx, *, name: str.lower = None):
160160
color=self.bot.error_color, description="You dont have any snippets at the moment."
161161
)
162162
embed.set_footer(text=f'Check "{self.bot.prefix}help snippet add" to add a snippet.')
163-
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
163+
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild, size=128))
164164
return await ctx.send(embed=embed)
165165

166166
embeds = []
167167

168168
for i, names in enumerate(zip_longest(*(iter(sorted(self.bot.snippets)),) * 15)):
169169
description = format_description(i, names)
170170
embed = discord.Embed(color=self.bot.main_color, description=description)
171-
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
171+
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild, size=128))
172172
embeds.append(embed)
173173

174174
session = EmbedPaginatorSession(ctx, *embeds)
@@ -1031,7 +1031,7 @@ async def anonadduser(self, ctx, *users_arg: Union[discord.Member, discord.Role,
10311031
name = tag
10321032
avatar_url = self.bot.config["anon_avatar_url"]
10331033
if avatar_url is None:
1034-
avatar_url = self.bot.get_guild_icon(guild=ctx.guild)
1034+
avatar_url = self.bot.get_guild_icon(guild=ctx.guild, size=128)
10351035
em.set_footer(text=name, icon_url=avatar_url)
10361036

10371037
for u in users:
@@ -1120,7 +1120,7 @@ async def anonremoveuser(self, ctx, *users_arg: Union[discord.Member, discord.Ro
11201120
name = tag
11211121
avatar_url = self.bot.config["anon_avatar_url"]
11221122
if avatar_url is None:
1123-
avatar_url = self.bot.get_guild_icon(guild=ctx.guild)
1123+
avatar_url = self.bot.get_guild_icon(guild=ctx.guild, size=128)
11241124
em.set_footer(text=name, icon_url=avatar_url)
11251125

11261126
for u in users:
@@ -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):

cogs/utility.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,15 +1005,17 @@ async def alias(self, ctx, *, name: str.lower = None):
10051005
color=self.bot.error_color, description="You dont have any aliases at the moment."
10061006
)
10071007
embed.set_footer(text=f'Do "{self.bot.prefix}help alias" for more commands.')
1008-
embed.set_author(name="Aliases", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
1008+
embed.set_author(name="Aliases", icon_url=self.bot.get_guild_icon(guild=ctx.guild, size=128))
10091009
return await ctx.send(embed=embed)
10101010

10111011
embeds = []
10121012

10131013
for i, names in enumerate(zip_longest(*(iter(sorted(self.bot.aliases)),) * 15)):
10141014
description = utils.format_description(i, names)
10151015
embed = discord.Embed(color=self.bot.main_color, description=description)
1016-
embed.set_author(name="Command Aliases", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
1016+
embed.set_author(
1017+
name="Command Aliases", icon_url=self.bot.get_guild_icon(guild=ctx.guild, size=128)
1018+
)
10171019
embeds.append(embed)
10181020

10191021
session = EmbedPaginatorSession(ctx, *embeds)
@@ -1597,7 +1599,8 @@ async def permissions_get(
15971599
)
15981600
embed = discord.Embed(color=self.bot.main_color, description=description)
15991601
embed.set_author(
1600-
name="Permission Overrides", icon_url=self.bot.get_guild_icon(guild=ctx.guild)
1602+
name="Permission Overrides",
1603+
icon_url=self.bot.get_guild_icon(guild=ctx.guild, size=128),
16011604
)
16021605
embeds.append(embed)
16031606

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}}

core/thread.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ async def send_recipient_genesis_message():
228228
else:
229229
footer = self.bot.config["thread_creation_footer"]
230230

231-
embed.set_footer(text=footer, icon_url=self.bot.get_guild_icon(guild=self.bot.modmail_guild))
231+
embed.set_footer(
232+
text=footer, icon_url=self.bot.get_guild_icon(guild=self.bot.modmail_guild, size=128)
233+
)
232234
embed.title = self.bot.config["thread_creation_title"]
233235

234236
if creator is None or creator == recipient:
@@ -521,7 +523,7 @@ async def _close(self, closer, silent=False, delete_channel=True, message=None,
521523

522524
embed.description = message
523525
footer = self.bot.config["thread_close_footer"]
524-
embed.set_footer(text=footer, icon_url=self.bot.get_guild_icon(guild=self.bot.guild))
526+
embed.set_footer(text=footer, icon_url=self.bot.get_guild_icon(guild=self.bot.guild, size=128))
525527

526528
if not silent:
527529
for user in self.recipients:
@@ -957,7 +959,7 @@ async def send(
957959
name = tag
958960
avatar_url = self.bot.config["anon_avatar_url"]
959961
if avatar_url is None:
960-
avatar_url = self.bot.get_guild_icon(guild=self.bot.guild)
962+
avatar_url = self.bot.get_guild_icon(guild=self.bot.guild, size=128)
961963
embed.set_author(
962964
name=name,
963965
icon_url=avatar_url,

0 commit comments

Comments
 (0)