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

Fix fallback category error. #3109

Merged
merged 3 commits into from
Nov 19, 2021
Merged
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
17 changes: 10 additions & 7 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@ def get_top_hoisted_role(member: discord.Member):
return role


async def create_thread_channel(bot, recipient, category, overwrites, *, name=None, errors_raised=[]):
async def create_thread_channel(bot, recipient, category, overwrites, *, name=None, errors_raised=None):
name = name or bot.format_channel_name(recipient)
errors_raised = errors_raised or []

try:
channel = await bot.modmail_guild.create_text_channel(
name=name,
Expand All @@ -393,19 +395,20 @@ async def create_thread_channel(bot, recipient, category, overwrites, *, name=No
errors_raised.append((e.text, (category, name)))

if "Maximum number of channels in category reached" in e.text:
fallback = None
fallback_id = bot.config["fallback_category_id"]
if fallback_id:
fallback = discord.utils.get(category.guild.categories, id=int(fallback_id))
if fallback and len(fallback.channels) < 49:
category = fallback
if fallback and len(fallback.channels) >= 49:
fallback = None

if not category:
category = await category.clone(name="Fallback Modmail")
bot.config.set("fallback_category_id", str(category.id))
if not fallback:
fallback = await category.clone(name="Fallback Modmail")
bot.config.set("fallback_category_id", str(fallback.id))
await bot.config.update()

return await create_thread_channel(
bot, recipient, category, overwrites, errors_raised=errors_raised
bot, recipient, fallback, overwrites, errors_raised=errors_raised
)

if "Contains words not allowed" in e.text:
Expand Down