Skip to content

Commit

Permalink
Moves the modmail config check to setup (#980)
Browse files Browse the repository at this point in the history
Moves the check if modmail is disabled to the setup function to prevent the modmail bot from trying to load at all
  • Loading branch information
ajax146 authored Apr 30, 2024
1 parent d2f96cc commit 0676dea
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions techsupport_bot/commands/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,13 @@ async def log_closure(

async def setup(bot):
"""Sets the modmail extension up"""

# Only runs if modmail is enabled
if not bot.file_config.modmail_config.enable_modmail:
# Raising an exception makes the extension loading mark as failed, this is surprisingly
# the most reliable way to ensure the modmail bot or code doesn't run
raise AttributeError("Modmail was not loaded because it's disabled")

config = extensionconfig.ExtensionConfig()

config.add(
Expand Down Expand Up @@ -867,12 +874,6 @@ def __init__(self: Self, bot: bot.TechSupportBot):
# Init is used to make variables global so they can be used on the modmail side
super().__init__(bot=bot)

# Only runs if modmail is enabled
if not bot.file_config.modmail_config.enable_modmail:
# Raising an exception makes the extension loading mark as failed, this is surprisingly
# the most reliable way to ensure the modmail bot or code doesn't run
raise AttributeError("Modmail was not loaded because it's disabled")

# Makes the TS client available globally for creating threads and populating them with info
# pylint: disable=W0603
global Ts_client
Expand Down

0 comments on commit 0676dea

Please sign in to comment.