diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/recruitment/talentpool/_cog.py | 70 | 
1 files changed, 66 insertions, 4 deletions
diff --git a/bot/exts/recruitment/talentpool/_cog.py b/bot/exts/recruitment/talentpool/_cog.py index 03326cab2..80bd48534 100644 --- a/bot/exts/recruitment/talentpool/_cog.py +++ b/bot/exts/recruitment/talentpool/_cog.py @@ -5,18 +5,20 @@ from io import StringIO  from typing import Union  import discord +from async_rediscache import RedisCache  from discord import Color, Embed, Member, PartialMessage, RawReactionActionEvent, User  from discord.ext.commands import Cog, Context, group, has_any_role  from bot.api import ResponseCodeError  from bot.bot import Bot -from bot.constants import Channels, Emojis, Guild, MODERATION_ROLES, STAFF_ROLES, Webhooks +from bot.constants import Channels, Emojis, Guild, MODERATION_ROLES, Roles, STAFF_ROLES, Webhooks  from bot.converters import FetchedMember  from bot.exts.moderation.watchchannels._watchchannel import WatchChannel  from bot.exts.recruitment.talentpool._review import Reviewer  from bot.pagination import LinePaginator  from bot.utils import time +AUTOREVIEW_ENABLED_KEY = "autoreview_enabled"  REASON_MAX_CHARS = 1000  log = logging.getLogger(__name__) @@ -25,6 +27,10 @@ log = logging.getLogger(__name__)  class TalentPool(WatchChannel, Cog, name="Talentpool"):      """Relays messages of helper candidates to a watch channel to observe them.""" +    # RedisCache[str, bool] +    # Can contain a single key, "autoreview_enabled", with the value a bool indicating if autoreview is enabled. +    talentpool_settings = RedisCache() +      def __init__(self, bot: Bot) -> None:          super().__init__(              bot, @@ -37,7 +43,18 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):          )          self.reviewer = Reviewer(self.__class__.__name__, bot, self) -        self.bot.loop.create_task(self.reviewer.reschedule_reviews()) +        self.bot.loop.create_task(self.schedule_autoreviews()) + +    async def schedule_autoreviews(self) -> None: +        """Reschedule reviews for active nominations if autoreview is enabled.""" +        if await self.autoreview_enabled(): +            await self.reviewer.reschedule_reviews() +        else: +            self.log.trace("Not scheduling reviews as autoreview is disabled.") + +    async def autoreview_enabled(self) -> bool: +        """Return whether automatic posting of nomination reviews is enabled.""" +        return await self.talentpool_settings.get(AUTOREVIEW_ENABLED_KEY, True)      @group(name='talentpool', aliases=('tp', 'talent', 'nomination', 'n'), invoke_without_command=True)      @has_any_role(*MODERATION_ROLES) @@ -45,6 +62,50 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):          """Highlights the activity of helper nominees by relaying their messages to the talent pool channel."""          await ctx.send_help(ctx.command) +    @nomination_group.group(name="autoreview", aliases=("ar",), invoke_without_command=True) +    @has_any_role(*MODERATION_ROLES) +    async def nomination_autoreview_group(self, ctx: Context) -> None: +        """Commands for enabling or disabling autoreview.""" +        await ctx.send_help(ctx.command) + +    @nomination_autoreview_group.command(name="enable", aliases=("on",)) +    @has_any_role(Roles.admins) +    async def autoreview_enable(self, ctx: Context) -> None: +        """ +        Enable automatic posting of reviews. + +        This will post reviews up to one day overdue. Older nominations can be +        manually reviewed with the `tp post_review <user_id>` command. +        """ +        if await self.autoreview_enabled(): +            await ctx.send(":x: Autoreview is already enabled") +            return + +        await self.talentpool_settings.set(AUTOREVIEW_ENABLED_KEY, True) +        await self.reviewer.reschedule_reviews() +        await ctx.send(":white_check_mark: Autoreview enabled") + +    @nomination_autoreview_group.command(name="disable", aliases=("off",)) +    @has_any_role(Roles.admins) +    async def autoreview_disable(self, ctx: Context) -> None: +        """Disable automatic posting of reviews.""" +        if not await self.autoreview_enabled(): +            await ctx.send(":x: Autoreview is already disabled") +            return + +        await self.talentpool_settings.set(AUTOREVIEW_ENABLED_KEY, False) +        self.reviewer.cancel_all() +        await ctx.send(":white_check_mark: Autoreview disabled") + +    @nomination_autoreview_group.command(name="status") +    @has_any_role(*MODERATION_ROLES) +    async def autoreview_status(self, ctx: Context) -> None: +        """Show whether automatic posting of reviews is enabled or disabled.""" +        if await self.autoreview_enabled(): +            await ctx.send("Autoreview is currently enabled") +        else: +            await ctx.send("Autoreview is currently disabled") +      @nomination_group.command(name='watched', aliases=('all', 'list'), root_aliases=("nominees",))      @has_any_role(*MODERATION_ROLES)      async def watched_command( @@ -190,7 +251,7 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):          self.watched_users[user.id] = response_data -        if user.id not in self.reviewer: +        if await self.autoreview_enabled() and user.id not in self.reviewer:              self.reviewer.schedule_review(user.id)          history = await self.bot.api_client.get( @@ -403,7 +464,8 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):          )          self._remove_user(user_id) -        self.reviewer.cancel(user_id) +        if await self.autoreview_enabled(): +            self.reviewer.cancel(user_id)          return True  |