Skip to content

Commit

Permalink
Merge branch 'main' into 2226-track-old-votes-in-github
Browse files Browse the repository at this point in the history
# Conflicts:
#	bot/exts/recruitment/talentpool/_cog.py
#	bot/exts/recruitment/talentpool/_review.py
  • Loading branch information
shtlrs committed Jan 1, 2023
2 parents da3c904 + 870cf7f commit 59319b4
Show file tree
Hide file tree
Showing 69 changed files with 1,146 additions and 2,052 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
bot/exts/info/codeblock/** @MarkKoz
bot/exts/utils/extensions.py @MarkKoz
bot/exts/utils/snekbox.py @MarkKoz @jb3
bot/exts/help_channels/** @MarkKoz
bot/exts/moderation/** @mbaruh @Den4200 @ks129 @jb3
bot/exts/info/** @Den4200 @jb3
bot/exts/info/information.py @mbaruh @jb3
Expand Down
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
2 changes: 1 addition & 1 deletion bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from typing import TYPE_CHECKING

from botcore.utils import apply_monkey_patches
from pydis_core.utils import apply_monkey_patches

from bot import log

Expand Down
4 changes: 2 additions & 2 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import aiohttp
import discord
from async_rediscache import RedisSession
from botcore import StartupError
from botcore.site_api import APIClient
from discord.ext import commands
from pydis_core import StartupError
from pydis_core.site_api import APIClient
from redis import RedisError

import bot
Expand Down
6 changes: 3 additions & 3 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from collections import defaultdict

import aiohttp
from botcore import BotBase
from botcore.utils import scheduling
from pydis_core import BotBase
from pydis_core.utils import scheduling
from sentry_sdk import push_scope

from bot import constants, exts
Expand All @@ -21,7 +21,7 @@ def __init__(self, base: Exception):


class Bot(BotBase):
"""A subclass of `botcore.BotBase` that implements bot-specific functions."""
"""A subclass of `pydis_core.BotBase` that implements bot-specific functions."""

def __init__(self, *args, **kwargs):

Expand Down
20 changes: 3 additions & 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 @@ -619,19 +615,9 @@ class HelpChannels(metaclass=YAMLGetter):
section = 'help_channels'

enable: bool
cmd_whitelist: List[int]
idle_minutes_claimant: int
idle_minutes_others: int
idle_minutes: 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
cmd_whitelist: List[int]


class RedirectOutput(metaclass=YAMLGetter):
Expand Down
6 changes: 3 additions & 3 deletions bot/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import dateutil.parser
import discord
from aiohttp import ClientConnectorError
from botcore.site_api import ResponseCodeError
from botcore.utils import unqualify
from botcore.utils.regex import DISCORD_INVITE
from dateutil.relativedelta import relativedelta
from discord.ext.commands import BadArgument, Bot, Context, Converter, IDConverter, MemberConverter, UserConverter
from discord.utils import escape_markdown, snowflake_time
from pydis_core.site_api import ResponseCodeError
from pydis_core.utils import unqualify
from pydis_core.utils.regex import DISCORD_INVITE

from bot import exts, instance as bot_instance
from bot.constants import URLs
Expand Down
2 changes: 1 addition & 1 deletion bot/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from contextlib import suppress

import arrow
from botcore.utils import scheduling
from discord import Member, NotFound
from discord.ext import commands
from discord.ext.commands import Cog, Context
from pydis_core.utils import scheduling

from bot.constants import Channels, DEBUG_MODE, RedirectOutput
from bot.log import get_logger
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/backend/error_handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import copy
import difflib

from botcore.site_api import ResponseCodeError
from discord import Embed
from discord.ext.commands import ChannelNotFound, Cog, Context, TextChannelConverter, VoiceChannelConverter, errors
from pydis_core.site_api import ResponseCodeError
from sentry_sdk import push_scope

from bot.bot import Bot
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/backend/logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from botcore.utils import scheduling
from discord import Embed
from discord.ext.commands import Cog
from pydis_core.utils import scheduling

from bot.bot import Bot
from bot.constants import Channels, DEBUG_MODE
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/backend/sync/_cog.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
from typing import Any, Dict

from botcore.site_api import ResponseCodeError
from discord import Member, Role, User
from discord.ext import commands
from discord.ext.commands import Cog, Context
from pydis_core.site_api import ResponseCodeError

from bot import constants
from bot.bot import Bot
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/backend/sync/_syncers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from collections import namedtuple

import discord.errors
from botcore.site_api import ResponseCodeError
from discord import Guild
from discord.ext.commands import Context
from more_itertools import chunked
from pydis_core.site_api import ResponseCodeError

import bot
from bot.log import get_logger
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/filters/antispam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from typing import Dict, Iterable, List, Set

import arrow
from botcore.utils import scheduling
from discord import Colour, Member, Message, MessageType, NotFound, Object, TextChannel
from discord.ext.commands import Cog
from pydis_core.utils import scheduling

from bot import rules
from bot.bot import Bot
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/filters/filter_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import arrow
import discord
from botcore.site_api import ResponseCodeError
from discord.ext import tasks
from discord.ext.commands import BadArgument, Cog, Context, IDConverter, command, group, has_any_role
from pydis_core.site_api import ResponseCodeError

from bot import constants
from bot.bot import Bot
Expand Down
6 changes: 3 additions & 3 deletions bot/exts/filters/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import regex
import tldextract
from async_rediscache import RedisCache
from botcore.site_api import ResponseCodeError
from botcore.utils import scheduling
from botcore.utils.regex import DISCORD_INVITE
from dateutil.relativedelta import relativedelta
from discord import ChannelType, Colour, Embed, Forbidden, HTTPException, Member, Message, NotFound, TextChannel
from discord.ext.commands import Cog
from discord.utils import escape_markdown
from pydis_core.site_api import ResponseCodeError
from pydis_core.utils import scheduling
from pydis_core.utils.regex import DISCORD_INVITE

from bot.bot import Bot
from bot.constants import Bot as BotConfig, Channels, Colours, Filter, Guild, Icons, URLs
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/fun/off_topic_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from functools import partial
from typing import Optional

from botcore.site_api import ResponseCodeError
from discord import ButtonStyle, Colour, Embed, Interaction
from discord.ext import tasks
from discord.ext.commands import Cog, Context, group, has_any_role
from discord.ui import Button, View
from pydis_core.site_api import ResponseCodeError

from bot.bot import Bot
from bot.constants import Bot as BotConfig, Channels, MODERATION_ROLES, NEGATIVE_REPLIES
Expand Down
41 changes: 8 additions & 33 deletions bot/exts/help_channels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
from bot import constants

from bot.bot import Bot
from bot.exts.help_channels._channel import MAX_CHANNELS_PER_CATEGORY
from bot.constants import HelpChannels
from bot.exts.help_channels._cog import HelpForum
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."
)


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."""
if not HelpChannels.enable:
log.warning("HelpChannel.enabled set to false, not loading help channel cog.")
return
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, non-bot, 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

0 comments on commit 59319b4

Please sign in to comment.