Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,7 @@ async def contact(
creator=creator,
category=category,
manual_trigger=manual_trigger,
# The minimum character check is enforced in ThreadManager.create
)

if thread.cancelled:
Expand Down
5 changes: 5 additions & 0 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class ConfigManager:
# regex
"use_regex_autotrigger": False,
"use_hoisted_top_role": True,
# Minimum characters for thread creation
"thread_min_characters": 0,
"thread_min_characters_title": "Message too short",
"thread_min_characters_response": "Your message is too short to create a thread. Please provide more details.",
"thread_min_characters_footer": "Minimum {min_characters} characters required.",
}

private_keys = {
Expand Down
45 changes: 44 additions & 1 deletion core/config_help.json
Original file line number Diff line number Diff line change
Expand Up @@ -1222,5 +1222,48 @@
"If this configuration is enabled, only roles that are hoisted (displayed seperately in member list) will be used. If a user has no hoisted roles, it will return 'None'.",
"If you would like to display the top role of a user regardless of if it's hoisted or not, disable `use_hoisted_top_role`."
]
},
"thread_min_characters": {
"default": "0",
"description": "The minimum number of characters required in the initial message to create a thread. Set to 0 to disable.",
"examples": [
"`{prefix}config set thread_min_characters 20`"
],
"notes": [
"If a user tries to create a thread with a message shorter than this, an error will be shown.",
"See also: `thread_min_characters_title`, `thread_min_characters_response`, `thread_min_characters_footer`."
]
},
"thread_min_characters_title": {
"default": "Message too short",
"description": "The title of the error embed when a user tries to create a thread with too few characters.",
"examples": [
"`{prefix}config set thread_min_characters_title Too short!`"
],
"notes": [
"See also: `thread_min_characters`, `thread_min_characters_response`, `thread_min_characters_footer`."
]
},
"thread_min_characters_response": {
"default": "Your message is too short to create a thread. Please provide more details.",
"description": "The description of the error embed when a user tries to create a thread with too few characters.",
"examples": [
"`{prefix}config set thread_min_characters_response Please write a longer message.`"
],
"notes": [
"You can use `{min_characters}` as a placeholder for the minimum required characters.",
"See also: `thread_min_characters`, `thread_min_characters_title`, `thread_min_characters_footer`."
]
},
"thread_min_characters_footer": {
"default": "Minimum {min_characters} characters required.",
"description": "The footer of the error embed when a user tries to create a thread with too few characters.",
"examples": [
"`{prefix}config set thread_min_characters_footer At least {min_characters} characters needed.`"
],
"notes": [
"You can use `{min_characters}` as a placeholder for the minimum required characters.",
"See also: `thread_min_characters`, `thread_min_characters_title`, `thread_min_characters_response`."
]
}
}
}
21 changes: 21 additions & 0 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,27 @@ async def create(
) -> Thread:
"""Creates a Modmail thread"""

# Minimum character check
min_chars = self.bot.config.get("thread_min_characters")
if min_chars is None:
min_chars = 0
try:
min_chars = int(min_chars)
except ValueError:
min_chars = 0
if min_chars > 0 and message is not None and message.content is not None:
if len(message.content.strip()) < min_chars:
embed = discord.Embed(
title=self.bot.config["thread_min_characters_title"],
description=self.bot.config["thread_min_characters_response"].replace("{min_characters}", str(min_chars)),
color=self.bot.error_color,
)
embed.set_footer(text=self.bot.config["thread_min_characters_footer"].replace("{min_characters}", str(min_chars)))
await message.channel.send(embed=embed)
thread = Thread(self, recipient)
thread.cancelled = True
return thread

# checks for existing thread in cache
thread = self.cache.get(recipient.id)
if thread:
Expand Down
Loading