diff options
| -rw-r--r-- | bot/exts/recruitment/talentpool/_review.py | 10 | ||||
| -rw-r--r-- | bot/utils/messages.py | 17 |
2 files changed, 23 insertions, 4 deletions
diff --git a/bot/exts/recruitment/talentpool/_review.py b/bot/exts/recruitment/talentpool/_review.py index 04581ec13..ddad5c9c0 100644 --- a/bot/exts/recruitment/talentpool/_review.py +++ b/bot/exts/recruitment/talentpool/_review.py @@ -16,7 +16,7 @@ from discord.ext.commands import Context from bot.api import ResponseCodeError from bot.bot import Bot from bot.constants import Channels, Colours, Emojis, Guild, Roles -from bot.utils.messages import count_unique_users_reaction +from bot.utils.messages import count_unique_users_reaction, pin_no_system_message from bot.utils.scheduling import Scheduler from bot.utils.time import get_time_delta, humanize_delta, time_since @@ -77,10 +77,14 @@ class Reviewer: channel = guild.get_channel(Channels.nomination_voting) log.trace(f"Posting the review of {user_id}") - message = (await self._bulk_send(channel, review))[-1] + messages = await self._bulk_send(channel, review) + + await pin_no_system_message(messages[0]) + + last_message = messages[-1] if seen_emoji: for reaction in (seen_emoji, "\N{THUMBS UP SIGN}", "\N{THUMBS DOWN SIGN}"): - await message.add_reaction(reaction) + await last_message.add_reaction(reaction) if update_database: nomination = self._pool.watched_users[user_id] diff --git a/bot/utils/messages.py b/bot/utils/messages.py index 2fcc5a01f..d0d56e273 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -8,7 +8,7 @@ from io import BytesIO from typing import Callable, List, Optional, Sequence, Union import discord -from discord import Reaction +from discord import Message, MessageType, Reaction from discord.errors import HTTPException from discord.ext.commands import Context @@ -186,6 +186,21 @@ async def count_unique_users_reaction( return len(unique_users) +async def pin_no_system_message(message: Message) -> bool: + """Pin the given message, wait a couple of seconds and try to delete the system message.""" + await message.pin() + + # Make sure that we give it enough time to deliver the message + await asyncio.sleep(2) + # Search for the system message in the last 10 messages + async for historical_message in message.channel.history(limit=10): + if historical_message.type == MessageType.pins_add: + await historical_message.delete() + return True + + return False + + def sub_clyde(username: Optional[str]) -> Optional[str]: """ Replace "e"/"E" in any "clyde" in `username` with a Cyrillic "ะต"/"E" and return the new string. |