From 341fd254fb71bb61c76a75d949220d01cd820676 Mon Sep 17 00:00:00 2001 From: Trent Kable Date: Sat, 15 Aug 2020 17:59:53 -0500 Subject: [PATCH] Add allowed_mentions and mention everyone check to stream alerts (#4182) * [streams]allowed_mentions on stream announcement Allows role mentions for discord.py 1.4+ # Type [x] Bugfix [ ] Enhancement [ ] New feature Description of the changes Referencing line 747. Gives permissions to mention role on stream announcement. * Update streams.py * Add `mention_everyone` defaults Lines for reference: - [751-753]: ```py if can_mention_everyone: await self.save_streams() return # if bot can mention everyone already, let's stop here``` - [722-774]: ```py if can_mention_everyone: mentions.append(role.mention) return # if bot can mention everyone already, let's stop here (part two)``` Hopefully, this is what you had in mind? Humbly admit I may not have a business in biting this piece but looking forward to feedback on the best methodology for the wanted outcome. Thanks! * *sweats* * imagine variable naming Should complete all passes. * misplaced unindent on return * Update redbot/cogs/streams/streams.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/streams/streams.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update redbot/cogs/streams/streams.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * You're a beast jack Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * this would cover all channels in guild (think) * give this a reeeeee * Update streams.py * adds channel argument https://github.com/Cog-Creators/Red-DiscordBot/pull/4182#pullrequestreview-468012281 * image style checking, self * imagine Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/cogs/streams/streams.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py index fc8c2138c..653c7d28c 100644 --- a/redbot/cogs/streams/streams.py +++ b/redbot/cogs/streams/streams.py @@ -712,7 +712,9 @@ class Streams(commands.Cog): ignore_reruns = await self.config.guild(channel.guild).ignore_reruns() if ignore_reruns and is_rerun: continue - mention_str, edited_roles = await self._get_mention_str(channel.guild) + mention_str, edited_roles = await self._get_mention_str( + channel.guild, channel + ) if mention_str: alert_msg = await self.config.guild( @@ -749,14 +751,20 @@ class Streams(commands.Cog): ) ) - m = await channel.send(content, embed=embed) + m = await channel.send( + content, + embed=embed, + allowed_mentions=discord.AllowedMentions(roles=True, everyone=True), + ) stream._messages_cache.append(m) if edited_roles: for role in edited_roles: await role.edit(mentionable=False) await self.save_streams() - async def _get_mention_str(self, guild: discord.Guild) -> Tuple[str, List[discord.Role]]: + async def _get_mention_str( + self, guild: discord.Guild, channel: discord.TextChannel + ) -> Tuple[str, List[discord.Role]]: """Returns a 2-tuple with the string containing the mentions, and a list of all roles which need to have their `mentionable` property set back to False. """ @@ -768,9 +776,10 @@ class Streams(commands.Cog): if await settings.mention_here(): mentions.append("@here") can_manage_roles = guild.me.guild_permissions.manage_roles + can_mention_everyone = channel.permissions_for(guild.me).mention_everyone for role in guild.roles: if await self.config.role(role).mention(): - if can_manage_roles and not role.mentionable: + if not can_mention_everyone and can_manage_roles and not role.mentionable: try: await role.edit(mentionable=True) except discord.Forbidden: