Skip to content
Merged
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ log.*
!log.py

# Custom user configuration
config.yml
*config.yml
docker-compose.override.yml
metricity-config.toml

Expand Down
18 changes: 1 addition & 17 deletions bot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@ class Categories(metaclass=YAMLGetter):
section = "guild"
subsection = "categories"

help_available: int
help_dormant: int
help_in_use: int
moderators: int
modmail: int
voice: int
Expand All @@ -416,8 +413,7 @@ class Channels(metaclass=YAMLGetter):
meta: int
python_general: int

cooldown: int
how_to_get_help: int
help_system_forum: int

attachment_log: int
filter_log: int
Expand Down Expand Up @@ -620,18 +616,6 @@ class HelpChannels(metaclass=YAMLGetter):

enable: bool
cmd_whitelist: List[int]
idle_minutes_claimant: int
idle_minutes_others: int
deleted_idle_minutes: int
max_available: int
max_total_channels: int
name_prefix: str
notify_channel: int
notify_minutes: int
notify_none_remaining: bool
notify_none_remaining_roles: List[int]
notify_running_low: bool
notify_running_low_threshold: int


class RedirectOutput(metaclass=YAMLGetter):
Expand Down
40 changes: 4 additions & 36 deletions bot/exts/help_channels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
from bot import constants
from bot.bot import Bot
from bot.exts.help_channels._channel import MAX_CHANNELS_PER_CATEGORY
from bot.log import get_logger

log = get_logger(__name__)


def validate_config() -> None:
"""Raise a ValueError if the cog's config is invalid."""
log.trace("Validating config.")
total = constants.HelpChannels.max_total_channels
available = constants.HelpChannels.max_available

if total == 0 or available == 0:
raise ValueError("max_total_channels and max_available and must be greater than 0.")

if total < available:
raise ValueError(
f"max_total_channels ({total}) must be greater than or equal to max_available "
f"({available})."
)

if total > MAX_CHANNELS_PER_CATEGORY:
raise ValueError(
f"max_total_channels ({total}) must be less than or equal to "
f"{MAX_CHANNELS_PER_CATEGORY} due to Discord's limit on channels per category."
)
from bot.bot import Bot
from bot.exts.help_channels._cog import HelpForum


async def setup(bot: Bot) -> None:
"""Load the HelpChannels cog."""
# Defer import to reduce side effects from importing the help_channels package.
from bot.exts.help_channels._cog import HelpChannels
try:
validate_config()
except ValueError as e:
log.error(f"HelpChannels cog will not be loaded due to misconfiguration: {e}")
else:
await bot.add_cog(HelpChannels(bot))
"""Load the HelpForum cog."""
await bot.add_cog(HelpForum(bot))
25 changes: 4 additions & 21 deletions bot/exts/help_channels/_caches.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
from async_rediscache import RedisCache

# This dictionary maps a help channel to the time it was claimed
# RedisCache[discord.TextChannel.id, UtcPosixTimestamp]
claim_times = RedisCache(namespace="HelpChannels.claim_times")

# This cache tracks which channels are claimed by which members.
# RedisCache[discord.TextChannel.id, t.Union[discord.User.id, discord.Member.id]]
claimants = RedisCache(namespace="HelpChannels.help_channel_claimants")

# Stores the timestamp of the last message from the claimant of a help channel
# RedisCache[discord.TextChannel.id, UtcPosixTimestamp]
claimant_last_message_times = RedisCache(namespace="HelpChannels.claimant_last_message_times")

# This cache maps a help channel to the timestamp of the last non-claimant message.
# This cache being empty for a given help channel indicates the question is unanswered.
# RedisCache[discord.TextChannel.id, UtcPosixTimestamp]
non_claimant_last_message_times = RedisCache(namespace="HelpChannels.non_claimant_last_message_times")

# This cache keeps track of the dynamic message ID for
# the continuously updated message in the #How-to-get-help channel.
dynamic_message = RedisCache(namespace="HelpChannels.dynamic_message")

# This cache keeps track of who has help-dms on.
# RedisCache[discord.User.id, bool]
help_dm = RedisCache(namespace="HelpChannels.help_dm")
Expand All @@ -29,3 +8,7 @@
# serialise the set as a comma separated string to allow usage with redis
# RedisCache[discord.TextChannel.id, str[set[discord.User.id]]]
session_participants = RedisCache(namespace="HelpChannels.session_participants")

# Stores posts that have had a non-claimant reply.
# Currently only used to determine whether the post was answered or not when collecting stats.
posts_with_non_claimant_messages = RedisCache(namespace="HelpChannels.posts_with_non_claimant_messages")
Loading