Skip to content

Commit d00b562

Browse files
committed
Retry with diff name if channel cant be created resolves #2934
1 parent cc17001 commit d00b562

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@ 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.8.2
10+
11+
### Fixed
12+
13+
- Retry with `null-discrim` if channel could not be created. ([GH #2934](https://github.com/kyb3r/modmail/issues/2934))
14+
- Fix update notifications.
15+
916
# v3.8.1
1017

1118
### Fixed
1219

13-
- Additional image uploads now render properly. ([PR #2933](https://github.com/kyb3r/modmail/pull/2933)))
20+
- Additional image uploads now render properly. ([PR #2933](https://github.com/kyb3r/modmail/pull/2933))
1421
- `confirm_thread_creation` no longer raises unnecessary errors. ([GH #2931](https://github.com/kyb3r/modmail/issues/2931), [PR #2933](https://github.com/kyb3r/modmail/pull/2933))
1522
- Autotriggers no longer sends attachments back. ([GH #2932](https://github.com/kyb3r/modmail/issues/2932))
1623

17-
1824
# v3.8.0
1925

2026
### Added

bot.py

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

33

44
import asyncio

core/thread.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,27 @@ async def setup(self, *, creator=None, category=None, initial_message=None):
125125
overwrites=overwrites,
126126
reason="Creating a thread channel.",
127127
)
128-
except discord.HTTPException as e: # Failed to create due to missing perms.
129-
logger.critical("An error occurred while creating a thread.", exc_info=True)
130-
self.manager.cache.pop(self.id)
131-
132-
embed = discord.Embed(color=self.bot.error_color)
133-
embed.title = "Error while trying to create a thread."
134-
embed.description = str(e)
135-
embed.add_field(name="Recipient", value=recipient.mention)
136-
137-
if self.bot.log_channel is not None:
138-
await self.bot.log_channel.send(embed=embed)
139-
return
128+
except discord.HTTPException as e:
129+
# try again but null-discrim (name could be banned)
130+
try:
131+
channel = await self.bot.modmail_guild.create_text_channel(
132+
name=format_channel_name(recipient, self.bot.modmail_guild, force_null=True),
133+
category=category,
134+
overwrites=overwrites,
135+
reason="Creating a thread channel.",
136+
)
137+
except discord.HTTPException as e: # Failed to create due to missing perms.
138+
logger.critical("An error occurred while creating a thread.", exc_info=True)
139+
self.manager.cache.pop(self.id)
140+
141+
embed = discord.Embed(color=self.bot.error_color)
142+
embed.title = "Error while trying to create a thread."
143+
embed.description = str(e)
144+
embed.add_field(name="Recipient", value=recipient.mention)
145+
146+
if self.bot.log_channel is not None:
147+
await self.bot.log_channel.send(embed=embed)
148+
return
140149

141150
self._channel = channel
142151

core/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,12 @@ def escape_code_block(text):
339339
return re.sub(r"```", "`\u200b``", text)
340340

341341

342-
def format_channel_name(author, guild, exclude_channel=None):
342+
def format_channel_name(author, guild, exclude_channel=None, force_null=False):
343343
"""Sanitises a username for use with text channel names"""
344344
name = author.name.lower()
345+
if force_null:
346+
name = "null"
347+
345348
name = new_name = (
346349
"".join(l for l in name if l not in string.punctuation and l.isprintable()) or "null"
347350
) + f"-{author.discriminator}"

0 commit comments

Comments
 (0)