Skip to content

Commit ec45e0c

Browse files
move error messages
1 parent 30e7251 commit ec45e0c

1 file changed

Lines changed: 18 additions & 23 deletions

File tree

config.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,28 +157,22 @@ def _setup_logging() -> None:
157157

158158
@classmethod
159159
def _setup_discord_bot_token(cls) -> None:
160-
INVALID_DISCORD_BOT_TOKEN_MESSAGE: Final[str] = (
161-
"DISCORD_BOT_TOKEN must be set to a valid Discord bot token " # noqa: S105
162-
"(see https://discord.com/developers/docs/topics/oauth2#bot-vs-user-accounts)."
163-
)
164-
165160
raw_discord_bot_token: str = os.getenv("DISCORD_BOT_TOKEN", default="").strip()
166161

167162
if not raw_discord_bot_token or not re.fullmatch(
168163
r"\A([A-Za-z0-9_-]{24,26})\.([A-Za-z0-9_-]{6})\.([A-Za-z0-9_-]{27,38})\Z",
169164
raw_discord_bot_token,
170165
):
166+
INVALID_DISCORD_BOT_TOKEN_MESSAGE: Final[str] = (
167+
"DISCORD_BOT_TOKEN must be set to a valid Discord bot token " # noqa: S105
168+
"(see https://discord.com/developers/docs/topics/oauth2#bot-vs-user-accounts)."
169+
)
171170
raise ImproperlyConfiguredError(INVALID_DISCORD_BOT_TOKEN_MESSAGE)
172171

173172
cls._settings["DISCORD_BOT_TOKEN"] = raw_discord_bot_token
174173

175174
@classmethod
176175
def _setup_discord_log_channel_webhook(cls) -> "Logger":
177-
INVALID_DISCORD_LOG_CHANNEL_WEBHOOK_URL_MESSAGE: Final[str] = (
178-
"DISCORD_LOG_CHANNEL_WEBHOOK_URL must be a valid webhook URL "
179-
"that points to a discord channel where logs should be displayed."
180-
)
181-
182176
raw_discord_log_channel_webhook_url: str = (
183177
(os.getenv("DISCORD_LOG_CHANNEL_WEBHOOK_URL", "")).strip().lower()
184178
)
@@ -190,6 +184,10 @@ def _setup_discord_log_channel_webhook(cls) -> "Logger":
190184
"https://discord.com/api/webhooks/"
191185
)
192186
):
187+
INVALID_DISCORD_LOG_CHANNEL_WEBHOOK_URL_MESSAGE: Final[str] = (
188+
"DISCORD_LOG_CHANNEL_WEBHOOK_URL must be a valid webhook URL "
189+
"that points to a discord channel where logs should be displayed."
190+
)
193191
raise ImproperlyConfiguredError(INVALID_DISCORD_LOG_CHANNEL_WEBHOOK_URL_MESSAGE)
194192

195193
webhook_config_logger: Logger = logging.getLogger("_temp_webhook_config")
@@ -212,16 +210,15 @@ def _setup_discord_log_channel_webhook(cls) -> "Logger":
212210

213211
@classmethod
214212
def _setup_discord_guild_id(cls) -> None:
215-
INVALID_DISCORD_GUILD_ID_MESSAGE: Final[str] = (
216-
"DISCORD_GUILD_ID must be a valid Discord guild ID "
217-
"(see https://docs.pycord.dev/en/stable/api/abcs.html#discord.abc.Snowflake.id)."
218-
)
219-
220213
raw_discord_guild_id: str = os.getenv("DISCORD_GUILD_ID", default="").strip()
221214

222215
if not raw_discord_guild_id or not re.fullmatch(
223216
r"\A\d{17,20}\Z", raw_discord_guild_id
224217
):
218+
INVALID_DISCORD_GUILD_ID_MESSAGE: Final[str] = (
219+
"DISCORD_GUILD_ID must be a valid Discord guild ID "
220+
"(see https://docs.pycord.dev/en/stable/api/abcs.html#discord.abc.Snowflake.id)."
221+
)
225222
raise ImproperlyConfiguredError(INVALID_DISCORD_GUILD_ID_MESSAGE)
226223

227224
cls._settings["_DISCORD_MAIN_GUILD_ID"] = int(raw_discord_guild_id)
@@ -443,23 +440,18 @@ def _setup_roles_messages(cls) -> None:
443440

444441
@classmethod
445442
def _setup_organisation_id(cls) -> None:
446-
INVALID_ORGANISATION_ID_MESSAGE: Final[str] = (
447-
"ORGANISATION_ID must be an integer 4 to 5 digits long."
448-
)
449-
450443
raw_organisation_id: str = os.getenv("ORGANISATION_ID", default="").strip()
451444

452445
if not raw_organisation_id or not re.fullmatch(r"\A\d{4,5}\Z", raw_organisation_id):
446+
INVALID_ORGANISATION_ID_MESSAGE: Final[str] = (
447+
"ORGANISATION_ID must be an integer 4 to 5 digits long."
448+
)
453449
raise ImproperlyConfiguredError(INVALID_ORGANISATION_ID_MESSAGE)
454450

455451
cls._settings["ORGANISATION_ID"] = raw_organisation_id
456452

457453
@classmethod
458454
def _setup_members_list_auth_session_cookie(cls) -> None:
459-
INVALID_MEMBERS_LIST_AUTH_SESSION_COOKIE_MESSAGE: Final[str] = (
460-
"MEMBERS_LIST_URL_SESSION_COOKIE must be a valid .ASPXAUTH cookie."
461-
)
462-
463455
raw_members_list_auth_session_cookie: str = os.getenv(
464456
"MEMBERS_LIST_URL_SESSION_COOKIE",
465457
default="",
@@ -468,6 +460,9 @@ def _setup_members_list_auth_session_cookie(cls) -> None:
468460
if not raw_members_list_auth_session_cookie or not re.fullmatch(
469461
r"\A[A-Fa-f\d]{128,256}\Z", raw_members_list_auth_session_cookie
470462
):
463+
INVALID_MEMBERS_LIST_AUTH_SESSION_COOKIE_MESSAGE: Final[str] = (
464+
"MEMBERS_LIST_URL_SESSION_COOKIE must be a valid .ASPXAUTH cookie."
465+
)
471466
raise ImproperlyConfiguredError(INVALID_MEMBERS_LIST_AUTH_SESSION_COOKIE_MESSAGE)
472467

473468
cls._settings["MEMBERS_LIST_AUTH_SESSION_COOKIE"] = (

0 commit comments

Comments
 (0)