From 210c0a09b1bced80d03ed9ac81845f5f94c8b687 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sun, 12 Jul 2020 13:23:22 +0200 Subject: Ping @Moderators in ModLog Instead of pinging @everyone, let's just ping the people who actually need to see the mod alerts or the modlogs, which would be the mods. `@everyone` is currently not permitted by our allowed_mentions setting, so this also restores pings to those channels. GitHub #1038 https://github.com/python-discord/bot/issues/1038 --- bot/cogs/antispam.py | 4 ++-- bot/cogs/filtering.py | 2 +- bot/cogs/moderation/modlog.py | 10 +++++----- bot/cogs/watchchannels/watchchannel.py | 4 ++-- bot/constants.py | 4 ++-- config-default.yml | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bot/cogs/antispam.py b/bot/cogs/antispam.py index 0bcca578d..71382bba9 100644 --- a/bot/cogs/antispam.py +++ b/bot/cogs/antispam.py @@ -98,7 +98,7 @@ class DeletionContext: text=mod_alert_message, thumbnail=last_message.author.avatar_url_as(static_format="png"), channel_id=Channels.mod_alerts, - ping_everyone=AntiSpamConfig.ping_everyone + ping_moderators=AntiSpamConfig.ping_moderators ) @@ -132,7 +132,7 @@ class AntiSpam(Cog): await self.mod_log.send_log_message( title="Error: AntiSpam configuration validation failed!", text=body, - ping_everyone=True, + ping_moderators=True, icon_url=Icons.token_removed, colour=Colour.red() ) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 76ea68660..a5d59085f 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -329,7 +329,7 @@ class Filtering(Cog, Scheduler): text=message, thumbnail=msg.author.avatar_url_as(static_format="png"), channel_id=Channels.mod_alerts, - ping_everyone=Filter.ping_everyone, + ping_moderators=Filter.ping_moderators, additional_embeds=additional_embeds, additional_embeds_msg=additional_embeds_msg ) diff --git a/bot/cogs/moderation/modlog.py b/bot/cogs/moderation/modlog.py index ffbb87bbe..a37a9faf5 100644 --- a/bot/cogs/moderation/modlog.py +++ b/bot/cogs/moderation/modlog.py @@ -15,7 +15,7 @@ from discord.ext.commands import Cog, Context from discord.utils import escape_markdown from bot.bot import Bot -from bot.constants import Categories, Channels, Colours, Emojis, Event, Guild as GuildConstant, Icons, URLs +from bot.constants import Categories, Channels, Colours, Emojis, Event, Guild as GuildConstant, Icons, Roles, URLs from bot.utils.time import humanize_delta log = logging.getLogger(__name__) @@ -88,7 +88,7 @@ class ModLog(Cog, name="ModLog"): text: str, thumbnail: t.Optional[t.Union[str, discord.Asset]] = None, channel_id: int = Channels.mod_log, - ping_everyone: bool = False, + ping_moderators: bool = False, files: t.Optional[t.List[discord.File]] = None, content: t.Optional[str] = None, additional_embeds: t.Optional[t.List[discord.Embed]] = None, @@ -114,11 +114,11 @@ class ModLog(Cog, name="ModLog"): if thumbnail: embed.set_thumbnail(url=thumbnail) - if ping_everyone: + if ping_moderators: if content: - content = f"@everyone\n{content}" + content = f"<@&{Roles.moderators}>\n{content}" else: - content = "@everyone" + content = f"<@&{Roles.moderators}>" channel = self.bot.get_channel(channel_id) log_message = await channel.send(content=content, embed=embed, files=files) diff --git a/bot/cogs/watchchannels/watchchannel.py b/bot/cogs/watchchannels/watchchannel.py index 7c58a0fb5..8c4af4581 100644 --- a/bot/cogs/watchchannels/watchchannel.py +++ b/bot/cogs/watchchannels/watchchannel.py @@ -120,7 +120,7 @@ class WatchChannel(metaclass=CogABCMeta): await self.modlog.send_log_message( title=f"Error: Failed to initialize the {self.__class__.__name__} watch channel", text=message, - ping_everyone=True, + ping_moderators=True, icon_url=Icons.token_removed, colour=Color.red() ) @@ -132,7 +132,7 @@ class WatchChannel(metaclass=CogABCMeta): await self.modlog.send_log_message( title=f"Warning: Failed to retrieve user cache for the {self.__class__.__name__} watch channel", text="Could not retrieve the list of watched users from the API and messages will not be relayed.", - ping_everyone=True, + ping_moderators=True, icon_url=Icons.token_removed, colour=Color.red() ) diff --git a/bot/constants.py b/bot/constants.py index a1b392c82..34b312d2d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -225,7 +225,7 @@ class Filter(metaclass=YAMLGetter): notify_user_invites: bool notify_user_domains: bool - ping_everyone: bool + ping_moderators: bool offensive_msg_delete_days: int guild_invite_whitelist: List[int] domain_blacklist: List[str] @@ -522,7 +522,7 @@ class AntiSpam(metaclass=YAMLGetter): section = 'anti_spam' clean_offending: bool - ping_everyone: bool + ping_moderators: bool punishment: Dict[str, Dict[str, int]] rules: Dict[str, Dict[str, int]] diff --git a/config-default.yml b/config-default.yml index 64c4e715b..5dd96d67a 100644 --- a/config-default.yml +++ b/config-default.yml @@ -269,7 +269,7 @@ filter: notify_user_domains: false # Filter configuration - ping_everyone: true # Ping @everyone when we send a mod-alert? + ping_moderators: true # Ping @everyone when we send a mod-alert? offensive_msg_delete_days: 7 # How many days before deleting an offensive message? guild_invite_whitelist: @@ -428,7 +428,7 @@ urls: anti_spam: # Clean messages that violate a rule. clean_offending: true - ping_everyone: true + ping_moderators: true punishment: role_id: *MUTED_ROLE -- cgit v1.2.3 From 57e210ccfcc91132182029f1d931118e715439b2 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sun, 12 Jul 2020 13:38:02 +0200 Subject: Allow role pings in Syncers and help_channels.py Now that we're running Discord 1.4.0a, we need to explicitely allow all the role mentions for sends that don't use ping one of the globally whitelisted role pings, which are Moderators, Admins and Owners. We were pinging roles other than Mods+ in exactly two cases: - Inside the Syncers, whenever we ask for sync confirmation (if the number of roles or users to sync is unusually high) - In the help_channels.py system, whenever we max out help channels and are unable to create more. This commit addresses both of these. GitHub #1038 https://github.com/python-discord/bot/issues/1038 --- bot/cogs/help_channels.py | 4 +++- bot/cogs/sync/syncers.py | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 187adfe51..fd1a449c1 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -624,11 +624,13 @@ class HelpChannels(Scheduler, commands.Cog): channel = self.bot.get_channel(constants.HelpChannels.notify_channel) mentions = " ".join(f"<@&{role}>" for role in constants.HelpChannels.notify_roles) + allowed_roles = [discord.Object(id_) for id_ in constants.HelpChannels.notify_roles] message = await channel.send( f"{mentions} A new available help channel is needed but there " f"are no more dormant ones. Consider freeing up some in-use channels manually by " - f"using the `{constants.Bot.prefix}dormant` command within the channels." + f"using the `{constants.Bot.prefix}dormant` command within the channels.", + allowed_mentions=discord.AllowedMentions(everyone=False, roles=allowed_roles) ) self.bot.stats.incr("help.out_of_channel_alerts") diff --git a/bot/cogs/sync/syncers.py b/bot/cogs/sync/syncers.py index 536455668..f7ba811bc 100644 --- a/bot/cogs/sync/syncers.py +++ b/bot/cogs/sync/syncers.py @@ -5,6 +5,7 @@ import typing as t from collections import namedtuple from functools import partial +import discord from discord import Guild, HTTPException, Member, Message, Reaction, User from discord.ext.commands import Context @@ -68,7 +69,11 @@ class Syncer(abc.ABC): ) return None - message = await channel.send(f"{self._CORE_DEV_MENTION}{msg_content}") + allowed_roles = [discord.Object(constants.Roles.core_developers)] + message = await channel.send( + f"{self._CORE_DEV_MENTION}{msg_content}", + allowed_mentions=discord.AllowedMentions(everyone=False, roles=allowed_roles) + ) else: await message.edit(content=msg_content) -- cgit v1.2.3 From 3fd89d59081f2c906fa43265471d235f4f5b4749 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sun, 12 Jul 2020 15:08:54 +0200 Subject: Remove pointless comment This comment violates the DRY principle. Co-authored-by: Sebastiaan Zeeff <33516116+SebastiaanZ@users.noreply.github.com> --- config-default.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-default.yml b/config-default.yml index 5dd96d67a..0f6a25ef2 100644 --- a/config-default.yml +++ b/config-default.yml @@ -269,7 +269,7 @@ filter: notify_user_domains: false # Filter configuration - ping_moderators: true # Ping @everyone when we send a mod-alert? + ping_moderators: true offensive_msg_delete_days: 7 # How many days before deleting an offensive message? guild_invite_whitelist: -- cgit v1.2.3 From 4527c038d21149d4d3fab73c54b9a1ad31e671c0 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Mon, 13 Jul 2020 00:17:37 +0200 Subject: Revert "Ping @Moderators in ModLog" Let's continue to use "@everyone" for now, and add an explicit allow for it so that it successfully pings people. There's a full justification for this in the pull request. https://github.com/python-discord/bot/issues/1038 --- bot/cogs/antispam.py | 4 ++-- bot/cogs/filtering.py | 2 +- bot/cogs/moderation/modlog.py | 17 +++++++++++------ bot/cogs/watchchannels/watchchannel.py | 4 ++-- bot/constants.py | 4 ++-- config-default.yml | 4 ++-- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/bot/cogs/antispam.py b/bot/cogs/antispam.py index 71382bba9..0bcca578d 100644 --- a/bot/cogs/antispam.py +++ b/bot/cogs/antispam.py @@ -98,7 +98,7 @@ class DeletionContext: text=mod_alert_message, thumbnail=last_message.author.avatar_url_as(static_format="png"), channel_id=Channels.mod_alerts, - ping_moderators=AntiSpamConfig.ping_moderators + ping_everyone=AntiSpamConfig.ping_everyone ) @@ -132,7 +132,7 @@ class AntiSpam(Cog): await self.mod_log.send_log_message( title="Error: AntiSpam configuration validation failed!", text=body, - ping_moderators=True, + ping_everyone=True, icon_url=Icons.token_removed, colour=Colour.red() ) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index a5d59085f..76ea68660 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -329,7 +329,7 @@ class Filtering(Cog, Scheduler): text=message, thumbnail=msg.author.avatar_url_as(static_format="png"), channel_id=Channels.mod_alerts, - ping_moderators=Filter.ping_moderators, + ping_everyone=Filter.ping_everyone, additional_embeds=additional_embeds, additional_embeds_msg=additional_embeds_msg ) diff --git a/bot/cogs/moderation/modlog.py b/bot/cogs/moderation/modlog.py index a37a9faf5..0a63f57b8 100644 --- a/bot/cogs/moderation/modlog.py +++ b/bot/cogs/moderation/modlog.py @@ -15,7 +15,7 @@ from discord.ext.commands import Cog, Context from discord.utils import escape_markdown from bot.bot import Bot -from bot.constants import Categories, Channels, Colours, Emojis, Event, Guild as GuildConstant, Icons, Roles, URLs +from bot.constants import Categories, Channels, Colours, Emojis, Event, Guild as GuildConstant, Icons, URLs from bot.utils.time import humanize_delta log = logging.getLogger(__name__) @@ -88,7 +88,7 @@ class ModLog(Cog, name="ModLog"): text: str, thumbnail: t.Optional[t.Union[str, discord.Asset]] = None, channel_id: int = Channels.mod_log, - ping_moderators: bool = False, + ping_everyone: bool = False, files: t.Optional[t.List[discord.File]] = None, content: t.Optional[str] = None, additional_embeds: t.Optional[t.List[discord.Embed]] = None, @@ -114,14 +114,19 @@ class ModLog(Cog, name="ModLog"): if thumbnail: embed.set_thumbnail(url=thumbnail) - if ping_moderators: + if ping_everyone: if content: - content = f"<@&{Roles.moderators}>\n{content}" + content = f"@everyone\n{content}" else: - content = f"<@&{Roles.moderators}>" + content = "@everyone" channel = self.bot.get_channel(channel_id) - log_message = await channel.send(content=content, embed=embed, files=files) + log_message = await channel.send( + content=content, + embed=embed, + files=files, + allowed_mentions=discord.AllowedMentions(everyone=True) + ) if additional_embeds: if additional_embeds_msg: diff --git a/bot/cogs/watchchannels/watchchannel.py b/bot/cogs/watchchannels/watchchannel.py index 8c4af4581..7c58a0fb5 100644 --- a/bot/cogs/watchchannels/watchchannel.py +++ b/bot/cogs/watchchannels/watchchannel.py @@ -120,7 +120,7 @@ class WatchChannel(metaclass=CogABCMeta): await self.modlog.send_log_message( title=f"Error: Failed to initialize the {self.__class__.__name__} watch channel", text=message, - ping_moderators=True, + ping_everyone=True, icon_url=Icons.token_removed, colour=Color.red() ) @@ -132,7 +132,7 @@ class WatchChannel(metaclass=CogABCMeta): await self.modlog.send_log_message( title=f"Warning: Failed to retrieve user cache for the {self.__class__.__name__} watch channel", text="Could not retrieve the list of watched users from the API and messages will not be relayed.", - ping_moderators=True, + ping_everyone=True, icon_url=Icons.token_removed, colour=Color.red() ) diff --git a/bot/constants.py b/bot/constants.py index 34b312d2d..a1b392c82 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -225,7 +225,7 @@ class Filter(metaclass=YAMLGetter): notify_user_invites: bool notify_user_domains: bool - ping_moderators: bool + ping_everyone: bool offensive_msg_delete_days: int guild_invite_whitelist: List[int] domain_blacklist: List[str] @@ -522,7 +522,7 @@ class AntiSpam(metaclass=YAMLGetter): section = 'anti_spam' clean_offending: bool - ping_moderators: bool + ping_everyone: bool punishment: Dict[str, Dict[str, int]] rules: Dict[str, Dict[str, int]] diff --git a/config-default.yml b/config-default.yml index 0f6a25ef2..636b9db37 100644 --- a/config-default.yml +++ b/config-default.yml @@ -269,7 +269,7 @@ filter: notify_user_domains: false # Filter configuration - ping_moderators: true + ping_everyone: true offensive_msg_delete_days: 7 # How many days before deleting an offensive message? guild_invite_whitelist: @@ -428,7 +428,7 @@ urls: anti_spam: # Clean messages that violate a rule. clean_offending: true - ping_moderators: true + ping_everyone: true punishment: role_id: *MUTED_ROLE -- cgit v1.2.3