diff --git a/ccrole/ccrole.py b/ccrole/ccrole.py index 5dbbf1f..bd41a67 100644 --- a/ccrole/ccrole.py +++ b/ccrole/ccrole.py @@ -8,6 +8,19 @@ from redbot.core.bot import Red from redbot.core.utils.chat_formatting import box, pagify +async def _get_roles_from_content(ctx, content): + content_list = content.split(",") + try: + role_list = [ + discord.utils.get(ctx.guild.roles, name=role.strip(" ")).id + for role in content_list + ] + except (discord.HTTPException, AttributeError): # None.id is attribute error + return None + else: + return role_list + + class CCRole(commands.Cog): """ Custom commands @@ -77,7 +90,7 @@ class CCRole(commands.Cog): arole_list = [] if answer.content.upper() != "NONE": - arole_list = await self._get_roles_from_content(ctx, answer.content) + arole_list = await _get_roles_from_content(ctx, answer.content) if arole_list is None: await ctx.send("Invalid answer, canceling") return @@ -94,7 +107,7 @@ class CCRole(commands.Cog): rrole_list = [] if answer.content.upper() != "NONE": - rrole_list = await self._get_roles_from_content(ctx, answer.content) + rrole_list = await _get_roles_from_content(ctx, answer.content) if rrole_list is None: await ctx.send("Invalid answer, canceling") return @@ -112,7 +125,7 @@ class CCRole(commands.Cog): prole_list = [] if answer.content.upper() != "NONE": - prole_list = await self._get_roles_from_content(ctx, answer.content) + prole_list = await _get_roles_from_content(ctx, answer.content) if prole_list is None: await ctx.send("Invalid answer, canceling") return @@ -244,14 +257,17 @@ class CCRole(commands.Cog): https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/cogs/customcom/customcom.py#L508 for the message filtering """ + # This covers message.author.bot check + if not await self.bot.message_eligible_as_command(message): + return + ########### is_private = isinstance(message.channel, discord.abc.PrivateChannel) - # user_allowed check, will be replaced with self.bot.user_allowed or - # something similar once it's added - user_allowed = True + if is_private or len(message.content) < 2: + return - if len(message.content) < 2 or is_private or not user_allowed or message.author.bot: + if await self.bot.cog_disabled_in_guild(self, message.guild): return ctx = await self.bot.get_context(message) @@ -273,40 +289,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: - role_list = [ - discord.utils.get(ctx.guild.roles, name=role.strip(" ")).id - for role in content_list - ] - except (discord.HTTPException, AttributeError): # None.id is attribute error - return None - else: - return role_list - async def get_prefix(self, message: discord.Message) -> str: """ Borrowed from alias cog @@ -325,7 +307,7 @@ 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"]) @@ -400,7 +382,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/ccrole/info.json b/ccrole/info.json index 8021be9..4f29a5f 100644 --- a/ccrole/info.json +++ b/ccrole/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Creates custom commands to adjust roles and send custom messages", "hidden": false, "install_msg": "Thank you for installing Custom Commands w/ Roles. Get started with `[p]load ccrole` and `[p]help CCRole`", diff --git a/chatter/chat.py b/chatter/chat.py index 20d13ff..54f3b2d 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -219,7 +219,7 @@ class Chatter(Cog): @chatter.command(name="algorithm", aliases=["algo"]) async def chatter_algorithm( - self, ctx: commands.Context, algo_number: int, threshold: float = None + self, ctx: commands.Context, algo_number: int, threshold: float = None ): """ Switch the active logic algorithm to one of the three. Default after reload is Spacy @@ -283,7 +283,9 @@ class Chatter(Cog): async with ctx.typing(): self.chatbot = self._create_chatbot() - await ctx.maybe_send_embed(f"Model has been switched to {self.tagger_language.ISO_639_1}") + await ctx.maybe_send_embed( + f"Model has been switched to {self.tagger_language.ISO_639_1}" + ) @chatter.command(name="minutes") async def minutes(self, ctx: commands.Context, minutes: int): @@ -427,6 +429,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/chatter/info.json b/chatter/info.json index abf51a8..e9749ff 100644 --- a/chatter/info.json +++ b/chatter/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.10", + "min_bot_version": "3.4.0", "description": "Create an offline chatbot that talks like your average member using Machine Learning", "hidden": false, "install_msg": "Thank you for installing Chatter! Get started ith `[p]load chatter` and `[p]help Chatter`", diff --git a/dad/dad.py b/dad/dad.py index de4361e..edf98c5 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,10 @@ 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/dad/info.json b/dad/info.json index c4b2dd8..caabef6 100644 --- a/dad/info.json +++ b/dad/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Tell dad jokes and give out bad nicknames", "hidden": false, "install_msg": "Thank you for installing Dad. Get started with `[p]load dad`, then `[p]help Dad`", 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/exclusiverole/info.json b/exclusiverole/info.json index 426eabd..dd0ecfd 100644 --- a/exclusiverole/info.json +++ b/exclusiverole/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Assign roles to be exclusive, preventing other roles from being added", "hidden": false, "install_msg": "Thank you for installing ExclusiveRole. Get started with `[p]load exclusiverole` and `[p]help ExclusiveRole`", diff --git a/flag/flag.py b/flag/flag.py index f93de2f..035ae1d 100644 --- a/flag/flag.py +++ b/flag/flag.py @@ -66,7 +66,9 @@ class Flag(Cog): Set the number of days for flags to expire after for server """ await self.config.guild(ctx.guild).days.set(days) - await ctx.maybe_send_embed("Number of days for new flags to expire is now {} days".format(days)) + await ctx.maybe_send_embed( + "Number of days for new flags to expire is now {} days".format(days) + ) @flagset.command(name="dm") async def flagset_dm(self, ctx: commands.Context): @@ -75,7 +77,9 @@ class Flag(Cog): dm = await self.config.guild(ctx.guild).dm() await self.config.guild(ctx.guild).dm.set(not dm) - await ctx.maybe_send_embed("DM-ing members when they get a flag is now set to **{}**".format(not dm)) + await ctx.maybe_send_embed( + "DM-ing members when they get a flag is now set to **{}**".format(not dm) + ) @staticmethod def _flag_template(): 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..c7d005d 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 @@ -179,14 +180,18 @@ class Hangman(Cog): current = await self.config.guild(ctx.guild).emojis() await self.config.guild(ctx.guild).emojis.set(not current) - await ctx.maybe_send_embed("Emoji Letter reactions have been set to {}".format(not current)) + await ctx.maybe_send_embed( + "Emoji Letter reactions have been set to {}".format(not current) + ) @commands.command(aliases=["hang"]) async def hangman(self, ctx, guess: str = None): """Play a game of hangman against the bot!""" if guess is None: if self.the_data[ctx.guild]["running"]: - await ctx.maybe_send_embed("Game of hangman is already running!\nEnter your guess!") + await ctx.maybe_send_embed( + "Game of hangman is already running!\nEnter your guess!" + ) await self._printgame(ctx.channel) """await self.bot.send_cmd_help(ctx)""" else: @@ -194,7 +199,9 @@ class Hangman(Cog): self._startgame(ctx.guild) await self._printgame(ctx.channel) elif not self.the_data[ctx.guild]["running"]: - await ctx.maybe_send_embed("Game of hangman is not yet running!\nStarting a game of hangman!") + await ctx.maybe_send_embed( + "Game of hangman is not yet running!\nStarting a game of hangman!" + ) self._startgame(ctx.guild) await self._printgame(ctx.channel) else: @@ -280,15 +287,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/hangman/info.json b/hangman/info.json index b4db258..6b22848 100644 --- a/hangman/info.json +++ b/hangman/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Play Hangman with your friends", "hidden": false, "install_msg": "Thank you for installing Hangman! Get started with `[p]load hangman`, then `[p]help Hangman`", diff --git a/infochannel/info.json b/infochannel/info.json index b8fad4e..5cafb35 100644 --- a/infochannel/info.json +++ b/infochannel/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Create a channel with updating server info", "hidden": false, "install_msg": "Thank you for installing InfoChannel. Get started with `[p]load infochannel`, then `[p]help InfoChannel`", 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/info.json b/leaver/info.json index 0c8d3d1..3ca9986 100644 --- a/leaver/info.json +++ b/leaver/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Keeps track of when people leave the server, and posts a message notifying", "hidden": false, "install_msg": "Thank you for installing Leaver. Get started with `[p]load leaver`, then `[p]help Leaver`", 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/lovecalculator/lovecalculator.py b/lovecalculator/lovecalculator.py index ad57c5d..1b7e5c1 100644 --- a/lovecalculator/lovecalculator.py +++ b/lovecalculator/lovecalculator.py @@ -18,7 +18,7 @@ class LoveCalculator(Cog): @commands.command(aliases=["lovecalc"]) async def lovecalculator( - self, ctx: commands.Context, lover: discord.Member, loved: discord.Member + self, ctx: commands.Context, lover: discord.Member, loved: discord.Member ): """Calculate the love percentage!""" @@ -34,8 +34,8 @@ class LoveCalculator(Cog): try: description = ( soup_object.find("div", attrs={"class": "result__score"}) - .get_text() - .strip() + .get_text() + .strip() ) except: description = "Dr. Love is busy right now" diff --git a/lseen/info.json b/lseen/info.json index 33ae133..dcef201 100644 --- a/lseen/info.json +++ b/lseen/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Keep track of when users were last seen online", "hidden": false, "install_msg": "Thank you for installing LastSeen. Get started with `[p]load lseen`, then `[p]help LastSeen`", diff --git a/lseen/lseen.py b/lseen/lseen.py index abfef2d..a451f57 100644 --- a/lseen/lseen.py +++ b/lseen/lseen.py @@ -75,7 +75,9 @@ class LastSeen(Cog): else: last_seen = await self.config.member(member).seen() if last_seen is None: - await ctx.maybe_send_embed(embed=discord.Embed(description="I've never seen this user")) + await ctx.maybe_send_embed( + embed=discord.Embed(description="I've never seen this user") + ) return last_seen = self.get_date_time(last_seen) @@ -89,6 +91,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/info..json b/nudity/info..json index 4a2c1fb..b8c757f 100644 --- a/nudity/info..json +++ b/nudity/info..json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.11", + "min_bot_version": "3.4.0", "description": "Monitor images for NSFW content and moves them to a nsfw channel if possible", "hidden": false, "install_msg": "Thank you for installing Nudity. Get started with `[p]load nudity`, then `[p]help Nudity`", 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/qrinvite/qrinvite.py b/qrinvite/qrinvite.py index c35f617..ab5f5dc 100644 --- a/qrinvite/qrinvite.py +++ b/qrinvite/qrinvite.py @@ -48,7 +48,9 @@ class QRInvite(Cog): invite = await ctx.channel.invites() invite = invite[0] except discord.Forbidden: - await ctx.maybe_send_embed("No permission to get an invite, please provide one") + await ctx.maybe_send_embed( + "No permission to get an invite, please provide one" + ) return invite = invite.code diff --git a/reactrestrict/info.json b/reactrestrict/info.json index 1eaa291..9dbbe8b 100644 --- a/reactrestrict/info.json +++ b/reactrestrict/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Cog to prevent reactions on specific messages from certain users", "hidden": false, "install_msg": "Thank you for installing ReactRestrict.", 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/info.json b/stealemoji/info.json index f91ce8e..c050f85 100644 --- a/stealemoji/info.json +++ b/stealemoji/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.3.0", + "min_bot_version": "3.4.0", "description": "Steals custom emojis the bot sees and moves them to an emoji server", "hidden": false, "install_msg": "Thank you for installing StealEmoji", 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..99bc768 100644 --- a/werewolf/info.json +++ b/werewolf/info.json @@ -8,7 +8,7 @@ "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 stores user IDs in memory while they're actively using the cog, and stores no persistent End User Data.", "tags": [ "mafia", "werewolf",