Skip to content

Commit c0c8db9

Browse files
DAzViseDAzVise
authored andcommitted
added fallback category
1 parent 1fa212a commit c0c8db9

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
738738
await self.add_reaction(message, blocked_emoji)
739739
return await message.channel.send(embed=embed)
740740

741-
thread = self.threads.create(message.author)
741+
thread = await self.threads.create(message.author)
742742
else:
743743
if self.config["dm_disabled"] == 2:
744744
embed = discord.Embed(

core/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ConfigManager:
2727
"twitch_url": "https://www.twitch.tv/discordmodmail/",
2828
# bot settings
2929
"main_category_id": None,
30+
"fallback_category_id": None,
3031
"prefix": "?",
3132
"mention": "@here",
3233
"main_color": str(discord.Color.blurple()),

core/config_help.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
"If the Modmail category ended up being non-existent/invalid, Modmail will break. To fix this, run `{prefix}setup` again or set `main_category_id` to a valid category."
2121
]
2222
},
23+
"fallback_category_id": {
24+
"default": "`Fallback Modmail` (created when the main category is full)",
25+
"description": "This is the category that will hold the threads when the main category is full.\n\nTo change the Fallback category, you will need to find the [category’s ID](https://support.discordapp.com/hc/en-us/articles/206346498).",
26+
"examples": [
27+
"`{prefix}config set fallback_category_id 9234932582312` (`9234932582312` is the category ID)"
28+
],
29+
"notes": [
30+
"If the Fallback category ended up being non-existent/invalid, Modmail will create a new one. To fix this, set `fallback_category_id` to a valid category."
31+
]
32+
},
2333
"prefix": {
2434
"default": "`?`",
2535
"description": "The prefix of the bot.",

core/thread.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def _find_from_channel(self, channel):
846846
return thread
847847
return None
848848

849-
def create(
849+
async def create(
850850
self,
851851
recipient: typing.Union[discord.Member, discord.User],
852852
*,
@@ -859,11 +859,27 @@ def create(
859859
self.cache[recipient.id] = thread
860860

861861
# Schedule thread setup for later
862+
cat = self.bot.main_category
863+
if len(cat.channels) == 50:
864+
fallback_id = self.bot.config["fallback_category_id"]
865+
fallback = discord.utils.get(cat.guild.categories, id=int(fallback_id))
866+
if fallback and len(fallback.channels) != 50:
867+
self.bot.loop.create_task(thread.setup(creator=creator, category=fallback))
868+
return thread
869+
870+
fallback = await cat.clone(name="Fallback Modmail")
871+
self.bot.config.set("fallback_category_id", fallback.id)
872+
await self.bot.config.update()
873+
self.bot.loop.create_task(thread.setup(creator=creator, category=fallback))
874+
return thread
875+
876+
self.bot.loop.create_task(thread.setup(creator=creator, category=category))
877+
return thread
862878
self.bot.loop.create_task(thread.setup(creator=creator, category=category))
863879
return thread
864880

865881
async def find_or_create(self, recipient) -> Thread:
866-
return await self.find(recipient=recipient) or self.create(recipient)
882+
return await self.find(recipient=recipient) or await self.create(recipient)
867883

868884
def format_channel_name(self, author):
869885
"""Sanitises a username for use with text channel names"""

0 commit comments

Comments
 (0)