Skip to content

Commit 6412f13

Browse files
authored
Feature/ignore prefix (#2)
Add ignore_prefix config option When reply_without_command is enabled, a message starting with this character (or string) will not be sent as a reply
1 parent e98a540 commit 6412f13

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

bot.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ async def on_message(self, message):
15251525

15261526
await self.process_commands(message)
15271527

1528-
async def process_commands(self, message):
1528+
async def process_commands(self, message: discord.Message):
15291529
if message.author.bot:
15301530
return
15311531

@@ -1593,9 +1593,16 @@ async def process_commands(self, message):
15931593
or self.config.get("anon_reply_without_command")
15941594
or self.config.get("plain_reply_without_command")
15951595
):
1596-
# When replying without a command in a thread channel, use the raw content
1597-
# from the sent message as reply text while still preserving attachments.
1598-
await thread.reply(message, message.content, anonymous=anonymous, plain=plain)
1596+
# Check to see if the message starts with the ignore prefix
1597+
if not message.content.startswith(self.config.get("ignore_prefix")):
1598+
# When replying without a command in a thread channel, use the raw content
1599+
# from the sent message as reply text while still preserving attachments.
1600+
await thread.reply(message, message.content, anonymous=anonymous, plain=plain)
1601+
else:
1602+
logger.debug(f"Message {message.id} ignored because it started with the ignore_prefix.")
1603+
await self.api.append_log(message, type_="internal")
1604+
else:
1605+
await self.api.append_log(message, type_="internal")
15991606
elif ctx.invoked_with:
16001607
exc = commands.CommandNotFound(f'Command "{ctx.invoked_with}" is not found')
16011608
self.dispatch("command_error", ctx, exc)

core/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ConfigManager:
3939
"reply_without_command": False,
4040
"anon_reply_without_command": False,
4141
"plain_reply_without_command": False,
42+
"ignore_prefix": "\0",
4243
# logging
4344
"log_channel_id": None,
4445
"mention_channel_id": None,

core/config_help.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@
195195
"See also: `anon_reply_without_command`, `plain_reply_without_command`."
196196
]
197197
},
198+
"ignore_prefix": {
199+
"default": "\\0",
200+
"description": "Messages that start with this prefix will be ignored by Modmail.",
201+
"examples": [
202+
"`{prefix}config set ignore_prefix .`"
203+
],
204+
"notes": [
205+
"`reply_without_command` must be enabled"
206+
]
207+
},
198208
"anon_reply_without_command": {
199209
"default": "Disabled",
200210
"description": "Setting this configuration will make all non-command messages sent in the thread channel to be anonymously forwarded to the recipient without the need of `{prefix}reply`.",

0 commit comments

Comments
 (0)