From 4054c510f8694372173ff99eb48cde43c359490a Mon Sep 17 00:00:00 2001 From: Jerrie-Aries <70805800+Jerrie-Aries@users.noreply.github.com> Date: Tue, 2 Feb 2021 21:24:40 +0800 Subject: [PATCH 01/13] Ability to disable mention on thread creation. --- cogs/utility.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cogs/utility.py b/cogs/utility.py index 65b3ef00f5..a89442464a 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -674,20 +674,41 @@ async def ping(self, ctx): @commands.command() @checks.has_permissions(PermissionLevel.ADMINISTRATOR) - async def mention(self, ctx, *mention: Union[discord.Role, discord.Member]): + async def mention(self, ctx, *mention: Union[discord.Role, discord.Member, str]): """ Change what the bot mentions at the start of each thread. Type only `{prefix}mention` to retrieve your current "mention" message. + `{prefix}mention disable` to disable mention. + `{prefix}mention reset` to reset it to default value. """ - # TODO: ability to disable mention. current = self.bot.config["mention"] - if not mention: embed = discord.Embed( title="Current mention:", color=self.bot.main_color, description=str(current) ) + elif ( + len(mention) == 1 + and isinstance(mention[0], str) + and mention[0] in ["disable", "reset"] + ): + option = mention[0] + if option == "disable": + embed = discord.Embed( + description=f"Disabled mention on thread creation.", + color=self.bot.main_color, + ) + self.bot.config["mention"] = None + else: + embed = discord.Embed( + description="`mention` had been reset to default.", color=self.bot.main_color, + ) + self.bot.config.remove("mention") + await self.bot.config.update() else: + for m in mention: + if not isinstance(m, (discord.Role, discord.Member)): + raise commands.BadArgument(f'Role or Member "{m}" not found.') mention = " ".join(i.mention for i in mention) embed = discord.Embed( title="Changed mention!", From 15a38bcfc11958291c24f36d3d9cbde44d032e3d Mon Sep 17 00:00:00 2001 From: Jerrie-Aries <70805800+Jerrie-Aries@users.noreply.github.com> Date: Tue, 2 Feb 2021 22:08:35 +0800 Subject: [PATCH 02/13] Update thread move message in case `mention` was set to disable/None. --- cogs/modmail.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cogs/modmail.py b/cogs/modmail.py index ee109420af..fee8e0b5fe 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -341,7 +341,11 @@ async def move(self, ctx, *, arguments): if self.bot.config["thread_move_notify_mods"]: mention = self.bot.config["mention"] - await thread.channel.send(f"{mention}, thread has been moved.") + if mention is not None: + msg = f"{mention}, thread has been moved." + else: + msg = "Thread has been moved." + await thread.channel.send(msg) sent_emoji, _ = await self.bot.retrieve_emoji() await self.bot.add_reaction(ctx.message, sent_emoji) From 0bfb02e01256f3c0a8b5b4ab872aa6a72e1a95b3 Mon Sep 17 00:00:00 2001 From: Jerrie-Aries <70805800+Jerrie-Aries@users.noreply.github.com> Date: Tue, 2 Feb 2021 22:16:43 +0800 Subject: [PATCH 03/13] Formatting... --- cogs/utility.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cogs/utility.py b/cogs/utility.py index a89442464a..0428f079d9 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -695,8 +695,7 @@ async def mention(self, ctx, *mention: Union[discord.Role, discord.Member, str]) option = mention[0] if option == "disable": embed = discord.Embed( - description=f"Disabled mention on thread creation.", - color=self.bot.main_color, + description=f"Disabled mention on thread creation.", color=self.bot.main_color, ) self.bot.config["mention"] = None else: From 270483fd65898b46433b7e4052476c276f1c590f Mon Sep 17 00:00:00 2001 From: Jerrie-Aries <70805800+Jerrie-Aries@users.noreply.github.com> Date: Wed, 3 Feb 2021 08:26:19 +0800 Subject: [PATCH 04/13] Apply suggestions from code review Co-authored-by: Jia Rong Yee <28086837+fourjr@users.noreply.github.com> --- cogs/utility.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cogs/utility.py b/cogs/utility.py index 0428f079d9..f4c490b846 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -690,9 +690,9 @@ async def mention(self, ctx, *mention: Union[discord.Role, discord.Member, str]) elif ( len(mention) == 1 and isinstance(mention[0], str) - and mention[0] in ["disable", "reset"] + and mention[0].lower() in ["disable", "reset"] ): - option = mention[0] + option = mention[0].lower() if option == "disable": embed = discord.Embed( description=f"Disabled mention on thread creation.", color=self.bot.main_color, @@ -700,7 +700,7 @@ async def mention(self, ctx, *mention: Union[discord.Role, discord.Member, str]) self.bot.config["mention"] = None else: embed = discord.Embed( - description="`mention` had been reset to default.", color=self.bot.main_color, + description="`mention` is reset to default.", color=self.bot.main_color, ) self.bot.config.remove("mention") await self.bot.config.update() From c5a48f0cf9e28131ea36e8307bb35e7ee3bc2e45 Mon Sep 17 00:00:00 2001 From: Jerrie-Aries <70805800+Jerrie-Aries@users.noreply.github.com> Date: Sun, 28 Feb 2021 21:56:08 +0800 Subject: [PATCH 05/13] Fix typo in 'config_help.json' (#2957) --- core/config_help.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/config_help.json b/core/config_help.json index e6bf3730ab..271e726346 100644 --- a/core/config_help.json +++ b/core/config_help.json @@ -706,7 +706,7 @@ "`{prefix}config set confirm_thread_creation yes`" ], "notes": [ - "See also: `confirm_thread_creation_title`, `confirm_thread_response`, `confirm_thread_creation_accept`, `confirm_thread_creation_deny``" + "See also: `confirm_thread_creation_title`, `confirm_thread_response`, `confirm_thread_creation_accept`, `confirm_thread_creation_deny`" ] }, "confirm_thread_creation_title": { From 907b10d466b5df16d6438c6735088c4d65cdf098 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Sun, 7 Mar 2021 22:53:56 +1000 Subject: [PATCH 06/13] Add msglink command to get DM message URLs. --- cogs/modmail.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cogs/modmail.py b/cogs/modmail.py index ee109420af..2392916fea 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -601,6 +601,18 @@ async def sfw(self, ctx): sent_emoji, _ = await self.bot.retrieve_emoji() await self.bot.add_reaction(ctx.message, sent_emoji) + @commands.command() + @checks.has_permissions(PermissionLevel.SUPPORTER) + @checks.thread_only() + async def loglink(self, ctx, message_id: int): + """Retrieves the link to a message in the current thread.""" + message = await ctx.thread.recipient.fetch_message(message_id) + if not message: + embed = discord.Embed(color=self.bot.main_color, description="Message no longer exists.") + else: + embed = discord.Embed(color=self.bot.main_color, description=message.jump_url) + await ctx.send(embed=embed) + @commands.command() @checks.has_permissions(PermissionLevel.SUPPORTER) @checks.thread_only() From 5482bed00fab2da73c1fae694271acd682967dca Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Sun, 7 Mar 2021 22:54:16 +1000 Subject: [PATCH 07/13] Add DM channel ID to genesis message footer. --- core/thread.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/thread.py b/core/thread.py index d534ef352e..98f67ca897 100644 --- a/core/thread.py +++ b/core/thread.py @@ -300,7 +300,11 @@ def _format_info_embed(self, user, log_url, log_count, color): # embed.add_field(name='Mention', value=user.mention) # embed.add_field(name='Registered', value=created + days(created)) - footer = "User ID: " + str(user.id) + if user.dm_channel: + footer = f"User ID: {user.id} • DM ID: {user.dm_channel}" + else: + footer = f"User ID: {user.id}" + embed.set_author(name=str(user), icon_url=user.avatar_url, url=log_url) # embed.set_thumbnail(url=avi) From 784aa4f950b2b6fe9e275860c03fa961ff1abd84 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Sun, 7 Mar 2021 23:07:54 +1000 Subject: [PATCH 08/13] Amend typo and black formatting. --- cogs/modmail.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cogs/modmail.py b/cogs/modmail.py index 2392916fea..d9965243be 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -604,11 +604,13 @@ async def sfw(self, ctx): @commands.command() @checks.has_permissions(PermissionLevel.SUPPORTER) @checks.thread_only() - async def loglink(self, ctx, message_id: int): + async def msglink(self, ctx, message_id: int): """Retrieves the link to a message in the current thread.""" message = await ctx.thread.recipient.fetch_message(message_id) if not message: - embed = discord.Embed(color=self.bot.main_color, description="Message no longer exists.") + embed = discord.Embed( + color=self.bot.main_color, description="Message no longer exists." + ) else: embed = discord.Embed(color=self.bot.main_color, description=message.jump_url) await ctx.send(embed=embed) From e0956c48061ed164af3ae3953589f9cba1e56cb7 Mon Sep 17 00:00:00 2001 From: Jia Rong Yee <28086837+fourjr@users.noreply.github.com> Date: Sun, 7 Mar 2021 23:11:20 +0800 Subject: [PATCH 09/13] Improve messages --- cogs/modmail.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cogs/modmail.py b/cogs/modmail.py index d9965243be..f0ee2815c8 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -606,13 +606,16 @@ async def sfw(self, ctx): @checks.thread_only() async def msglink(self, ctx, message_id: int): """Retrieves the link to a message in the current thread.""" - message = await ctx.thread.recipient.fetch_message(message_id) - if not message: + try: + message = await ctx.thread.recipient.fetch_message(message_id) + except discord.NotFound: embed = discord.Embed( - color=self.bot.main_color, description="Message no longer exists." + color=self.bot.error_color, description="Message not found or no longer exists." ) else: - embed = discord.Embed(color=self.bot.main_color, description=message.jump_url) + embed = discord.Embed( + color=self.bot.main_color, description=message.jump_url + ) await ctx.send(embed=embed) @commands.command() From 9d9a609b1f8a521161bf483eb5a8e7ab7f5594e4 Mon Sep 17 00:00:00 2001 From: Jia Rong Yee <28086837+fourjr@users.noreply.github.com> Date: Sun, 7 Mar 2021 23:14:00 +0800 Subject: [PATCH 10/13] Changelog update --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebf7ecaa3e..da576ec027 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html); however, insignificant breaking changes do not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319). If you're a plugin developer, note the "BREAKING" section. +# v3.8.5 + +This update is a quick hotfix for a weird behaviour experienced on 1 Feb 2021 where users were not properly cached. + +### Added + +- `?msglink `, allows you to obtain channel + message ID for T&S reports. ([GH #2963](https://github.com/kyb3r/modmail/issues/2963), [PR #2964](https://github.com/kyb3r/modmail/pull/2964)) + +### Fixed + +- Non-master/development branch deployments no longer cause erros to be raised. + # v3.8.4 This update is a quick hotfix for a weird behaviour experienced on 1 Feb 2021 where users were not properly cached. From 41d5593d0370bece803628cb79bfd1a54809277d Mon Sep 17 00:00:00 2001 From: Jia Rong Yee <28086837+fourjr@users.noreply.github.com> Date: Sun, 7 Mar 2021 23:14:49 +0800 Subject: [PATCH 11/13] Non-master/development branch deployments no longer cause erros to be raised. --- CHANGELOG.md | 4 +--- core/changelog.py | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da576ec027..83603ac880 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,15 +8,13 @@ however, insignificant breaking changes do not guarantee a major version bump, s # v3.8.5 -This update is a quick hotfix for a weird behaviour experienced on 1 Feb 2021 where users were not properly cached. - ### Added - `?msglink `, allows you to obtain channel + message ID for T&S reports. ([GH #2963](https://github.com/kyb3r/modmail/issues/2963), [PR #2964](https://github.com/kyb3r/modmail/pull/2964)) ### Fixed -- Non-master/development branch deployments no longer cause erros to be raised. +- Non-master/development branch deployments no longer cause errors to be raised. # v3.8.4 diff --git a/core/changelog.py b/core/changelog.py index ada9fe6984..878a19b26c 100644 --- a/core/changelog.py +++ b/core/changelog.py @@ -180,6 +180,9 @@ async def from_url(cls, bot, url: str = "") -> "Changelog": if not branch or err: branch = "master" if not bot.version.is_prerelease else "development" + if branch not in ("master", "development"): + branch = "master" + url = url or f"https://raw.githubusercontent.com/kyb3r/modmail/{branch}/CHANGELOG.md" async with await bot.session.get(url) as resp: From 3c42c22e34ebb5d439a0af36553db027f66b0a24 Mon Sep 17 00:00:00 2001 From: Jia Rong Yee <28086837+fourjr@users.noreply.github.com> Date: Sun, 7 Mar 2021 23:16:12 +0800 Subject: [PATCH 12/13] Update changelog --- CHANGELOG.md | 1 + bot.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83603ac880..0ceeeeedf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s ### Added - `?msglink `, allows you to obtain channel + message ID for T&S reports. ([GH #2963](https://github.com/kyb3r/modmail/issues/2963), [PR #2964](https://github.com/kyb3r/modmail/pull/2964)) +- `?mention disable/reset`, disables or resets mention on thread creation. ([PR #2951](https://github.com/kyb3r/modmail/pull/2951)) ### Fixed diff --git a/bot.py b/bot.py index aa19d7b3d1..bc68584f58 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,4 @@ -__version__ = "3.8.4" +__version__ = "3.8.5" import asyncio From baa7e5fb677e35433586efe0cd63e97d95aa55c4 Mon Sep 17 00:00:00 2001 From: Jia Rong Yee <28086837+fourjr@users.noreply.github.com> Date: Sun, 7 Mar 2021 23:44:25 +0800 Subject: [PATCH 13/13] Fix bug where autotriggers are in dm context, resolve #2961 --- CHANGELOG.md | 1 + bot.py | 3 ++- cogs/modmail.py | 4 +--- cogs/utility.py | 1 - 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ceeeeedf0..0af5009464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s ### Fixed - Non-master/development branch deployments no longer cause errors to be raised. +- Autotriggers now can search for roles/channels in guild context. ([GH #2961](https://github.com/kyb3r/modmail/issues/2961)) # v3.8.4 diff --git a/bot.py b/bot.py index bc68584f58..1b474e40dd 100644 --- a/bot.py +++ b/bot.py @@ -939,6 +939,7 @@ async def get_contexts(self, message, *, cls=commands.Context): async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context): message.author = self.modmail_guild.me message.channel = channel + message.guild = channel.guild view = StringView(message.content) ctx = cls(prefix=self.prefix, view=view, bot=self, message=message) @@ -967,7 +968,7 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context) ctxs = [] aliases = normalize_alias(alias) if not aliases: - logger.warning("Alias %s is invalid as called in automove.", invoker) + logger.warning("Alias %s is invalid as called in autotrigger.", invoker) for alias in aliases: view = StringView(invoked_prefix + alias) diff --git a/cogs/modmail.py b/cogs/modmail.py index 9a659a1934..cbc6e4c2a8 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -617,9 +617,7 @@ async def msglink(self, ctx, message_id: int): color=self.bot.error_color, description="Message not found or no longer exists." ) else: - embed = discord.Embed( - color=self.bot.main_color, description=message.jump_url - ) + embed = discord.Embed(color=self.bot.main_color, description=message.jump_url) await ctx.send(embed=embed) @commands.command() diff --git a/cogs/utility.py b/cogs/utility.py index f4c490b846..8663e70e73 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -1798,7 +1798,6 @@ async def autotrigger_edit(self, ctx, keyword, *, command): split_cmd = command.split(" ") for n in range(1, len(split_cmd) + 1): if self.bot.get_command(" ".join(split_cmd[0:n])): - print(self.bot.get_command(" ".join(split_cmd[0:n]))) valid = True break