From 151eca1c7693f9f07a4f57f402eeab69888c2942 Mon Sep 17 00:00:00 2001 From: bobloy Date: Tue, 18 Aug 2020 10:01:10 -0400 Subject: [PATCH] More 3.4 compatibility, mentions and listeners --- ccrole/ccrole.py | 33 +++++++-------------------------- chatter/chat.py | 3 +++ dad/dad.py | 6 +++++- exclusiverole/exclusiverole.py | 3 +++ forcemention/forcemention.py | 15 +++++++++++++-- forcemention/info.json | 2 +- hangman/hangman.py | 16 ++++++++++++---- infochannel/infochannel.py | 6 ++++++ leaver/leaver.py | 4 ++++ lseen/lseen.py | 4 +++- nudity/nudity.py | 3 +++ reactrestrict/reactrestrict.py | 3 +++ stealemoji/stealemoji.py | 4 ++++ werewolf/info.json | 3 ++- 14 files changed, 69 insertions(+), 36 deletions(-) diff --git a/ccrole/ccrole.py b/ccrole/ccrole.py index 5dbbf1f..f162d44 100644 --- a/ccrole/ccrole.py +++ b/ccrole/ccrole.py @@ -229,7 +229,7 @@ class CCRole(commands.Cog): cmd_list = "Custom commands:\n\n" + cmd_list if ( - len(cmd_list) < 1500 + len(cmd_list) < 1500 ): # I'm allowed to have arbitrary numbers for when it's too much to dm dammit await ctx.send(box(cmd_list)) else: @@ -254,6 +254,9 @@ class CCRole(commands.Cog): if len(message.content) < 2 or is_private or not user_allowed or message.author.bot: return + if await self.bot.cog_disabled_in_guild(self, message.guild): + return + ctx = await self.bot.get_context(message) if ctx.prefix is None: @@ -273,28 +276,6 @@ class CCRole(commands.Cog): if cmd is not None: await self.eval_cc(cmd, message, ctx) - # @commands.Cog.listener() - # async def on_message(self, message: discord.Message): - # if len(message.content) < 2 or message.guild is None: - # return - # - # ctx: commands.Context = await self.bot.get_context(message) - # cmd = ctx.invoked_with - # guild = message.guild - # # try: - # # prefix = await self.get_prefix(message) - # # except ValueError: - # # return - # - # # prefix = ctx.prefix - # - # cmdlist = self.config.guild(guild).cmdlist - # # cmd = message.content[len(prefix) :].split()[0].lower() - # cmd = await cmdlist.get_raw(cmd, default=None) - # - # if cmd is not None: - # await self.eval_cc(cmd, message, ctx) - async def _get_roles_from_content(self, ctx, content): content_list = content.split(",") try: @@ -325,10 +306,10 @@ class CCRole(commands.Cog): return p raise ValueError - async def eval_cc(self, cmd, message, ctx): + async def eval_cc(self, cmd, message: discord.Message, ctx: commands.Context): """Does all the work""" if cmd["proles"] and not ( - set(role.id for role in message.author.roles) & set(cmd["proles"]) + set(role.id for role in message.author.roles) & set(cmd["proles"]) ): return # Not authorized, do nothing @@ -400,7 +381,7 @@ class CCRole(commands.Cog): await message.channel.send("Permission error: Unable to remove roles") out_message = self.format_cc(cmd, message, target) - await message.channel.send(out_message) + await message.channel.send(out_message, allowed_mentions=discord.AllowedMentions()) def format_cc(self, cmd, message, target): out = cmd["text"] diff --git a/chatter/chat.py b/chatter/chat.py index 20d13ff..35e5b5b 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -427,6 +427,9 @@ class Chatter(Cog): if len(message.content) < 2 or is_private or not user_allowed or message.author.bot: return + if await self.bot.cog_disabled_in_guild(self, message.guild): + return + ctx: commands.Context = await self.bot.get_context(message) if ctx.prefix is not None: diff --git a/dad/dad.py b/dad/dad.py index de4361e..b59ceb1 100644 --- a/dad/dad.py +++ b/dad/dad.py @@ -89,6 +89,9 @@ class Dad(Cog): if guild is None: return + if await self.bot.cog_disabled_in_guild(self, guild): + return + guild_config = self.config.guild(guild) is_on = await guild_config.enabled() if not is_on: @@ -113,7 +116,8 @@ class Dad(Cog): else: out = cleaned_content[4:] try: - await message.channel.send(f"Hi {out}, I'm {guild.me.display_name}!") + await message.channel.send(f"Hi {out}, I'm {guild.me.display_name}!", + allowed_mentions=discord.AllowedMentions) except discord.HTTPException: return diff --git a/exclusiverole/exclusiverole.py b/exclusiverole/exclusiverole.py index 6dc4b84..ce94a7d 100644 --- a/exclusiverole/exclusiverole.py +++ b/exclusiverole/exclusiverole.py @@ -97,6 +97,9 @@ class ExclusiveRole(Cog): if before.roles == after.roles: return + if await self.bot.cog_disabled_in_guild(self, after.guild): + return + await asyncio.sleep(1) role_set = set(await self.config.guild(after.guild).role_list()) diff --git a/forcemention/forcemention.py b/forcemention/forcemention.py index 2aeaac5..dd8948c 100644 --- a/forcemention/forcemention.py +++ b/forcemention/forcemention.py @@ -1,5 +1,6 @@ import asyncio +import discord from discord.utils import get from redbot.core import Config, checks, commands from redbot.core.bot import Red @@ -38,8 +39,18 @@ class ForceMention(Cog): if not role_obj.mentionable: await role_obj.edit(mentionable=True) - await ctx.send("{}\n{}".format(role_obj.mention, message)) + await ctx.send( + "{}\n{}".format(role_obj.mention, message), + allowed_mentions=discord.AllowedMentions( + everyone=False, users=False, roles=[role_obj] + ), + ) await asyncio.sleep(5) await role_obj.edit(mentionable=False) else: - await ctx.send("{}\n{}".format(role_obj.mention, message)) + await ctx.send( + "{}\n{}".format(role_obj.mention, message), + allowed_mentions=discord.AllowedMentions( + everyone=False, users=False, roles=[role_obj] + ), + ) diff --git a/forcemention/info.json b/forcemention/info.json index e99f611..7644234 100644 --- a/forcemention/info.json +++ b/forcemention/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Mentions roles that are unmentionable", "hidden": false, "install_msg": "Thank you for installing ForceMention! Get started with `[p]load forcemention`, then `[p]forcemention`", diff --git a/hangman/hangman.py b/hangman/hangman.py index 338e8b7..2aca999 100644 --- a/hangman/hangman.py +++ b/hangman/hangman.py @@ -1,5 +1,6 @@ from collections import defaultdict from random import randint +from typing import Union import discord from redbot.core import Config, checks, commands @@ -280,15 +281,22 @@ class Hangman(Cog): await self._reprintgame(message) @commands.Cog.listener() - async def on_react(self, reaction, user): + async def on_react(self, reaction, user: Union[discord.User, discord.Member]): """ Thanks to flapjack reactpoll for guidelines https://github.com/flapjax/FlapJack-Cogs/blob/master/reactpoll/reactpoll.py""" + guild: discord.Guild = getattr(user, "guild", None) + if guild is None: + return + + if reaction.message.id != self.the_data[guild]["trackmessage"]: + return + + if user.bot: + return # Don't react to bot reactions - if reaction.message.id != self.the_data[user.guild]["trackmessage"]: + if await self.bot.cog_disabled_in_guild(self, guild): return - if user == self.bot.user: - return # Don't react to bot's own reactions message = reaction.message emoji = reaction.emoji diff --git a/infochannel/infochannel.py b/infochannel/infochannel.py index eb393d0..c7297b8 100644 --- a/infochannel/infochannel.py +++ b/infochannel/infochannel.py @@ -273,14 +273,20 @@ class InfoChannel(Cog): @Cog.listener() async def on_member_join(self, member: discord.Member): + if await self.bot.cog_disabled_in_guild(self, member.guild): + return await self.update_infochannel_with_cooldown(member.guild) @Cog.listener() async def on_member_remove(self, member: discord.Member): + if await self.bot.cog_disabled_in_guild(self, member.guild): + return await self.update_infochannel_with_cooldown(member.guild) @Cog.listener() async def on_member_update(self, before: discord.Member, after: discord.Member): + if await self.bot.cog_disabled_in_guild(self, after.guild): + return onlinecount = await self.config.guild(after.guild).online_count() if onlinecount: if before.status != after.status: diff --git a/leaver/leaver.py b/leaver/leaver.py index 9475384..0c0d947 100644 --- a/leaver/leaver.py +++ b/leaver/leaver.py @@ -38,6 +38,10 @@ class Leaver(Cog): @commands.Cog.listener() async def on_member_remove(self, member: discord.Member): guild = member.guild + + if await self.bot.cog_disabled_in_guild(self, guild): + return + channel = await self.config.guild(guild).channel() if channel != "": diff --git a/lseen/lseen.py b/lseen/lseen.py index abfef2d..e22f479 100644 --- a/lseen/lseen.py +++ b/lseen/lseen.py @@ -89,6 +89,8 @@ class LastSeen(Cog): @commands.Cog.listener() async def on_member_update(self, before: discord.Member, after: discord.Member): if before.status != self.offline_status and after.status == self.offline_status: - if not await self.config.guild(before.guild).enabled(): + if await self.bot.cog_disabled_in_guild(self, after.guild): + return + if not await self.config.guild(after.guild).enabled(): return await self.config.member(before).seen.set(datetime.utcnow().isoformat()) diff --git a/nudity/nudity.py b/nudity/nudity.py index 6eb4221..0d46ca9 100644 --- a/nudity/nudity.py +++ b/nudity/nudity.py @@ -96,6 +96,9 @@ class Nudity(commands.Cog): # print("did not qualify") return + if await self.bot.cog_disabled_in_guild(self, message.guild): + return + try: is_on = await self.config.guild(message.guild).enabled() except AttributeError: diff --git a/reactrestrict/reactrestrict.py b/reactrestrict/reactrestrict.py index 585d7dc..4030538 100644 --- a/reactrestrict/reactrestrict.py +++ b/reactrestrict/reactrestrict.py @@ -281,6 +281,9 @@ class ReactRestrict(Cog): if member.bot: return + if await self.bot.cog_disabled_in_guild(self, member.guild): + return + try: roles = [self._get_role(member.guild, c.role_id) for c in combos] except LookupError: diff --git a/stealemoji/stealemoji.py b/stealemoji/stealemoji.py index d3391e6..b1c7de5 100644 --- a/stealemoji/stealemoji.py +++ b/stealemoji/stealemoji.py @@ -181,6 +181,10 @@ class StealEmoji(Cog): # print("Collecting is off") return + guild: discord.Guild = getattr(user, "guild", None) + if await self.bot.cog_disabled_in_guild(self, guild): # Handles None guild just fine + return + emoji: discord.Emoji = reaction.emoji if emoji in self.bot.emojis: # print("Emoji already in bot.emojis") diff --git a/werewolf/info.json b/werewolf/info.json index af67794..250edd4 100644 --- a/werewolf/info.json +++ b/werewolf/info.json @@ -3,12 +3,13 @@ "Bobloy" ], "min_bot_version": "3.3.0", + "max_bot_version": "3.3.12", "description": "Customizable Werewolf Game", "hidden": true, "install_msg": "Thank you for installing Werewolf! Get started with `[p]load werewolf`\n Use `[p]wwset` to run inital setup", "requirements": [], "short": "Werewolf Game", - "end_user_data_statement": "This store user IDs in memory while they're actively using the cog, and store no persistent End User Data.", + "end_user_data_statement": "This store user IDs in memory while they're actively using the cog, and stores no persistent End User Data.", "tags": [ "mafia", "werewolf",