From e6d682bf49e95b63f67e7c8d5cd9161ddfe06642 Mon Sep 17 00:00:00 2001 From: Cyrus <54488650+RealCyGuy@users.noreply.github.com> Date: Sat, 5 Jun 2021 22:03:28 -0700 Subject: [PATCH 01/11] Update registry.json --- plugins/registry.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/registry.json b/plugins/registry.json index a9f565a013..36b106bbc8 100644 --- a/plugins/registry.json +++ b/plugins/registry.json @@ -154,7 +154,7 @@ "suggest": { "repository": "realcyguy/modmail-plugins", "branch": "master", - "description": "Send suggestions to a selected server! It even has moderation...", + "description": "Send suggestions to a selected server! It has accepting, denying, and moderation-ing.", "bot_version": "3.4.1", "title": "Suggest stuff.", "icon_url": "https://i.imgur.com/qtE7AH8.png", From d50ec339ca56f2eb0d3809bc525a66e1740b1fef Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Mon, 2 Aug 2021 09:51:36 +0200 Subject: [PATCH 02/11] Plugins: add Python Discord's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - **Case insensitive snippets**: Allow snippets to be ran even if with the wrong case. For example, `?Dm-RePort` will be recognized as `?dm-report`. - **Close message:** Add a `?closemessage` command that will close the thread after 15 minutes with a default message. - **MDLink**: Generate a ready to paste link to the thread logs. - **Reply cooldown**: Forbid you from sending the same message twice in ten seconds. - **Tagging**: Add a `?tag` command capable of adding a `$message|` header to the channel name. --- plugins/registry.json | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/plugins/registry.json b/plugins/registry.json index a9f565a013..0ba98f499c 100644 --- a/plugins/registry.json +++ b/plugins/registry.json @@ -1,4 +1,49 @@ { + "case_insensitive_snippets": { + "repository": "python-discord/modmail-plugins", + "branch": "main", + "description": "Allow snippets to be ran even if with the wrong case. For example, ?Dm-RePort will be recognized as ?dm-report.", + "bot_version": "2.20.1", + "title": "Case insensitive snippets", + "icon_url": "https://i.imgur.com/kaJYlMB.png", + "thumbnail_url": "https://i.imgur.com/kaJYlMB.png" + }, + "close_message": { + "repository": "python-discord/modmail-plugins", + "branch": "main", + "description": "Add a ?closemessage command that will close the thread after 15 minutes with a default message.", + "bot_version": "2.20.1", + "title": "Close message", + "icon_url": "https://i.imgur.com/ev7BFMz.png", + "thumbnail_url": "https://i.imgur.com/ev7BFMz.png" + }, + "mdlink": { + "repository": "python-discord/modmail-plugins", + "branch": "main", + "description": "Generate a ready to paste link to the thread logs.", + "bot_version": "2.20.1", + "title": "MDLink", + "icon_url": "https://i.imgur.com/JA2E63R.png", + "thumbnail_url": "https://i.imgur.com/JA2E63R.png" + }, + "reply_cooldown": { + "repository": "python-discord/modmail-plugins", + "branch": "main", + "description": "Forbid you from sending the same message twice in ten seconds.", + "bot_version": "2.20.1", + "title": "Reply cooldown", + "icon_url": "https://i.imgur.com/FtRQveT.png", + "thumbnail_url": "https://i.imgur.com/FtRQveT.png" + }, + "tagging": { + "repository": "python-discord/modmail-plugins", + "branch": "main", + "description": "Add a ?tag command capable of adding a $message| header to the channel name.", + "bot_version": "2.20.1", + "title": "Tagging", + "icon_url": "https://i.imgur.com/WajSLB1.png", + "thumbnail_url": "https://i.imgur.com/WajSLB1.png" + }, "dragory-migrate": { "repository": "kyb3r/modmail-plugins", "branch": "master", From 835390b80c8f4a36bd19aa77d19370b899f5c8b6 Mon Sep 17 00:00:00 2001 From: Yee Jia Rong <28086837+fourjr@users.noreply.github.com> Date: Fri, 6 Aug 2021 21:53:04 +0800 Subject: [PATCH 03/11] Remove tagging and case insensitive plugins --- plugins/registry.json | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/plugins/registry.json b/plugins/registry.json index 0ba98f499c..a805360b57 100644 --- a/plugins/registry.json +++ b/plugins/registry.json @@ -1,13 +1,4 @@ { - "case_insensitive_snippets": { - "repository": "python-discord/modmail-plugins", - "branch": "main", - "description": "Allow snippets to be ran even if with the wrong case. For example, ?Dm-RePort will be recognized as ?dm-report.", - "bot_version": "2.20.1", - "title": "Case insensitive snippets", - "icon_url": "https://i.imgur.com/kaJYlMB.png", - "thumbnail_url": "https://i.imgur.com/kaJYlMB.png" - }, "close_message": { "repository": "python-discord/modmail-plugins", "branch": "main", @@ -35,15 +26,6 @@ "icon_url": "https://i.imgur.com/FtRQveT.png", "thumbnail_url": "https://i.imgur.com/FtRQveT.png" }, - "tagging": { - "repository": "python-discord/modmail-plugins", - "branch": "main", - "description": "Add a ?tag command capable of adding a $message| header to the channel name.", - "bot_version": "2.20.1", - "title": "Tagging", - "icon_url": "https://i.imgur.com/WajSLB1.png", - "thumbnail_url": "https://i.imgur.com/WajSLB1.png" - }, "dragory-migrate": { "repository": "kyb3r/modmail-plugins", "branch": "master", From 55b311f294bb7570d2b5ae5b77eccea4e0518cd6 Mon Sep 17 00:00:00 2001 From: popeeyy <29686338+popeeyy@users.noreply.github.com> Date: Sat, 7 Aug 2021 19:44:29 -0700 Subject: [PATCH 04/11] Initial commit --- bot.py | 28 +++++++++++++++++++++++++--- cogs/modmail.py | 3 +++ cogs/utility.py | 18 ++++++++++++++++++ core/thread.py | 1 + 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index 1c4fdd5354..12e28c8571 100644 --- a/bot.py +++ b/bot.py @@ -1010,6 +1010,7 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) if trigger: invoker = trigger.lower() + print("looking for auto trigger", trigger, self.auto_triggers[trigger]) alias = self.auto_triggers[trigger] ctxs = [] @@ -1019,24 +1020,45 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) if not aliases: logger.warning("Alias %s is invalid as called in autotrigger.", invoker) + print("Aliases", aliases) + for alias in aliases: view = StringView(invoked_prefix + alias) + invoked_with = view.get_word().lower() + invoked_with = invoked_with[1:] + print("Looking for", invoked_with) + found_command = self.all_commands.get(invoked_with) + + # Check for alias + if not found_command: + print("INVOKED WITH", invoked_with) + command_alias = self.aliases.get(invoked_with)[1:-1] + view = StringView(invoked_prefix + command_alias) + split_cmd = command_alias.split(" ") + found_command = self.all_commands.get(split_cmd[0]) + ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message) + ctx_.command = found_command + ctx_.invoked_with = invoked_with ctx_.thread = thread discord.utils.find(view.skip_string, await self.get_prefix()) - ctx_.invoked_with = view.get_word().lower() - ctx_.command = self.all_commands.get(ctx_.invoked_with) + + print("Command info:", view, ctx_, ctx_.thread, ctx_.invoked_with, ctx_.command) ctxs += [ctx_] for ctx in ctxs: if ctx.command: + print("Found command") old_checks = copy.copy(ctx.command.checks) + print("Old checks set") ctx.command.checks = [checks.has_permissions(PermissionLevel.INVALID)] - + print("Command checks added, invoking...", ctx) await self.invoke(ctx) ctx.command.checks = old_checks continue + else: + print("unable to find command") async def get_context(self, message, *, cls=commands.Context): """ diff --git a/cogs/modmail.py b/cogs/modmail.py index 0e41b76677..35e80bdf9b 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -818,7 +818,10 @@ async def reply(self, ctx, *, msg: str = ""): Supports attachments and images as well as automatically embedding image URLs. """ + ctx.message.content = msg + print("MSG IS", msg) + print("Sending", ctx.message, msg) async with ctx.typing(): await ctx.thread.reply(ctx.message) diff --git a/cogs/utility.py b/cogs/utility.py index 759b573748..d068b6cc1e 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -1750,6 +1750,16 @@ async def autotrigger_add(self, ctx, keyword, *, command): print(self.bot.get_command(" ".join(split_cmd[0:n]))) valid = True break + + print("Split command", split_cmd, "Range", range(1, len(split_cmd) + 1), self.bot.aliases) + + if not valid and self.bot.aliases: + for n in range(1, len(split_cmd) + 1): + print(" ".join(split_cmd[0:n]), self.bot.aliases.get(" ".join(split_cmd[0:n]))) + if self.bot.aliases.get(" ".join(split_cmd[0:n])): + print(self.bot.aliases.get(" ".join(split_cmd[0:n]))) + valid = True + break if valid: self.bot.auto_triggers[keyword] = command @@ -1784,6 +1794,14 @@ async def autotrigger_edit(self, ctx, keyword, *, command): valid = True break + if not valid and self.bot.aliases: + for n in range(1, len(split_cmd) + 1): + print(" ".join(split_cmd[0:n]), self.bot.aliases.get(" ".join(split_cmd[0:n]))) + if self.bot.aliases.get(" ".join(split_cmd[0:n])): + print(self.bot.aliases.get(" ".join(split_cmd[0:n]))) + valid = True + break + if valid: self.bot.auto_triggers[keyword] = command await self.bot.config.update() diff --git a/core/thread.py b/core/thread.py index 41d2cd96ba..a494891965 100644 --- a/core/thread.py +++ b/core/thread.py @@ -241,6 +241,7 @@ class Author: async def activate_auto_triggers(): if initial_message: message = DummyMessage(copy.copy(initial_message)) + try: return await self.bot.trigger_auto_triggers(message, channel) except RuntimeError: From 115ccfadb797d876b8d7cbba91f311576695365a Mon Sep 17 00:00:00 2001 From: popeeyy <29686338+popeeyy@users.noreply.github.com> Date: Sat, 7 Aug 2021 20:17:11 -0700 Subject: [PATCH 05/11] Bug fixes and debug removal --- bot.py | 22 +++++++--------------- cogs/modmail.py | 5 ++--- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/bot.py b/bot.py index 12e28c8571..8c9d20dd87 100644 --- a/bot.py +++ b/bot.py @@ -1010,7 +1010,6 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) if trigger: invoker = trigger.lower() - print("looking for auto trigger", trigger, self.auto_triggers[trigger]) alias = self.auto_triggers[trigger] ctxs = [] @@ -1020,39 +1019,32 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) if not aliases: logger.warning("Alias %s is invalid as called in autotrigger.", invoker) - print("Aliases", aliases) - for alias in aliases: + print("Initial view", invoked_prefix + alias) view = StringView(invoked_prefix + alias) - invoked_with = view.get_word().lower() - invoked_with = invoked_with[1:] - print("Looking for", invoked_with) + invoked_with = view.get_word().lower()[1:] found_command = self.all_commands.get(invoked_with) # Check for alias if not found_command: - print("INVOKED WITH", invoked_with) - command_alias = self.aliases.get(invoked_with)[1:-1] - view = StringView(invoked_prefix + command_alias) - split_cmd = command_alias.split(" ") - found_command = self.all_commands.get(split_cmd[0]) + invoked_with = self.aliases.get(invoked_with)[1:-1] # Get command linked to alias + view = StringView(invoked_prefix + invoked_with) # Create StringView for new command + invoked_with = view.get_word().lower()[1:] # Parse the new command + found_command = self.all_commands.get(invoked_with) # Get the command function ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message) ctx_.command = found_command + ctx_.invoked_with = invoked_with ctx_.thread = thread discord.utils.find(view.skip_string, await self.get_prefix()) - print("Command info:", view, ctx_, ctx_.thread, ctx_.invoked_with, ctx_.command) ctxs += [ctx_] for ctx in ctxs: if ctx.command: - print("Found command") old_checks = copy.copy(ctx.command.checks) - print("Old checks set") ctx.command.checks = [checks.has_permissions(PermissionLevel.INVALID)] - print("Command checks added, invoking...", ctx) await self.invoke(ctx) ctx.command.checks = old_checks diff --git a/cogs/modmail.py b/cogs/modmail.py index 35e80bdf9b..66d2f675da 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -818,10 +818,9 @@ async def reply(self, ctx, *, msg: str = ""): Supports attachments and images as well as automatically embedding image URLs. """ - + print("MSG IS", msg, ctx.message.content) ctx.message.content = msg - print("MSG IS", msg) - print("Sending", ctx.message, msg) + async with ctx.typing(): await ctx.thread.reply(ctx.message) From a24cae3dd6c0a0b6a88e2bdb405374458d8e12d3 Mon Sep 17 00:00:00 2001 From: popeeyy <29686338+popeeyy@users.noreply.github.com> Date: Sat, 7 Aug 2021 20:18:22 -0700 Subject: [PATCH 06/11] Remove debug --- bot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot.py b/bot.py index 8c9d20dd87..20b8483128 100644 --- a/bot.py +++ b/bot.py @@ -1020,7 +1020,6 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) logger.warning("Alias %s is invalid as called in autotrigger.", invoker) for alias in aliases: - print("Initial view", invoked_prefix + alias) view = StringView(invoked_prefix + alias) invoked_with = view.get_word().lower()[1:] found_command = self.all_commands.get(invoked_with) From 4c0d8717192da6d57dbb13bfc8e4890849e6ef24 Mon Sep 17 00:00:00 2001 From: popeeyy <29686338+popeeyy@users.noreply.github.com> Date: Sat, 7 Aug 2021 20:20:27 -0700 Subject: [PATCH 07/11] Remove additional debug --- bot.py | 2 -- cogs/modmail.py | 2 +- cogs/utility.py | 3 --- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/bot.py b/bot.py index 20b8483128..a9b463fb0d 100644 --- a/bot.py +++ b/bot.py @@ -1048,8 +1048,6 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) ctx.command.checks = old_checks continue - else: - print("unable to find command") async def get_context(self, message, *, cls=commands.Context): """ diff --git a/cogs/modmail.py b/cogs/modmail.py index 66d2f675da..efbb90c0b1 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -818,7 +818,7 @@ async def reply(self, ctx, *, msg: str = ""): Supports attachments and images as well as automatically embedding image URLs. """ - print("MSG IS", msg, ctx.message.content) + ctx.message.content = msg async with ctx.typing(): diff --git a/cogs/utility.py b/cogs/utility.py index d068b6cc1e..3c3318cb6d 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -1750,12 +1750,9 @@ async def autotrigger_add(self, ctx, keyword, *, command): print(self.bot.get_command(" ".join(split_cmd[0:n]))) valid = True break - - print("Split command", split_cmd, "Range", range(1, len(split_cmd) + 1), self.bot.aliases) if not valid and self.bot.aliases: for n in range(1, len(split_cmd) + 1): - print(" ".join(split_cmd[0:n]), self.bot.aliases.get(" ".join(split_cmd[0:n]))) if self.bot.aliases.get(" ".join(split_cmd[0:n])): print(self.bot.aliases.get(" ".join(split_cmd[0:n]))) valid = True From ed0631c07cb3b551c5b2862de9a68b65afd56a44 Mon Sep 17 00:00:00 2001 From: popeeyy <29686338+popeeyy@users.noreply.github.com> Date: Sat, 7 Aug 2021 20:21:40 -0700 Subject: [PATCH 08/11] Update bot.py --- bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot.py b/bot.py index a9b463fb0d..01e9503c46 100644 --- a/bot.py +++ b/bot.py @@ -1044,6 +1044,7 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) if ctx.command: old_checks = copy.copy(ctx.command.checks) ctx.command.checks = [checks.has_permissions(PermissionLevel.INVALID)] + await self.invoke(ctx) ctx.command.checks = old_checks From 25cba86522b261ac6be406728313e31a416adb85 Mon Sep 17 00:00:00 2001 From: popeeyy <29686338+popeeyy@users.noreply.github.com> Date: Sat, 7 Aug 2021 20:24:16 -0700 Subject: [PATCH 09/11] Edit error message --- cogs/utility.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/utility.py b/cogs/utility.py index 3c3318cb6d..59e5d507dd 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -1771,7 +1771,7 @@ async def autotrigger_add(self, ctx, keyword, *, command): embed = discord.Embed( title="Error", color=self.bot.error_color, - description="Invalid command. Note that autotriggers do not work with aliases.", + description="Invalid command. Please provide a valid command or alias.", ) await ctx.send(embed=embed) @@ -1812,7 +1812,7 @@ async def autotrigger_edit(self, ctx, keyword, *, command): embed = discord.Embed( title="Error", color=self.bot.error_color, - description="Invalid command. Note that autotriggers do not work with aliases.", + description="Invalid command. Please provide a valid command or alias.", ) await ctx.send(embed=embed) From cc890c4b5fb1b642c34874a9c8cb4c37c12325f4 Mon Sep 17 00:00:00 2001 From: Yee Jia Rong <28086837+fourjr@users.noreply.github.com> Date: Sun, 8 Aug 2021 15:28:02 +0800 Subject: [PATCH 10/11] Formatting --- bot.py | 12 ++++++------ cogs/modmail.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index 01e9503c46..e066bc068a 100644 --- a/bot.py +++ b/bot.py @@ -1026,14 +1026,14 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) # Check for alias if not found_command: - invoked_with = self.aliases.get(invoked_with)[1:-1] # Get command linked to alias - view = StringView(invoked_prefix + invoked_with) # Create StringView for new command - invoked_with = view.get_word().lower()[1:] # Parse the new command - found_command = self.all_commands.get(invoked_with) # Get the command function + invoked_with = self.aliases.get(invoked_with)[1:-1] # Get command linked to alias + view = StringView(invoked_prefix + invoked_with) # Create StringView for new command + invoked_with = view.get_word().lower()[1:] # Parse the new command + found_command = self.all_commands.get(invoked_with) # Get the command function ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message) ctx_.command = found_command - + ctx_.invoked_with = invoked_with ctx_.thread = thread discord.utils.find(view.skip_string, await self.get_prefix()) @@ -1044,7 +1044,7 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) if ctx.command: old_checks = copy.copy(ctx.command.checks) ctx.command.checks = [checks.has_permissions(PermissionLevel.INVALID)] - + await self.invoke(ctx) ctx.command.checks = old_checks diff --git a/cogs/modmail.py b/cogs/modmail.py index efbb90c0b1..367c30f3c8 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -820,7 +820,7 @@ async def reply(self, ctx, *, msg: str = ""): """ ctx.message.content = msg - + async with ctx.typing(): await ctx.thread.reply(ctx.message) From 736863b49f981992f2e9f13add9552231f0d8c9b Mon Sep 17 00:00:00 2001 From: popeeyy <29686338+popeeyy@users.noreply.github.com> Date: Sun, 8 Aug 2021 19:39:57 -0700 Subject: [PATCH 11/11] Redo alias conversion --- bot.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/bot.py b/bot.py index e066bc068a..e5008d51d1 100644 --- a/bot.py +++ b/bot.py @@ -1013,32 +1013,20 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) alias = self.auto_triggers[trigger] ctxs = [] + if alias is not None: ctxs = [] aliases = normalize_alias(alias) if not aliases: logger.warning("Alias %s is invalid as called in autotrigger.", invoker) - for alias in aliases: - view = StringView(invoked_prefix + alias) - invoked_with = view.get_word().lower()[1:] - found_command = self.all_commands.get(invoked_with) - - # Check for alias - if not found_command: - invoked_with = self.aliases.get(invoked_with)[1:-1] # Get command linked to alias - view = StringView(invoked_prefix + invoked_with) # Create StringView for new command - invoked_with = view.get_word().lower()[1:] # Parse the new command - found_command = self.all_commands.get(invoked_with) # Get the command function + message.author = thread.recipient # Allow for get_contexts to work - ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message) - ctx_.command = found_command - - ctx_.invoked_with = invoked_with - ctx_.thread = thread - discord.utils.find(view.skip_string, await self.get_prefix()) + for alias in aliases: + message.content = invoked_prefix + alias + ctxs += await self.get_contexts(message) - ctxs += [ctx_] + message.author = self.modmail_guild.me # Fix message so commands execute properly for ctx in ctxs: if ctx.command: