aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ToxicKidz <[email protected]>2022-02-28 16:04:10 -0500
committerGravatar ToxicKidz <[email protected]>2022-02-28 16:10:51 -0500
commit880d42a384e90db34faebbbdeb47d879704c13fd (patch)
tree57693815b5021467ceacae2b88c78263e04fe719
parentFix two errors (diff)
chore: Disallow code snippets in DMs
-rw-r--r--bot/exts/info/code_snippets.py38
1 files changed, 16 insertions, 22 deletions
diff --git a/bot/exts/info/code_snippets.py b/bot/exts/info/code_snippets.py
index ebc7ce1c6..f2f29020f 100644
--- a/bot/exts/info/code_snippets.py
+++ b/bot/exts/info/code_snippets.py
@@ -246,6 +246,9 @@ class CodeSnippets(Cog):
if message.author.bot:
return
+ if message.guild is None:
+ return
+
message_to_send = await self._parse_snippets(message.content)
destination = message.channel
@@ -255,30 +258,21 @@ class CodeSnippets(Cog):
except discord.NotFound:
# Don't send snippets if the original message was deleted.
return
- except discord.Forbidden as e:
- # We still want to send snippets when in DMs, but if we're in guild then
- # reraise error since that means there's a permissions issue with the bot.
- if message.guild:
- raise e
-
- # If we're in a guild, then check if we need to redirect to #bot-commands
- if message.guild:
- if len(message_to_send) > 1000 and message.channel.id != Channels.bot_commands:
- # Redirects to #bot-commands if the snippet contents are too long
- await self.bot.wait_until_guild_available()
- destination = self.bot.get_channel(Channels.bot_commands)
-
- await message.channel.send(
- 'The snippet you tried to send was too long. '
- f'Please see {destination.mention} for the full snippet.'
- )
- await wait_for_deletion(
- await destination.send(message_to_send),
- (message.author.id,)
+ if len(message_to_send) > 1000 and message.channel.id != Channels.bot_commands:
+ # Redirects to #bot-commands if the snippet contents are too long
+ await self.bot.wait_until_guild_available()
+ destination = self.bot.get_channel(Channels.bot_commands)
+
+ await message.channel.send(
+ 'The snippet you tried to send was too long. '
+ f'Please see {destination.mention} for the full snippet.'
)
- else:
- await destination.send(message_to_send)
+
+ await wait_for_deletion(
+ await destination.send(message_to_send),
+ (message.author.id,)
+ )
def setup(bot: Bot) -> None: