diff options
| author | 2021-04-06 11:25:13 +0200 | |
|---|---|---|
| committer | 2021-04-06 11:29:32 +0200 | |
| commit | 2aa7e740d6a66e477895460ab51ac02c9b625ee1 (patch) | |
| tree | 99c9c9fda3949ad77683ece4150f5bb1b90dce55 | |
| parent | Merge pull request #1499 from bsoyka/user-colors (diff) | |
Add a !tp get_review command to get the nomination text without posting it
This can be used when an information should be added to the post, or someone wants to review the user.
| -rw-r--r-- | bot/exts/recruitment/talentpool/_cog.py | 13 | ||||
| -rw-r--r-- | bot/exts/recruitment/talentpool/_review.py | 37 |
2 files changed, 37 insertions, 13 deletions
diff --git a/bot/exts/recruitment/talentpool/_cog.py b/bot/exts/recruitment/talentpool/_cog.py index fbe79382d..eeba1b187 100644 --- a/bot/exts/recruitment/talentpool/_cog.py +++ b/bot/exts/recruitment/talentpool/_cog.py @@ -1,8 +1,10 @@ import logging import textwrap from collections import ChainMap +from io import StringIO from typing import Union +import discord from discord import Color, Embed, Member, User from discord.ext.commands import Cog, Context, group, has_any_role @@ -332,6 +334,17 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"): return await ctx.send(f"✅ The user with ID `{user_id}` was marked as reviewed.") + @nomination_group.command(aliases=('gr',)) + @has_any_role(*MODERATION_ROLES) + async def get_review(self, ctx: Context, user_id: int) -> None: + """Get the user's review as a markdown file.""" + review = StringIO((await self.reviewer.make_review(user_id))[0]) + if review: + file = discord.File(review, f"{user_id}_review.md") + await ctx.send(file=file) + else: + await ctx.send(f"There doesn't appear to be an active nomination for {user_id}") + @nomination_group.command(aliases=('review',)) @has_any_role(*MODERATION_ROLES) async def post_review(self, ctx: Context, user_id: int) -> None: diff --git a/bot/exts/recruitment/talentpool/_review.py b/bot/exts/recruitment/talentpool/_review.py index fb3461238..c46df4bcc 100644 --- a/bot/exts/recruitment/talentpool/_review.py +++ b/bot/exts/recruitment/talentpool/_review.py @@ -66,26 +66,40 @@ class Reviewer: self._review_scheduler.schedule_at(review_at, user_id, self.post_review(user_id, update_database=True)) async def post_review(self, user_id: int, update_database: bool) -> None: - """Format a generic review of a user and post it to the nomination voting channel.""" + """Format the review of a user and post it to the nomination voting channel.""" + review, seen_emoji = await self.make_review(user_id) + if not review: + return + + guild = self.bot.get_guild(Guild.id) + channel = guild.get_channel(Channels.nomination_voting) + log.trace(f"Posting the review of {user_id}") + message = (await self._bulk_send(channel, review))[-1] + if seen_emoji: + for reaction in (seen_emoji, "👍", "👎"): + await message.add_reaction(reaction) + + if update_database: + nomination = self._pool.watched_users[user_id] + await self.bot.api_client.patch(f"{self._pool.api_endpoint}/{nomination['id']}", json={"reviewed": True}) + + async def make_review(self, user_id: int) -> typing.Tuple[str, Optional[Emoji]]: + """Format a generic review of a user and return it with the seen emoji.""" + log.trace(f"Formatting the review of {user_id}") nomination = self._pool.watched_users[user_id] if not nomination: log.trace(f"There doesn't appear to be an active nomination for {user_id}") - return + return "", None guild = self.bot.get_guild(Guild.id) - channel = guild.get_channel(Channels.nomination_voting) member = guild.get_member(user_id) - if update_database: - await self.bot.api_client.patch(f"{self._pool.api_endpoint}/{nomination['id']}", json={"reviewed": True}) - if not member: - await channel.send( + return ( f"I tried to review the user with ID `{user_id}`, but they don't appear to be on the server 😔" - ) - return + ), None opening = f"<@&{Roles.moderators}> <@&{Roles.admins}>\n{member.mention} ({member}) for Helper!" @@ -104,10 +118,7 @@ class Reviewer: ) review = "\n\n".join(part for part in (opening, current_nominations, review_body, vote_request)) - - message = (await self._bulk_send(channel, review))[-1] - for reaction in (seen_emoji, "👍", "👎"): - await message.add_reaction(reaction) + return review, seen_emoji async def _construct_review_body(self, member: Member) -> str: """Formats the body of the nomination, with details of activity, infractions, and previous nominations.""" |