From 0d5da9e1304865034e8a2349d33b132e149ad890 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 5 Feb 2021 19:17:59 +0000 Subject: First pass of easy to produce errors --- bot/exts/evergreen/issues.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'bot/exts/evergreen/issues.py') diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 73ebe547..1f22f287 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -178,7 +178,12 @@ class Issues(commands.Cog): @commands.Cog.listener() async def on_message(self, message: discord.Message) -> None: """Command to retrieve issue(s) from a GitHub repository using automatic linking if matching #.""" - if not( + # Ignore messages from DMs + if not message.guild: + return + + # Ignore messages not in whitelisted categories / channels + if not ( message.channel.category.id in WHITELISTED_CATEGORIES or message.channel.id in WHITELISTED_CHANNELS_ON_MESSAGE ): -- cgit v1.2.3 From e3b7b3bc5b56b805112558377e25e2537cc86083 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 2 Apr 2021 14:53:27 +0100 Subject: Don't allow users to run the issue command in DMs, given error feedback. --- bot/exts/evergreen/issues.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'bot/exts/evergreen/issues.py') diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 1f22f287..0f0be33a 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -7,7 +7,16 @@ from enum import Enum import discord from discord.ext import commands, tasks -from bot.constants import Categories, Channels, Colours, ERROR_REPLIES, Emojis, Tokens, WHITELISTED_CHANNELS +from bot.constants import ( + Categories, + Channels, + Colours, + ERROR_REPLIES, + Emojis, + NEGATIVE_REPLIES, + Tokens, + WHITELISTED_CHANNELS +) log = logging.getLogger(__name__) @@ -148,11 +157,20 @@ class Issues(commands.Cog): user: str = "python-discord" ) -> None: """Command to retrieve issue(s) from a GitHub repository.""" - if not( + if not ctx.guild or not( ctx.channel.category.id in WHITELISTED_CATEGORIES or ctx.channel.id in WHITELISTED_CHANNELS ): - return + await ctx.send( + embed=discord.Embed( + title=random.choice(NEGATIVE_REPLIES), + description=( + "You can't run this command in this channel. " + f"Try again in {Channels.community_bot_commands}" + ), + colour=discord.Colour.red() + ) + ) result = await self.fetch_issues(set(numbers), repository, user) -- cgit v1.2.3 From 6a8a582c49c2a3d97a2a061eca157502acb0618d Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 2 Apr 2021 17:02:47 +0100 Subject: Send error embed when a user tries to retrieve an issue in DMs --- bot/exts/evergreen/issues.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'bot/exts/evergreen/issues.py') diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index ca0e4494..4a73d20b 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -168,11 +168,12 @@ class Issues(commands.Cog): title=random.choice(NEGATIVE_REPLIES), description=( "You can't run this command in this channel. " - f"Try again in {Channels.community_bot_commands}" + f"Try again in <#{Channels.community_bot_commands}>" ), colour=discord.Colour.red() ) ) + return result = await self.fetch_issues(set(numbers), repository, user) @@ -198,12 +199,8 @@ class Issues(commands.Cog): @commands.Cog.listener() async def on_message(self, message: discord.Message) -> None: """Command to retrieve issue(s) from a GitHub repository using automatic linking if matching #.""" - # Ignore messages from DMs - if not message.guild: - return - - # Ignore messages not in whitelisted categories / channels - if not ( + # Ignore messages not in whitelisted categories / channels, only when in guild. + if message.guild and not ( message.channel.category.id in WHITELISTED_CATEGORIES or message.channel.id in WHITELISTED_CHANNELS_ON_MESSAGE ): @@ -213,6 +210,18 @@ class Issues(commands.Cog): links = [] if message_repo_issue_map: + if not message.guild: + await message.channel.send( + embed=discord.Embed( + title=random.choice(NEGATIVE_REPLIES), + description=( + "You can't retreive issues from DMs. " + f"Try again in <#{Channels.community_bot_commands}>" + ), + colour=discord.Colour.red() + ) + ) + return for repo_issue in message_repo_issue_map: if not self.check_in_block(message, " ".join(repo_issue)): result = await self.fetch_issues({repo_issue[1]}, repo_issue[0], "python-discord") -- cgit v1.2.3