Delete own messages and remove reaction instead

https://github.com/hackclub/nephthys/pull/50#pullrequestreview-3166968776
This commit is contained in:
twonfi 2025-08-28 18:05:04 -07:00 committed by Amber
parent 218ebeb14a
commit d1c2aaf4cb
2 changed files with 39 additions and 29 deletions

View file

@ -9,7 +9,14 @@ from nephthys.utils.permissions import can_resolve
from prisma.enums import TicketStatus
async def resolve(ts: str, resolver: str, client: AsyncWebClient, stale: bool = False):
async def resolve(
ts: str,
resolver: str,
client: AsyncWebClient,
stale: bool = False,
add_reaction: bool = True,
send_resolved_message: bool = True,
):
resolving_user = await env.db.user.find_unique(where={"slackId": resolver})
if not resolving_user:
await send_heartbeat(
@ -55,19 +62,21 @@ async def resolve(ts: str, resolver: str, client: AsyncWebClient, stale: bool =
)
return
await client.chat_postMessage(
channel=env.slack_help_channel,
text=env.transcript.ticket_resolve.format(user_id=resolver)
if not stale
else env.transcript.ticket_resolve_stale.format(user_id=resolver),
thread_ts=ts,
)
if send_resolved_message:
await client.chat_postMessage(
channel=env.slack_help_channel,
text=env.transcript.ticket_resolve.format(user_id=resolver)
if not stale
else env.transcript.ticket_resolve_stale.format(user_id=resolver),
thread_ts=ts,
)
await client.reactions_add(
channel=env.slack_help_channel,
name="white_check_mark",
timestamp=ts,
)
if add_reaction:
await client.reactions_add(
channel=env.slack_help_channel,
name="white_check_mark",
timestamp=ts,
)
await client.reactions_remove(
channel=env.slack_help_channel,

View file

@ -8,30 +8,31 @@ class Thread(Macro):
async def run(self, ticket, helper, **kwargs):
"""
A simple macro telling people to use threads
A macro that deletes the Nephthys message and removes the
reaction to avoid duplicate thread clutter
"""
sender = await env.db.user.find_first(where={"id": ticket.openedById})
if not sender:
return
user_info = await env.slack_client.users_info(user=sender.slackId)
name = (
user_info["user"]["profile"].get("display_name")
or user_info["user"]["profile"].get("real_name")
or user_info["user"]["name"]
)
await env.slack_client.chat_postMessage(
text=f"hey, {name}! would you mind asking your questions in the same thread? :rac_info: it helps us keep track of questions easier!\n\n(to use them, hover over the message and click :speech_balloon:)",
# Delete the first (FAQ) message sent by the bot
bot_info = await env.slack_client.auth_test()
bot_user_id = bot_info.get("user_id")
bot_messages = await env.slack_client.conversations_replies(
channel=env.slack_help_channel,
thread_ts=ticket.msgTs,
)
# Thread emoji (standard practice on Slack)
await env.slack_client.reactions_add(
channel=env.slack_help_channel,
name="thread",
timestamp=ticket.msgTs,
ts=ticket.msgTs,
)
for msg in bot_messages["messages"]:
if msg["user"] == bot_user_id:
await env.slack_client.chat_delete(
channel=env.slack_help_channel,
ts=msg["ts"],
)
await resolve(
ts=ticket.msgTs,
resolver=helper.slackId,
client=env.slack_client,
add_reaction=False,
send_resolved_message=False,
)