Answer the search command immediately, and don't wait on a slow source
A search looked like it did nothing: the log shows the two sources finishing 21 seconds apart, and since the command message is deleted on sight, the channel stayed empty that whole time with no sign the bot had heard anything. The reply now goes out at once as "Ищу …" and is edited into the results, so there is always something on screen, and each source gets 12 seconds before the answer goes out without it — searching several at once otherwise means always waiting for the slowest, which behind a proxy is tens of seconds. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
e7e80e704b
commit
bf2d04d579
+13
-3
@@ -13,10 +13,11 @@ import {
|
||||
trackTitle,
|
||||
} from "./format.js";
|
||||
|
||||
/** What we need back from a sent message to hang reactions on it. */
|
||||
/** What we need back from a sent message to work with it afterwards. */
|
||||
export interface SentMessage {
|
||||
id: string;
|
||||
react(emoji: string): Promise<void>;
|
||||
edit(content: string): Promise<void>;
|
||||
}
|
||||
|
||||
export interface CommandContext {
|
||||
@@ -170,18 +171,27 @@ export const commands: Command[] = [
|
||||
description: "Найти треки и выбрать реакцией",
|
||||
async run(ctx) {
|
||||
if (!ctx.rest) throw new UserFacingError("Укажите поисковый запрос");
|
||||
// Searching several sources can take tens of seconds through a proxy, and
|
||||
// the command message is already deleted by then — without a placeholder
|
||||
// the chat sits silent and the bot looks broken.
|
||||
const placeholder = await ctx.reply(`🔎 Ищу **${ctx.rest}**…`);
|
||||
|
||||
const tracks = (await ctx.manager.search(ctx.rest, ctx.actor, CHAT_SEARCH_LIMIT)).slice(
|
||||
0,
|
||||
CHAT_SEARCH_LIMIT,
|
||||
);
|
||||
if (tracks.length === 0) {
|
||||
await ctx.reply(`🔎 ${NOTHING_FOUND}`);
|
||||
const missing = `🔎 ${NOTHING_FOUND}`;
|
||||
if (placeholder) await placeholder.edit(missing);
|
||||
else await ctx.reply(missing);
|
||||
return;
|
||||
}
|
||||
|
||||
const lines = tracks.map((track, index) => trackLine(track, { index: index + 1 }));
|
||||
const sent = await ctx.reply(`🔎 **${ctx.rest}**\n${lines.join("\n")}`);
|
||||
const text = `🔎 **${ctx.rest}**\n${lines.join("\n")}`;
|
||||
const sent = placeholder ?? (await ctx.reply(text));
|
||||
if (!sent) return;
|
||||
if (placeholder) await placeholder.edit(text);
|
||||
|
||||
rememberSearch(ctx, sent.id, tracks);
|
||||
for (const emoji of CHOICE_EMOJI.slice(0, tracks.length)) {
|
||||
|
||||
Reference in New Issue
Block a user