From c62a52e8e45e527bd3ec6404525964d6ccd79ddd Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 14 Feb 2022 10:45:57 +0000 Subject: Allow duckifying of messages in threads --- bot/exts/fun/duck_pond.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bot/exts/fun/duck_pond.py b/bot/exts/fun/duck_pond.py index c51656343..8968c766d 100644 --- a/bot/exts/fun/duck_pond.py +++ b/bot/exts/fun/duck_pond.py @@ -2,7 +2,7 @@ import asyncio from typing import Union import discord -from discord import Color, Embed, Message, RawReactionActionEvent, TextChannel, errors +from discord import Color, Embed, Message, RawReactionActionEvent, TextChannel, Thread, errors from discord.ext.commands import Cog, Context, command from bot import constants @@ -47,14 +47,18 @@ class DuckPond(Cog): return False @staticmethod - def is_helper_viewable(channel: TextChannel) -> bool: + def is_helper_viewable(channel: Union[TextChannel, Thread]) -> bool: """Check if helpers can view a specific channel.""" guild = channel.guild helper_role = guild.get_role(constants.Roles.helpers) # check channel overwrites for both the Helper role and @everyone and # return True for channels that they have permissions to view. - helper_overwrites = channel.overwrites_for(helper_role) - default_overwrites = channel.overwrites_for(guild.default_role) + if isinstance(channel, Thread): + helper_overwrites = channel.permissions_for(helper_role) + default_overwrites = channel.permissions_for(guild.default_role) + else: + helper_overwrites = channel.overwrites_for(helper_role) + default_overwrites = channel.overwrites_for(guild.default_role) return default_overwrites.view_channel is None or helper_overwrites.view_channel is True async def has_green_checkmark(self, message: Message) -> bool: @@ -165,7 +169,9 @@ class DuckPond(Cog): if not self._payload_has_duckpond_emoji(payload.emoji): return - channel = discord.utils.get(self.bot.get_all_channels(), id=payload.channel_id) + await self.bot.wait_until_guild_available() + guild = self.bot.get_guild(payload.guild_id) + channel = discord.utils.get(guild.text_channels + guild.threads, id=payload.channel_id) if channel is None: return -- cgit v1.2.3 From 71100240a6023cad4f35c36751c4c44e18f7f2d7 Mon Sep 17 00:00:00 2001 From: Izan Date: Thu, 17 Feb 2022 11:29:24 +0000 Subject: Use `discord.Guild.get_channel_or_thread()` instead of `discord.utils.get()` --- bot/exts/fun/duck_pond.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/fun/duck_pond.py b/bot/exts/fun/duck_pond.py index 8968c766d..8baa53026 100644 --- a/bot/exts/fun/duck_pond.py +++ b/bot/exts/fun/duck_pond.py @@ -171,7 +171,7 @@ class DuckPond(Cog): await self.bot.wait_until_guild_available() guild = self.bot.get_guild(payload.guild_id) - channel = discord.utils.get(guild.text_channels + guild.threads, id=payload.channel_id) + channel = guild.get_channel_or_thread(payload.channel_id) if channel is None: return -- cgit v1.2.3 From 532ce7d7785103c8c67341d8d24d5301f76a8257 Mon Sep 17 00:00:00 2001 From: ToxicKidz Date: Mon, 28 Feb 2022 16:21:05 -0500 Subject: chore: Simplify the permissions checking in duck ponds --- bot/exts/fun/duck_pond.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/bot/exts/fun/duck_pond.py b/bot/exts/fun/duck_pond.py index 8baa53026..8a41a3116 100644 --- a/bot/exts/fun/duck_pond.py +++ b/bot/exts/fun/duck_pond.py @@ -2,7 +2,7 @@ import asyncio from typing import Union import discord -from discord import Color, Embed, Message, RawReactionActionEvent, TextChannel, Thread, errors +from discord import Color, Embed, Message, RawReactionActionEvent, errors from discord.ext.commands import Cog, Context, command from bot import constants @@ -46,21 +46,6 @@ class DuckPond(Cog): return True return False - @staticmethod - def is_helper_viewable(channel: Union[TextChannel, Thread]) -> bool: - """Check if helpers can view a specific channel.""" - guild = channel.guild - helper_role = guild.get_role(constants.Roles.helpers) - # check channel overwrites for both the Helper role and @everyone and - # return True for channels that they have permissions to view. - if isinstance(channel, Thread): - helper_overwrites = channel.permissions_for(helper_role) - default_overwrites = channel.permissions_for(guild.default_role) - else: - helper_overwrites = channel.overwrites_for(helper_role) - default_overwrites = channel.overwrites_for(guild.default_role) - return default_overwrites.view_channel is None or helper_overwrites.view_channel is True - async def has_green_checkmark(self, message: Message) -> bool: """Check if the message has a green checkmark reaction.""" for reaction in message.reactions: @@ -176,7 +161,8 @@ class DuckPond(Cog): return # Was the message sent in a channel Helpers can see? - if not self.is_helper_viewable(channel): + helper_role = guild.get_role(constants.Roles.helpers) + if not channel.permissions_for(helper_role).view_channel: return try: -- cgit v1.2.3