diff options
| -rw-r--r-- | bot/exts/info/information.py | 3 | ||||
| -rw-r--r-- | bot/exts/recruitment/talentpool/_cog.py | 24 | ||||
| -rw-r--r-- | bot/exts/recruitment/talentpool/_review.py | 2 | 
3 files changed, 12 insertions, 17 deletions
| diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py index 51d47b75c..be67910a6 100644 --- a/bot/exts/info/information.py +++ b/bot/exts/info/information.py @@ -72,7 +72,8 @@ class Information(Cog):          """Return additional server info only visible in moderation channels."""          talentpool_info = ""          if cog := self.bot.get_cog("Talentpool"): -            talentpool_info = f"Nominated: {len(cog.cache)}\n" +            num_nominated = len(cog.cache) if cog.cache else "-" +            talentpool_info = f"Nominated: {num_nominated}\n"          bb_info = ""          if cog := self.bot.get_cog("Big Brother"): diff --git a/bot/exts/recruitment/talentpool/_cog.py b/bot/exts/recruitment/talentpool/_cog.py index a317c6645..aaafff973 100644 --- a/bot/exts/recruitment/talentpool/_cog.py +++ b/bot/exts/recruitment/talentpool/_cog.py @@ -2,7 +2,7 @@ import logging  import textwrap  from collections import ChainMap, defaultdict  from io import StringIO -from typing import Union +from typing import Optional, Union  import discord  from async_rediscache import RedisCache @@ -15,7 +15,7 @@ from bot.constants import Channels, Emojis, Guild, MODERATION_ROLES, Roles, STAF  from bot.converters import MemberOrUser  from bot.exts.recruitment.talentpool._review import Reviewer  from bot.pagination import LinePaginator -from bot.utils import time +from bot.utils import scheduling, time  from bot.utils.time import get_time_delta  AUTOREVIEW_ENABLED_KEY = "autoreview_enabled" @@ -34,12 +34,17 @@ class TalentPool(Cog, name="Talentpool"):      def __init__(self, bot: Bot) -> None:          self.bot = bot          self.reviewer = Reviewer(self.__class__.__name__, bot, self) +        self.cache: Optional[defaultdict[dict]] = None          self.api_default_params = {'active': 'true', 'ordering': '-inserted_at'} -        self.bot.loop.create_task(self.schedule_autoreviews()) + +        self.initial_refresh_task = scheduling.create_task(self.refresh_cache(), event_loop=self.bot.loop) +        scheduling.create_task(self.schedule_autoreviews(), event_loop=self.bot.loop)      async def schedule_autoreviews(self) -> None:          """Reschedule reviews for active nominations if autoreview is enabled."""          if await self.autoreview_enabled(): +            # Wait for a populated cache first +            await self.initial_refresh_task              await self.reviewer.reschedule_reviews()          else:              log.trace("Not scheduling reviews as autoreview is disabled.") @@ -50,6 +55,8 @@ class TalentPool(Cog, name="Talentpool"):      async def refresh_cache(self) -> bool:          """Updates TalentPool users cache.""" +        # Wait until logged in to ensure bot api client exists +        await self.bot.wait_until_guild_available()          try:              data = await self.bot.api_client.get(                  'bot/nominations', @@ -284,18 +291,7 @@ class TalentPool(Cog, name="Talentpool"):          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( -            'bot/nominations', -            params={ -                "user__id": str(user.id), -                "active": "false", -                "ordering": "-inserted_at" -            } -        ) -          msg = f"✅ The nomination for {user.mention} has been added to the talent pool" -        if history: -            msg += f"\n\n({len(history)} previous nominations in total)"          await ctx.send(msg) diff --git a/bot/exts/recruitment/talentpool/_review.py b/bot/exts/recruitment/talentpool/_review.py index 3ffbf93f3..f4aa73e75 100644 --- a/bot/exts/recruitment/talentpool/_review.py +++ b/bot/exts/recruitment/talentpool/_review.py @@ -57,8 +57,6 @@ class Reviewer:          """Reschedule all active nominations to be reviewed at the appropriate time."""          log.trace("Rescheduling reviews")          await self.bot.wait_until_guild_available() -        # TODO Once the watch channel is removed, this can be done in a smarter way, e.g create a sync function. -        await self._pool.refresh_cache()          for user_id, user_data in self._pool.cache.items():              if not user_data["reviewed"]: | 
