Skip to content

Commit 27f7e25

Browse files
make user configurable
1 parent a0a6e7e commit 27f7e25

2 files changed

Lines changed: 71 additions & 42 deletions

File tree

cogs/committee_actions_tracking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def _update_action_board(self) -> None:
7070
"""
7171
action_board_channel: discord.TextChannel | None = discord.utils.get(
7272
self.bot.main_guild.text_channels,
73-
name="actions", # TODO: Make this user-configurable # noqa: FIX002
73+
name=settings["COMMITTEE_ACTIONS_BOARD_CHANNEL"],
7474
)
7575

7676
if not action_board_channel:
@@ -275,7 +275,7 @@ async def committee_actions_reminders_task(self) -> None:
275275
"""
276276
committee_general_channel: discord.TextChannel | None = discord.utils.get(
277277
self.bot.main_guild.text_channels,
278-
name="committee-general", # TODO: Make this user-configurable # noqa: FIX002
278+
name=settings["COMMITTEE_ACTIONS_REMINDERS_CHANNEL"],
279279
)
280280

281281
if not committee_general_channel:

config.py

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,75 @@ def _setup_committee_actions_reminders(cls) -> None:
775775
raw_committee_actions_reminders in TRUE_VALUES
776776
)
777777

778+
@classmethod
779+
def _setup_committee_actions_reminders_interval(cls) -> None:
780+
if "COMMITTEE_ACTIONS_REMINDERS" not in cls._settings:
781+
INVALID_SETUP_ORDER_MESSAGE: Final[str] = (
782+
"Invalid setup order: COMMITTEE_ACTIONS_REMINDERS must be set up "
783+
"before COMMITTEE_ACTIONS_REMINDERS_INTERVAL can be set up."
784+
)
785+
raise RuntimeError(INVALID_SETUP_ORDER_MESSAGE)
786+
787+
raw_committee_actions_reminders_interval: re.Match[str] | None = re.fullmatch(
788+
r"\A(?:(?P<seconds>(?:\d*\.)?\d+)s)?(?:(?P<minutes>(?:\d*\.)?\d+)m)?(?:(?P<hours>(?:\d*\.)?\d+)h)?\Z",
789+
str(os.getenv("COMMITTEE_ACTIONS_REMINDERS_INTERVAL", "24h")),
790+
)
791+
792+
raw_timedelta_committee_actions_reminders_interval: Mapping[str, float] = {
793+
"hours": 24,
794+
}
795+
796+
if cls._settings["COMMITTEE_ACTIONS_REMINDERS"]:
797+
if not raw_committee_actions_reminders_interval:
798+
INVALID_COMMITTEE_ACTIONS_REMINDERS_INTERVAL_MESSAGE: Final[str] = (
799+
"COMMITTEE_ACTIONS_REMINDERS_INTERVAL must contain the interval "
800+
"in any combination of seconds, minutes or hours."
801+
)
802+
raise ImproperlyConfiguredError(
803+
INVALID_COMMITTEE_ACTIONS_REMINDERS_INTERVAL_MESSAGE,
804+
)
805+
806+
raw_timedelta_committee_actions_reminders_interval = {
807+
key: float(value)
808+
for key, value in (
809+
raw_committee_actions_reminders_interval.groupdict().items()
810+
)
811+
if value
812+
}
813+
814+
cls._settings["COMMITTEE_ACTIONS_REMINDERS_INTERVAL"] = (
815+
raw_timedelta_committee_actions_reminders_interval
816+
)
817+
818+
@classmethod
819+
def _setup_committee_actions_reminders_channel(cls) -> None:
820+
if "COMMITTEE_ACTIONS_REMINDERS" not in cls._settings:
821+
INVALID_SETUP_ORDER_MESSAGE: Final[str] = (
822+
"Invalid setup order: COMMITTEE_ACTIONS_REMINDERS must be set up "
823+
"before COMMITTEE_ACTIONS_REMINDERS_CHANNEL can be set up."
824+
)
825+
raise RuntimeError(INVALID_SETUP_ORDER_MESSAGE)
826+
827+
INVALID_COMMITTEE_ACTIONS_REMINDERS_CHANNEL_MESSAGE: Final[str] = (
828+
"COMMITTEE_ACTIONS_REMINDERS_CHANNEL must be a valid name"
829+
" of a channel in your group's Discord guild."
830+
)
831+
832+
raw_committee_actions_reminders_channel: str = (
833+
os.getenv("COMMITTEE_ACTIONS_REMINDERS_CHANNEL", "committee-general")
834+
.strip()
835+
.lower()
836+
)
837+
838+
if not raw_committee_actions_reminders_channel:
839+
raise ImproperlyConfiguredError(
840+
INVALID_COMMITTEE_ACTIONS_REMINDERS_CHANNEL_MESSAGE
841+
)
842+
843+
cls._settings["COMMITTEE_ACTIONS_REMINDERS_CHANNEL"] = (
844+
raw_committee_actions_reminders_channel
845+
)
846+
778847
@classmethod
779848
def _setup_committee_actions_board(cls) -> None:
780849
raw_committee_actions_board: str = (
@@ -817,46 +886,6 @@ def _setup_committee_actions_board_channel(cls) -> None:
817886

818887
cls._settings["COMMITTEE_ACTIONS_BOARD_CHANNEL"] = raw_committee_actions_board_channel
819888

820-
@classmethod
821-
def _setup_committee_actions_reminders_interval(cls) -> None:
822-
if "COMMITTEE_ACTIONS_REMINDERS" not in cls._settings:
823-
INVALID_SETUP_ORDER_MESSAGE: Final[str] = (
824-
"Invalid setup order: COMMITTEE_ACTIONS_REMINDERS must be set up "
825-
"before COMMITTEE_ACTIONS_REMINDERS_INTERVAL can be set up."
826-
)
827-
raise RuntimeError(INVALID_SETUP_ORDER_MESSAGE)
828-
829-
raw_committee_actions_reminders_interval: re.Match[str] | None = re.fullmatch(
830-
r"\A(?:(?P<seconds>(?:\d*\.)?\d+)s)?(?:(?P<minutes>(?:\d*\.)?\d+)m)?(?:(?P<hours>(?:\d*\.)?\d+)h)?\Z",
831-
str(os.getenv("COMMITTEE_ACTIONS_REMINDERS_INTERVAL", "24h")),
832-
)
833-
834-
raw_timedelta_committee_actions_reminders_interval: Mapping[str, float] = {
835-
"hours": 24,
836-
}
837-
838-
if cls._settings["COMMITTEE_ACTIONS_REMINDERS"]:
839-
if not raw_committee_actions_reminders_interval:
840-
INVALID_COMMITTEE_ACTIONS_REMINDERS_INTERVAL_MESSAGE: Final[str] = (
841-
"COMMITTEE_ACTIONS_REMINDERS_INTERVAL must contain the interval "
842-
"in any combination of seconds, minutes or hours."
843-
)
844-
raise ImproperlyConfiguredError(
845-
INVALID_COMMITTEE_ACTIONS_REMINDERS_INTERVAL_MESSAGE,
846-
)
847-
848-
raw_timedelta_committee_actions_reminders_interval = {
849-
key: float(value)
850-
for key, value in (
851-
raw_committee_actions_reminders_interval.groupdict().items()
852-
)
853-
if value
854-
}
855-
856-
cls._settings["COMMITTEE_ACTIONS_REMINDERS_INTERVAL"] = (
857-
raw_timedelta_committee_actions_reminders_interval
858-
)
859-
860889
@classmethod
861890
def _setup_env_variables(cls) -> None:
862891
"""

0 commit comments

Comments
 (0)