aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2021-04-30 12:35:25 +0100
committerGravatar GitHub <[email protected]>2021-04-30 12:35:25 +0100
commit9e59a1aa4d14481411abb931731fa2c807a96ae8 (patch)
treea515094f5df18615af14a016cfb4c174769cf205
parentMerge pull request #954 from ks129/error-handler-test (diff)
parentMerge branch 'main' into master (diff)
Merge pull request #1551 from dolphingarlic/master
Fixed the code snippets limits
-rw-r--r--bot/exts/info/code_snippets.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/bot/exts/info/code_snippets.py b/bot/exts/info/code_snippets.py
index c20115830..6ebc5e74b 100644
--- a/bot/exts/info/code_snippets.py
+++ b/bot/exts/info/code_snippets.py
@@ -8,6 +8,7 @@ from discord import Message
from discord.ext.commands import Cog
from bot.bot import Bot
+from bot.constants import Channels
from bot.utils.messages import wait_for_deletion
log = logging.getLogger(__name__)
@@ -234,12 +235,23 @@ class CodeSnippets(Cog):
# Sorts the list of snippets by their match index and joins them into a single message
message_to_send = '\n'.join(map(lambda x: x[1], sorted(all_snippets)))
- if 0 < len(message_to_send) <= 2000 and len(all_snippets) <= 15:
+ if 0 < len(message_to_send) <= 2000 and message_to_send.count('\n') <= 15:
await message.edit(suppress=True)
- await wait_for_deletion(
- await message.channel.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()
+ await message.channel.send(('The snippet you tried to send was too long. Please '
+ f'see <#{Channels.bot_commands}> for the full snippet.'))
+ bot_commands_channel = self.bot.get_channel(Channels.bot_commands)
+ await wait_for_deletion(
+ await bot_commands_channel.send(message_to_send),
+ (message.author.id,)
+ )
+ else:
+ await wait_for_deletion(
+ await message.channel.send(message_to_send),
+ (message.author.id,)
+ )
def setup(bot: Bot) -> None: