From 23065593c2b03a4eb300411b90eb04ab1266871f Mon Sep 17 00:00:00 2001 From: Taku <45324516+Taaku18@users.noreply.github.com> Date: Thu, 8 Apr 2021 21:51:22 +0800 Subject: [PATCH 1/4] v3.9.3 add use_user_id_channel_name --- CHANGELOG.md | 13 +++++++++++++ bot.py | 2 +- cogs/modmail.py | 2 +- core/config.py | 2 ++ core/config_help.json | 11 +++++++++++ core/thread.py | 4 ++-- core/utils.py | 20 ++++++++++++++------ pyproject.toml | 2 +- 8 files changed, 45 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d2ea15f89..df4c140165 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,19 @@ 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.9.3 + +## Added + +- New config: ` use_user_id_channel_name`, when set to TRUE, channel names would get created with the recipient's ID instead of their name and discriminator. + - This is now an option to better suit the needs of servers in Server Discovery + +## Internal Change + +- Signature of `format_channel_name` in core/util.py changed to: + - `format_channel_name(bot, author, exclude_channel=None, force_null=False)` + + # v3.9.2 ### Improved diff --git a/bot.py b/bot.py index d4ef7f250c..994e956e11 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,4 @@ -__version__ = "3.9.2" +__version__ = "3.9.3" import asyncio diff --git a/cogs/modmail.py b/cogs/modmail.py index bd89571193..b5d48d61c2 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -1490,7 +1490,7 @@ async def repair(self, ctx): if len(users) == 1: user = users.pop() name = format_channel_name( - user, self.bot.modmail_guild, exclude_channel=ctx.channel + self.bot, user, exclude_channel=ctx.channel ) recipient = self.bot.get_user(user.id) if user.id in self.bot.threads.cache: diff --git a/core/config.py b/core/config.py index 14197e112e..890b3690f1 100644 --- a/core/config.py +++ b/core/config.py @@ -50,6 +50,7 @@ class ConfigManager: "sent_emoji": "βœ…", "blocked_emoji": "🚫", "close_emoji": "πŸ”’", + "use_user_id_channel_name": False, "recipient_thread_close": False, "thread_auto_close_silently": False, "thread_auto_close": isodate.Duration(), @@ -157,6 +158,7 @@ class ConfigManager: time_deltas = {"account_age", "guild_age", "thread_auto_close", "thread_cooldown"} booleans = { + "use_user_id_channel_name", "user_typing", "mod_typing", "reply_without_command", diff --git a/core/config_help.json b/core/config_help.json index e764c9255d..2aef03ccf6 100644 --- a/core/config_help.json +++ b/core/config_help.json @@ -96,6 +96,17 @@ "See also: `mod_typing`." ] }, + "use_user_id_channel_name": { + "default": "No", + "description": "When this is set to `yes`, new thread channels will be named with the recipient's ID instead of the recipient's name.", + "examples": [ + "`{prefix}config set use_user_id_channel_name yes`", + "`{prefix}config set use_user_id_channel_name no`" + ], + "notes": [ + "This config is suitable for servers in Server Discovery to comply with channel name restrictions." + ] + }, "mod_typing": { "default": "Disabled", "description": "When this is set to `yes`, whenever a moderator starts to type in the thread channel, the recipient user will see \"{bot.user.display_name} is typing…\" in their DM channel.", diff --git a/core/thread.py b/core/thread.py index 9fe23301e4..7798454958 100644 --- a/core/thread.py +++ b/core/thread.py @@ -120,7 +120,7 @@ async def setup(self, *, creator=None, category=None, initial_message=None): try: channel = await self.bot.modmail_guild.create_text_channel( - name=format_channel_name(recipient, self.bot.modmail_guild), + name=format_channel_name(self.bot, recipient), category=category, overwrites=overwrites, reason="Creating a thread channel.", @@ -129,7 +129,7 @@ async def setup(self, *, creator=None, category=None, initial_message=None): # try again but null-discrim (name could be banned) try: channel = await self.bot.modmail_guild.create_text_channel( - name=format_channel_name(recipient, self.bot.modmail_guild, force_null=True), + name=format_channel_name(self.bot, recipient, force_null=True), category=category, overwrites=overwrites, reason="Creating a thread channel.", diff --git a/core/utils.py b/core/utils.py index 8f4b152ff5..af47c8e2e6 100644 --- a/core/utils.py +++ b/core/utils.py @@ -340,15 +340,23 @@ def escape_code_block(text): return re.sub(r"```", "`\u200b``", text) -def format_channel_name(author, guild, exclude_channel=None, force_null=False): +def format_channel_name(bot, author, exclude_channel=None, force_null=False): """Sanitises a username for use with text channel names""" - name = author.name.lower() + guild = bot.modmail_guild + if force_null: - name = "null" + name = new_name = "null" + else: + if bot.config["use_user_id_channel_name"]: + name = new_name = str(author.id) + else: + name = author.name.lower() + if force_null: + name = "null" - name = new_name = ( - "".join(l for l in name if l not in string.punctuation and l.isprintable()) or "null" - ) + f"-{author.discriminator}" + name = new_name = ( + "".join(l for l in name if l not in string.punctuation and l.isprintable()) or "null" + ) + f"-{author.discriminator}" counter = 1 existed = set(c.name for c in guild.text_channels if c != exclude_channel) diff --git a/pyproject.toml b/pyproject.toml index 3e4865bc8c..b74dfad111 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ exclude = ''' [tool.poetry] name = 'Modmail' -version = '3.9.2' +version = '3.9.3' description = "Modmail is similar to Reddit's Modmail, both in functionality and purpose. It serves as a shared inbox for server staff to communicate with their users in a seamless way." license = 'AGPL-3.0-only' authors = [ From a0e580ccb5db20002bdc8c5d99b506d18d8bf3e2 Mon Sep 17 00:00:00 2001 From: Taku <45324516+Taaku18@users.noreply.github.com> Date: Thu, 8 Apr 2021 22:25:18 +0800 Subject: [PATCH 2/4] black --- cogs/modmail.py | 4 +--- core/utils.py | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cogs/modmail.py b/cogs/modmail.py index b5d48d61c2..a45da27166 100644 --- a/cogs/modmail.py +++ b/cogs/modmail.py @@ -1489,9 +1489,7 @@ async def repair(self, ctx): ) if len(users) == 1: user = users.pop() - name = format_channel_name( - self.bot, user, exclude_channel=ctx.channel - ) + name = format_channel_name(self.bot, user, exclude_channel=ctx.channel) recipient = self.bot.get_user(user.id) if user.id in self.bot.threads.cache: thread = self.bot.threads.cache[user.id] diff --git a/core/utils.py b/core/utils.py index af47c8e2e6..2dfb319a8e 100644 --- a/core/utils.py +++ b/core/utils.py @@ -355,7 +355,8 @@ def format_channel_name(bot, author, exclude_channel=None, force_null=False): name = "null" name = new_name = ( - "".join(l for l in name if l not in string.punctuation and l.isprintable()) or "null" + "".join(l for l in name if l not in string.punctuation and l.isprintable()) + or "null" ) + f"-{author.discriminator}" counter = 1 From 3e4d9b019ce748eac1fb8db2aefec5f51c33c755 Mon Sep 17 00:00:00 2001 From: Taku <45324516+Taaku18@users.noreply.github.com> Date: Mon, 12 Apr 2021 14:56:43 +0800 Subject: [PATCH 3/4] Possibly fix emoji problem --- core/config.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/config.py b/core/config.py index 890b3690f1..30f364622d 100644 --- a/core/config.py +++ b/core/config.py @@ -47,9 +47,9 @@ class ConfigManager: # updates "update_notifications": True, # threads - "sent_emoji": "βœ…", - "blocked_emoji": "🚫", - "close_emoji": "πŸ”’", + "sent_emoji": "\N{WHITE HEAVY CHECK MARK}", + "blocked_emoji": "\N{NO ENTRY SIGN}", + "close_emoji": "\N{LOCK}", "use_user_id_channel_name": False, "recipient_thread_close": False, "thread_auto_close_silently": False, @@ -93,13 +93,13 @@ class ConfigManager: "anon_tag": "Response", # react to contact "react_to_contact_message": None, - "react_to_contact_emoji": "\u2705", + "react_to_contact_emoji": "\N{WHITE HEAVY CHECK MARK}", # confirm thread creation "confirm_thread_creation": False, "confirm_thread_creation_title": "Confirm thread creation", "confirm_thread_response": "React to confirm thread creation which will directly contact the moderators", - "confirm_thread_creation_accept": "\u2705", - "confirm_thread_creation_deny": "\U0001F6AB", + "confirm_thread_creation_accept": "\N{WHITE HEAVY CHECK MARK}", + "confirm_thread_creation_deny": "\N{NO ENTRY SIGN}", # regex "use_regex_autotrigger": False, } From c74e5f4ccbf0695b545e5d362897230b24472002 Mon Sep 17 00:00:00 2001 From: codeinteger6 <44692189+codeinteger6@users.noreply.github.com> Date: Wed, 14 Apr 2021 13:25:19 +0600 Subject: [PATCH 4/4] Bump python runtime version Security update --- runtime.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime.txt b/runtime.txt index 67068f10fe..87665291b8 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.9.0 \ No newline at end of file +python-3.9.4