Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump python runtime version #3001

Merged
merged 4 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "3.9.2"
__version__ = "3.9.3"


import asyncio
Expand Down
4 changes: 1 addition & 3 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,9 +1489,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
)
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]
Expand Down
14 changes: 8 additions & 6 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ 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,
"thread_auto_close": isodate.Duration(),
Expand Down Expand Up @@ -92,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,
}
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions core/config_help.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
4 changes: 2 additions & 2 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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.",
Expand Down
23 changes: 16 additions & 7 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,24 @@ 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()
if force_null:
name = "null"
guild = bot.modmail_guild

name = new_name = (
"".join(l for l in name if l not in string.punctuation and l.isprintable()) or "null"
) + f"-{author.discriminator}"
if force_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}"

counter = 1
existed = set(c.name for c in guild.text_channels if c != exclude_channel)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.9.0
python-3.9.4