Skip to content

Commit

Permalink
Retry with diff name if channel cant be created resolves #2934
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr committed Jan 14, 2021
1 parent cc17001 commit d00b562
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ 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.2

### Fixed

- Retry with `null-discrim` if channel could not be created. ([GH #2934](https://github.com/kyb3r/modmail/issues/2934))
- Fix update notifications.

# v3.8.1

### Fixed

- Additional image uploads now render properly. ([PR #2933](https://github.com/kyb3r/modmail/pull/2933)))
- Additional image uploads now render properly. ([PR #2933](https://github.com/kyb3r/modmail/pull/2933))
- `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))
- Autotriggers no longer sends attachments back. ([GH #2932](https://github.com/kyb3r/modmail/issues/2932))


# v3.8.0

### Added
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.8.1"
__version__ = "3.8.2"


import asyncio
Expand Down
33 changes: 21 additions & 12 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,27 @@ async def setup(self, *, creator=None, category=None, initial_message=None):
overwrites=overwrites,
reason="Creating a thread channel.",
)
except discord.HTTPException as e: # Failed to create due to missing perms.
logger.critical("An error occurred while creating a thread.", exc_info=True)
self.manager.cache.pop(self.id)

embed = discord.Embed(color=self.bot.error_color)
embed.title = "Error while trying to create a thread."
embed.description = str(e)
embed.add_field(name="Recipient", value=recipient.mention)

if self.bot.log_channel is not None:
await self.bot.log_channel.send(embed=embed)
return
except discord.HTTPException as e:
# 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),
category=category,
overwrites=overwrites,
reason="Creating a thread channel.",
)
except discord.HTTPException as e: # Failed to create due to missing perms.
logger.critical("An error occurred while creating a thread.", exc_info=True)
self.manager.cache.pop(self.id)

embed = discord.Embed(color=self.bot.error_color)
embed.title = "Error while trying to create a thread."
embed.description = str(e)
embed.add_field(name="Recipient", value=recipient.mention)

if self.bot.log_channel is not None:
await self.bot.log_channel.send(embed=embed)
return

self._channel = channel

Expand Down
5 changes: 4 additions & 1 deletion core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,12 @@ def escape_code_block(text):
return re.sub(r"```", "`\u200b``", text)


def format_channel_name(author, guild, exclude_channel=None):
def format_channel_name(author, guild, exclude_channel=None, force_null=False):
"""Sanitises a username for use with text channel names"""
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}"
Expand Down

0 comments on commit d00b562

Please sign in to comment.