Clear the search list after a pick, and stop double-announcing tracks

Two bits of clutter visible in one screenshot: the results list stayed in
the channel after a track was chosen, still wearing its reactions, and
every track produced two lines — the command's own reply and the player's
"now playing" notice.

Picking now spends the session and deletes the list, so a second reaction
does nothing and the message goes away. The player announces a track only
when it started one by itself; when a command started it, that command
has already said so.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Leonid Pershin
2026-09-09 06:04:17 +03:00
co-authored by Claude Opus 5
parent bf2d04d579
commit a63db8c957
3 changed files with 22 additions and 7 deletions
+11 -2
View File
@@ -81,13 +81,22 @@ function activeSession(messageId: string | undefined): SearchSession | null {
return session;
}
/** Resolves a reaction on a results message into the track it stands for. */
/**
* Resolves a reaction on a results message into the track it stands for, and
* spends the session: the list is answered once, so a second reaction on the
* same message does nothing and the message itself can go away.
*/
export function trackForReaction(messageId: string, userId: string, emoji: string): Track | null {
const session = activeSession(messageId);
// Only the person who searched picks; otherwise anyone could hijack the list.
if (!session || session.userId !== userId) return null;
const index = CHOICE_EMOJI.indexOf(emoji);
return index === -1 ? null : (session.tracks[index] ?? null);
const track = index === -1 ? null : (session.tracks[index] ?? null);
if (track) {
sessionsByMessage.delete(messageId);
latestByUser.delete(`${session.channelId}:${session.userId}`);
}
return track;
}
function added(track: Track, startedNow: boolean, position: number): string {