From c2fcb1fe0255c532e07b777df0ca1ce70e8a1040 Mon Sep 17 00:00:00 2001 From: Anand Krishna Date: Wed, 20 Jan 2021 23:17:09 +0400 Subject: Duck Pond: Add `is_helper_viewable` check --- bot/exts/fun/duck_pond.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bot/exts/fun/duck_pond.py b/bot/exts/fun/duck_pond.py index 48aa2749c..43be0dd83 100644 --- a/bot/exts/fun/duck_pond.py +++ b/bot/exts/fun/duck_pond.py @@ -3,7 +3,7 @@ import logging from typing import Union import discord -from discord import Color, Embed, Member, Message, RawReactionActionEvent, User, errors +from discord import Color, Embed, Member, Message, RawReactionActionEvent, TextChannel, User, errors from discord.ext.commands import Cog, Context, command from bot import constants @@ -44,6 +44,17 @@ class DuckPond(Cog): return True return False + @staticmethod + def is_helper_viewable(channel: TextChannel) -> 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 explicit permissions to view. + helper_overwrites = channel.overwrites_for(helper_role) + default_overwrites = channel.overwrites_for(guild.default_role) + return default_overwrites.view_channel or helper_overwrites.view_channel + async def has_green_checkmark(self, message: Message) -> bool: """Check if the message has a green checkmark reaction.""" for reaction in message.reactions: @@ -165,6 +176,10 @@ class DuckPond(Cog): message = await channel.fetch_message(payload.message_id) member = discord.utils.get(message.guild.members, id=payload.user_id) + # Was the message sent in a channel Helpers can see? + if not self.is_helper_viewable(channel): + return + # Was the message sent by a human staff member? if not self.is_staff(message.author) or message.author.bot: return -- cgit v1.2.3 From 73e89b8a7c8f12ae781aa0228e9b67c13232a34c Mon Sep 17 00:00:00 2001 From: Anand Krishna Date: Wed, 20 Jan 2021 23:18:24 +0400 Subject: Make type hints uniform across file --- bot/exts/fun/duck_pond.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/fun/duck_pond.py b/bot/exts/fun/duck_pond.py index 43be0dd83..c97f4b0cc 100644 --- a/bot/exts/fun/duck_pond.py +++ b/bot/exts/fun/duck_pond.py @@ -118,7 +118,7 @@ class DuckPond(Cog): except discord.HTTPException: log.exception("Failed to send an attachment to the webhook") - async def locked_relay(self, message: discord.Message) -> bool: + async def locked_relay(self, message: Message) -> bool: """Relay a message after obtaining the relay lock.""" if self.relay_lock is None: # Lazily load the lock to ensure it's created within the @@ -216,7 +216,7 @@ class DuckPond(Cog): @command(name="duckify", aliases=("duckpond", "pondify")) @has_any_role(constants.Roles.admins) - async def duckify(self, ctx: Context, message: discord.Message) -> None: + async def duckify(self, ctx: Context, message: Message) -> None: """Relay a message to the duckpond, no ducks required!""" if await self.locked_relay(message): await ctx.message.add_reaction("🦆") -- cgit v1.2.3 From c4399916db810a82adce1111fb6367e2228f8ef1 Mon Sep 17 00:00:00 2001 From: Anand Krishna Date: Fri, 22 Jan 2021 19:23:38 +0400 Subject: Do `is_helper_viewable` check before fetching message --- bot/exts/fun/duck_pond.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/exts/fun/duck_pond.py b/bot/exts/fun/duck_pond.py index c97f4b0cc..3eed25781 100644 --- a/bot/exts/fun/duck_pond.py +++ b/bot/exts/fun/duck_pond.py @@ -173,13 +173,13 @@ class DuckPond(Cog): if channel is None: return - message = await channel.fetch_message(payload.message_id) - member = discord.utils.get(message.guild.members, id=payload.user_id) - # Was the message sent in a channel Helpers can see? if not self.is_helper_viewable(channel): return + message = await channel.fetch_message(payload.message_id) + member = discord.utils.get(message.guild.members, id=payload.user_id) + # Was the message sent by a human staff member? if not self.is_staff(message.author) or message.author.bot: return -- cgit v1.2.3 From 3e338ca62e20f73f4563e194d5aab031b0df96fe Mon Sep 17 00:00:00 2001 From: Anand Krishna Date: Mon, 25 Jan 2021 19:32:25 +0400 Subject: Update `is_helper_viewable` check --- bot/exts/fun/duck_pond.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/fun/duck_pond.py b/bot/exts/fun/duck_pond.py index 3eed25781..ee440dec2 100644 --- a/bot/exts/fun/duck_pond.py +++ b/bot/exts/fun/duck_pond.py @@ -50,10 +50,10 @@ class DuckPond(Cog): 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 explicit permissions to view. + # 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) - return default_overwrites.view_channel or helper_overwrites.view_channel + 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.""" -- cgit v1.2.3