Skip to content

Commit

Permalink
Merge pull request #3235 from Cordila/patch-6
Browse files Browse the repository at this point in the history
Fix #3227 and #3205 (Fix guild icon not set issue)
  • Loading branch information
Taaku18 authored Dec 8, 2022
2 parents c63ed9d + ccc53ea commit b3ce7d0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
16 changes: 13 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def __init__(self):
self.plugin_db = PluginDatabaseClient(self) # Deprecated
self.startup()

def get_guild_icon(self, guild: typing.Optional[discord.Guild]) -> str:
if guild is None:
guild = self.guild
if guild.icon is None:
return self.user.display_avatar.url
return guild.icon.url

def _resolve_snippet(self, name: str) -> typing.Optional[str]:
"""
Get actual snippet names from direct aliases to snippets.
Expand Down Expand Up @@ -903,7 +910,10 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
color=self.error_color,
description=self.config["disabled_new_thread_response"],
)
embed.set_footer(text=self.config["disabled_new_thread_footer"], icon_url=self.guild.icon.url)
embed.set_footer(
text=self.config["disabled_new_thread_footer"],
icon_url=self.get_guild_icon(guild=message.guild),
)
logger.info("A new thread was blocked from %s due to disabled Modmail.", message.author)
await self.add_reaction(message, blocked_emoji)
return await message.channel.send(embed=embed)
Expand All @@ -918,7 +928,7 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
)
embed.set_footer(
text=self.config["disabled_current_thread_footer"],
icon_url=self.guild.icon.url,
icon_url=self.get_guild_icon(guild=message.guild),
)
logger.info("A message was blocked from %s due to disabled Modmail.", message.author)
await self.add_reaction(message, blocked_emoji)
Expand Down Expand Up @@ -1325,7 +1335,7 @@ async def handle_react_to_contact(self, payload):
)
embed.set_footer(
text=self.config["disabled_new_thread_footer"],
icon_url=self.guild.icon.url,
icon_url=self.get_guild_icon(guild=channel.guild),
)
logger.info(
"A new thread using react to contact was blocked from %s due to disabled Modmail.",
Expand Down
14 changes: 7 additions & 7 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ async def snippet(self, ctx, *, name: str.lower = None):
color=self.bot.error_color, description="You dont have any snippets at the moment."
)
embed.set_footer(text=f'Check "{self.bot.prefix}help snippet add" to add a snippet.')
embed.set_author(name="Snippets", icon_url=ctx.guild.icon.url)
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
return await ctx.send(embed=embed)

embeds = []

for i, names in enumerate(zip_longest(*(iter(sorted(self.bot.snippets)),) * 15)):
description = format_description(i, names)
embed = discord.Embed(color=self.bot.main_color, description=description)
embed.set_author(name="Snippets", icon_url=ctx.guild.icon.url)
embed.set_author(name="Snippets", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
embeds.append(embed)

session = EmbedPaginatorSession(ctx, *embeds)
Expand Down Expand Up @@ -1031,7 +1031,7 @@ async def anonadduser(self, ctx, *users_arg: Union[discord.Member, discord.Role,
name = tag
avatar_url = self.bot.config["anon_avatar_url"]
if avatar_url is None:
avatar_url = self.bot.guild.icon.url
avatar_url = self.bot.get_guild_icon(guild=ctx.guild)
em.set_footer(text=name, icon_url=avatar_url)

for u in users:
Expand Down Expand Up @@ -1120,7 +1120,7 @@ async def anonremoveuser(self, ctx, *users_arg: Union[discord.Member, discord.Ro
name = tag
avatar_url = self.bot.config["anon_avatar_url"]
if avatar_url is None:
avatar_url = self.bot.guild.icon.url
avatar_url = self.bot.get_guild_icon(guild=ctx.guild)
em.set_footer(text=name, icon_url=avatar_url)

for u in users:
Expand Down Expand Up @@ -1200,7 +1200,7 @@ async def logs_closed_by(self, ctx, *, user: User = None):
user = user if user is not None else ctx.author

entries = await self.bot.api.search_closed_by(user.id)
embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon.url)
embeds = self.format_log_embeds(entries, avatar_url=self.bot.get_guild_icon(guild=ctx.guild))

if not embeds:
embed = discord.Embed(
Expand Down Expand Up @@ -1250,7 +1250,7 @@ async def logs_responded(self, ctx, *, user: User = None):

entries = await self.bot.api.get_responded_logs(user.id)

embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon.url)
embeds = self.format_log_embeds(entries, avatar_url=self.bot.get_guild_icon(guild=ctx.guild))

if not embeds:
embed = discord.Embed(
Expand All @@ -1275,7 +1275,7 @@ async def logs_search(self, ctx, limit: Optional[int] = None, *, query):

entries = await self.bot.api.search_by_text(query, limit)

embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon.url)
embeds = self.format_log_embeds(entries, avatar_url=self.bot.get_guild_icon(guild=ctx.guild))

if not embeds:
embed = discord.Embed(
Expand Down
8 changes: 5 additions & 3 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,15 +1020,15 @@ async def alias(self, ctx, *, name: str.lower = None):
color=self.bot.error_color, description="You dont have any aliases at the moment."
)
embed.set_footer(text=f'Do "{self.bot.prefix}help alias" for more commands.')
embed.set_author(name="Aliases", icon_url=ctx.guild.icon.url)
embed.set_author(name="Aliases", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
return await ctx.send(embed=embed)

embeds = []

for i, names in enumerate(zip_longest(*(iter(sorted(self.bot.aliases)),) * 15)):
description = utils.format_description(i, names)
embed = discord.Embed(color=self.bot.main_color, description=description)
embed.set_author(name="Command Aliases", icon_url=ctx.guild.icon.url)
embed.set_author(name="Command Aliases", icon_url=self.bot.get_guild_icon(guild=ctx.guild))
embeds.append(embed)

session = EmbedPaginatorSession(ctx, *embeds)
Expand Down Expand Up @@ -1611,7 +1611,9 @@ async def permissions_get(
for name, level in takewhile(lambda x: x is not None, items)
)
embed = discord.Embed(color=self.bot.main_color, description=description)
embed.set_author(name="Permission Overrides", icon_url=ctx.guild.icon.url)
embed.set_author(
name="Permission Overrides", icon_url=self.bot.get_guild_icon(guild=ctx.guild)
)
embeds.append(embed)

session = EmbedPaginatorSession(ctx, *embeds)
Expand Down
6 changes: 3 additions & 3 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ async def send_recipient_genesis_message():
else:
footer = self.bot.config["thread_creation_footer"]

embed.set_footer(text=footer, icon_url=self.bot.guild.icon.url)
embed.set_footer(text=footer, icon_url=self.bot.get_guild_icon(guild=self.bot.modmail_guild))
embed.title = self.bot.config["thread_creation_title"]

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

embed.description = message
footer = self.bot.config["thread_close_footer"]
embed.set_footer(text=footer, icon_url=self.bot.guild.icon.url)
embed.set_footer(text=footer, icon_url=self.bot.get_guild_icon(guild=self.bot.guild))

if not silent:
for user in self.recipients:
Expand Down Expand Up @@ -957,7 +957,7 @@ async def send(
name = tag
avatar_url = self.bot.config["anon_avatar_url"]
if avatar_url is None:
avatar_url = self.bot.guild.icon.url
avatar_url = self.bot.get_guild_icon(guild=self.bot.guild)
embed.set_author(
name=name,
icon_url=avatar_url,
Expand Down

0 comments on commit b3ce7d0

Please sign in to comment.