Fix embed requested in DMs (#5635)

* Fix embed requested in DM's

* Add documentation

* black

* Address comments

* Unnecessary added line

* Use correct channel on context

* use correct var name

* More review stuff
This commit is contained in:
TrustyJAID 2022-03-22 14:04:45 -06:00 committed by GitHub
parent c69e8d31fd
commit 5a5b22003f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -1205,7 +1205,7 @@ class Red(
async def embed_requested( async def embed_requested(
self, self,
channel: discord.abc.Messageable, channel: Union[discord.TextChannel, commands.Context, discord.User, discord.Member],
*, *,
command: Optional[commands.Command] = None, command: Optional[commands.Command] = None,
check_permissions: bool = True, check_permissions: bool = True,
@ -1232,6 +1232,13 @@ class Red(
------- -------
bool bool
:code:`True` if an embed is requested :code:`True` if an embed is requested
Raises
------
TypeError
When the passed channel is of type `discord.GroupChannel`
or `discord.DMChannel`
""" """
async def get_command_setting(guild_id: int) -> Optional[bool]: async def get_command_setting(guild_id: int) -> Optional[bool]:
@ -1240,10 +1247,17 @@ class Red(
scope = self._config.custom(COMMAND_SCOPE, command.qualified_name, guild_id) scope = self._config.custom(COMMAND_SCOPE, command.qualified_name, guild_id)
return await scope.embeds() return await scope.embeds()
if isinstance(channel, (discord.GroupChannel, discord.DMChannel)):
raise TypeError("You cannot pass a GroupChannel or DMChannel to this method")
# using dpy_commands.Context to keep the Messageable contract in full # using dpy_commands.Context to keep the Messageable contract in full
if isinstance(channel, dpy_commands.Context): if isinstance(channel, dpy_commands.Context):
command = command or channel.command command = command or channel.command
channel = channel.channel channel = (
channel.author
if isinstance(channel.channel, discord.DMChannel)
else channel.channel
)
if isinstance(channel, discord.TextChannel): if isinstance(channel, discord.TextChannel):
if check_permissions and not channel.permissions_for(channel.guild.me).embed_links: if check_permissions and not channel.permissions_for(channel.guild.me).embed_links:
@ -1257,15 +1271,11 @@ class Red(
if (guild_setting := await self._config.guild(channel.guild).embeds()) is not None: if (guild_setting := await self._config.guild(channel.guild).embeds()) is not None:
return guild_setting return guild_setting
elif isinstance(channel, discord.GroupChannel):
# this only uses global settings
pass
else: else:
user = channel.recipient if isinstance(discord.DMChannel) else channel user = channel
if (user_setting := await self._config.user(user).embeds()) is not None: if (user_setting := await self._config.user(user).embeds()) is not None:
return user_setting return user_setting
# XXX: maybe this should be checked before guild setting?
if (global_command_setting := await get_command_setting(0)) is not None: if (global_command_setting := await get_command_setting(0)) is not None:
return global_command_setting return global_command_setting

View File

@ -713,7 +713,7 @@ class RedHelpFormatter(HelpFormatterABC):
yield obj yield obj
async def embed_requested(self, ctx: Context) -> bool: async def embed_requested(self, ctx: Context) -> bool:
return await ctx.bot.embed_requested(channel=ctx.channel, command=red_help) return await ctx.bot.embed_requested(channel=ctx, command=red_help)
async def command_not_found(self, ctx, help_for, help_settings: HelpSettings): async def command_not_found(self, ctx, help_for, help_settings: HelpSettings):
""" """