diff options
author | 2020-12-13 10:57:43 +0100 | |
---|---|---|
committer | 2020-12-13 10:57:43 +0100 | |
commit | dca6ec330694f8ff09a21a0f70dfc2b06feea674 (patch) | |
tree | d96964e01ff4310997671d69ef8ce7932902238d /bot/constants.py | |
parent | Update docstrings and fix grammar in comments (diff) | |
parent | Add callback to log errors in AoC background tasks (diff) |
Merge branch 'master' into sebastiaan/advent-of-code/refactor-background-tasks
# Conflicts:
# bot/exts/christmas/advent_of_code/_cog.py
# bot/exts/christmas/advent_of_code/_helpers.py
Diffstat (limited to 'bot/constants.py')
-rw-r--r-- | bot/constants.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/bot/constants.py b/bot/constants.py index c696b202..5e97fa2d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,3 +1,4 @@ +import dataclasses import enum import logging from datetime import datetime @@ -29,11 +30,27 @@ __all__ = ( log = logging.getLogger(__name__) -class AdventOfCodeLeaderboard(NamedTuple): +class AdventOfCodeLeaderboard: id: str - session: str + _session: str join_code: str + # If we notice that the session for this board expired, we set + # this attribute to `True`. We will emit a Sentry error so we + # can handle it, but, in the meantime, we'll try using the + # fallback session to make sure the commands still work. + use_fallback_session: bool = False + + @property + def session(self) -> str: + """Return either the actual `session` cookie or the fallback cookie.""" + if self.use_fallback_session: + log.info(f"Returning fallback cookie for board `{self.id}`.") + return AdventOfCode.fallback_session + + return self._session + def _parse_aoc_leaderboard_env() -> Dict[str, AdventOfCodeLeaderboard]: """ @@ -61,6 +78,7 @@ class AdventOfCode: # Information for the several leaderboards we have leaderboards = _parse_aoc_leaderboard_env() staff_leaderboard_id = environ.get("AOC_STAFF_LEADERBOARD_ID", "") + fallback_session = environ.get("AOC_FALLBACK_SESSION", "") # Other Advent of Code constants ignored_days = environ.get("AOC_IGNORED_DAYS", "").split(",") @@ -77,6 +95,7 @@ class Branding: class Channels(NamedTuple): admins = 365960823622991872 advent_of_code = int(environ.get("AOC_CHANNEL_ID", 782715290437943306)) + advent_of_code_commands = int(environ.get("AOC_COMMANDS_CHANNEL_ID", 607247579608121354)) announcements = int(environ.get("CHANNEL_ANNOUNCEMENTS", 354619224620138496)) big_brother_logs = 468507907357409333 bot = 267659945086812160 |