Skip to content

Commit 2306559

Browse files
committed
v3.9.3 add use_user_id_channel_name
1 parent 20877d9 commit 2306559

File tree

8 files changed

+45
-11
lines changed

8 files changed

+45
-11
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html);
77
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.
88

9+
# v3.9.3
10+
11+
## Added
12+
13+
- 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.
14+
- This is now an option to better suit the needs of servers in Server Discovery
15+
16+
## Internal Change
17+
18+
- Signature of `format_channel_name` in core/util.py changed to:
19+
- `format_channel_name(bot, author, exclude_channel=None, force_null=False)`
20+
21+
922
# v3.9.2
1023

1124
### Improved

bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.9.2"
1+
__version__ = "3.9.3"
22

33

44
import asyncio

cogs/modmail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ async def repair(self, ctx):
14901490
if len(users) == 1:
14911491
user = users.pop()
14921492
name = format_channel_name(
1493-
user, self.bot.modmail_guild, exclude_channel=ctx.channel
1493+
self.bot, user, exclude_channel=ctx.channel
14941494
)
14951495
recipient = self.bot.get_user(user.id)
14961496
if user.id in self.bot.threads.cache:

core/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ConfigManager:
5050
"sent_emoji": "✅",
5151
"blocked_emoji": "🚫",
5252
"close_emoji": "🔒",
53+
"use_user_id_channel_name": False,
5354
"recipient_thread_close": False,
5455
"thread_auto_close_silently": False,
5556
"thread_auto_close": isodate.Duration(),
@@ -157,6 +158,7 @@ class ConfigManager:
157158
time_deltas = {"account_age", "guild_age", "thread_auto_close", "thread_cooldown"}
158159

159160
booleans = {
161+
"use_user_id_channel_name",
160162
"user_typing",
161163
"mod_typing",
162164
"reply_without_command",

core/config_help.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@
9696
"See also: `mod_typing`."
9797
]
9898
},
99+
"use_user_id_channel_name": {
100+
"default": "No",
101+
"description": "When this is set to `yes`, new thread channels will be named with the recipient's ID instead of the recipient's name.",
102+
"examples": [
103+
"`{prefix}config set use_user_id_channel_name yes`",
104+
"`{prefix}config set use_user_id_channel_name no`"
105+
],
106+
"notes": [
107+
"This config is suitable for servers in Server Discovery to comply with channel name restrictions."
108+
]
109+
},
99110
"mod_typing": {
100111
"default": "Disabled",
101112
"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.",

core/thread.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async def setup(self, *, creator=None, category=None, initial_message=None):
120120

121121
try:
122122
channel = await self.bot.modmail_guild.create_text_channel(
123-
name=format_channel_name(recipient, self.bot.modmail_guild),
123+
name=format_channel_name(self.bot, recipient),
124124
category=category,
125125
overwrites=overwrites,
126126
reason="Creating a thread channel.",
@@ -129,7 +129,7 @@ async def setup(self, *, creator=None, category=None, initial_message=None):
129129
# try again but null-discrim (name could be banned)
130130
try:
131131
channel = await self.bot.modmail_guild.create_text_channel(
132-
name=format_channel_name(recipient, self.bot.modmail_guild, force_null=True),
132+
name=format_channel_name(self.bot, recipient, force_null=True),
133133
category=category,
134134
overwrites=overwrites,
135135
reason="Creating a thread channel.",

core/utils.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,23 @@ def escape_code_block(text):
340340
return re.sub(r"```", "`\u200b``", text)
341341

342342

343-
def format_channel_name(author, guild, exclude_channel=None, force_null=False):
343+
def format_channel_name(bot, author, exclude_channel=None, force_null=False):
344344
"""Sanitises a username for use with text channel names"""
345-
name = author.name.lower()
345+
guild = bot.modmail_guild
346+
346347
if force_null:
347-
name = "null"
348+
name = new_name = "null"
349+
else:
350+
if bot.config["use_user_id_channel_name"]:
351+
name = new_name = str(author.id)
352+
else:
353+
name = author.name.lower()
354+
if force_null:
355+
name = "null"
348356

349-
name = new_name = (
350-
"".join(l for l in name if l not in string.punctuation and l.isprintable()) or "null"
351-
) + f"-{author.discriminator}"
357+
name = new_name = (
358+
"".join(l for l in name if l not in string.punctuation and l.isprintable()) or "null"
359+
) + f"-{author.discriminator}"
352360

353361
counter = 1
354362
existed = set(c.name for c in guild.text_channels if c != exclude_channel)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exclude = '''
2121

2222
[tool.poetry]
2323
name = 'Modmail'
24-
version = '3.9.2'
24+
version = '3.9.3'
2525
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."
2626
license = 'AGPL-3.0-only'
2727
authors = [

0 commit comments

Comments
 (0)