diff --git a/src/hh/bot-commands.ts b/src/hh/bot-commands.ts index 26ebf7b..5f7a1d5 100644 --- a/src/hh/bot-commands.ts +++ b/src/hh/bot-commands.ts @@ -13,6 +13,9 @@ interface UserState { awaitingPrompt: boolean pendingResumes: ResumeListItem[] loginPromptMessageId: number | null + queryPromptMessageId: number | null + maxPromptMessageId: number | null + promptPromptMessageId: number | null } function makeUserState(): UserState { @@ -24,6 +27,9 @@ function makeUserState(): UserState { awaitingPrompt: false, pendingResumes: [], loginPromptMessageId: null, + queryPromptMessageId: null, + maxPromptMessageId: null, + promptPromptMessageId: null, } } @@ -300,6 +306,24 @@ export function registerHHCommands() { break } + case 'hh_keep_query': + state.awaitingQuery = false + state.queryPromptMessageId = null + await bot.deleteMessage(chatId, messageId).catch(() => {}) + break + + case 'hh_keep_max': + state.awaitingMax = false + state.maxPromptMessageId = null + await bot.deleteMessage(chatId, messageId).catch(() => {}) + break + + case 'hh_keep_prompt': + state.awaitingPrompt = false + state.promptPromptMessageId = null + await bot.deleteMessage(chatId, messageId).catch(() => {}) + break + case 'hh_resume_list': await bot.deleteMessage(chatId, messageId).catch(() => {}) await handleResumeList(chatId) @@ -343,6 +367,30 @@ export function registerHHCommands() { const state = getState(chatId) + const isMenuButton = Object.values(BTN).includes(msg.text as typeof BTN[keyof typeof BTN]) + if (isMenuButton && (state.awaitingEmail || state.awaitingQuery || state.awaitingMax || state.awaitingPrompt)) { + state.awaitingEmail = false + state.awaitingQuery = false + state.awaitingMax = false + state.awaitingPrompt = false + if (state.loginPromptMessageId) { + await bot.deleteMessage(chatId, state.loginPromptMessageId).catch(() => {}) + state.loginPromptMessageId = null + } + if (state.queryPromptMessageId) { + await bot.deleteMessage(chatId, state.queryPromptMessageId).catch(() => {}) + state.queryPromptMessageId = null + } + if (state.maxPromptMessageId) { + await bot.deleteMessage(chatId, state.maxPromptMessageId).catch(() => {}) + state.maxPromptMessageId = null + } + if (state.promptPromptMessageId) { + await bot.deleteMessage(chatId, state.promptPromptMessageId).catch(() => {}) + state.promptPromptMessageId = null + } + } + if (state.awaitingEmail) { state.awaitingEmail = false await bot.deleteMessage(chatId, msg.message_id).catch(() => {}) @@ -357,6 +405,10 @@ export function registerHHCommands() { if (state.awaitingQuery) { state.awaitingQuery = false await bot.deleteMessage(chatId, msg.message_id).catch(() => {}) + if (state.queryPromptMessageId) { + await bot.deleteMessage(chatId, state.queryPromptMessageId).catch(() => {}) + state.queryPromptMessageId = null + } const updated = await prisma.settings.update({ where: { telegramId: chatId }, data: { searchQuery: msg.text }, @@ -373,6 +425,10 @@ export function registerHHCommands() { } state.awaitingMax = false await bot.deleteMessage(chatId, msg.message_id).catch(() => {}) + if (state.maxPromptMessageId) { + await bot.deleteMessage(chatId, state.maxPromptMessageId).catch(() => {}) + state.maxPromptMessageId = null + } const updated = await prisma.settings.update({ where: { telegramId: chatId }, data: { maxApplies: num }, @@ -384,6 +440,10 @@ export function registerHHCommands() { if (state.awaitingPrompt) { state.awaitingPrompt = false await bot.deleteMessage(chatId, msg.message_id).catch(() => {}) + if (state.promptPromptMessageId) { + await bot.deleteMessage(chatId, state.promptPromptMessageId).catch(() => {}) + state.promptPromptMessageId = null + } await prisma.user.upsert({ where: { telegramId: chatId }, update: { prompt: msg.text }, @@ -405,15 +465,42 @@ export function registerHHCommands() { case BTN.QUERY: { state.awaitingQuery = true const q = await prisma.settings.findFirst({ where: { telegramId: chatId } }) - await bot.sendMessage(chatId, `π Π’Π΅ΠΊΡΡΠΈΠΉ Π·Π°ΠΏΡΠΎΡ: ${q?.searchQuery || '--'}`) - await bot.sendMessage(chatId, 'π ΠΠ²Π΅Π΄ΠΈ Π½ΠΎΠ²ΡΠΉ ΠΏΠΎΠΈΡΠΊΠΎΠ²ΡΠΉ Π·Π°ΠΏΡΠΎΡ:') + const currentQuery = q?.searchQuery || '--' + const queryMsg = await bot.sendMessage( + chatId, + `π Π’Π΅ΠΊΡΡΠΈΠΉ Π·Π°ΠΏΡΠΎΡ: ${escapeHtml(currentQuery)}\n\nΠΠ²Π΅Π΄ΠΈ Π½ΠΎΠ²ΡΠΉ ΠΈΠ»ΠΈ ΠΎΡΡΠ°Π²Ρ ΡΠ΅ΠΊΡΡΠΈΠΉ:`, + { + parse_mode: 'HTML', + reply_markup: { + inline_keyboard: [[ + { text: `β ΠΡΡΠ°Π²ΠΈΡΡ Β«${currentQuery}Β»`, callback_data: 'hh_keep_query' }, + ]], + }, + }, + ) + state.queryPromptMessageId = queryMsg.message_id break } - case BTN.MAX: + case BTN.MAX: { state.awaitingMax = true - await bot.sendMessage(chatId, 'π’ ΠΠ²Π΅Π΄ΠΈ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΠΎΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΎΡΠΊΠ»ΠΈΠΊΠΎΠ² (1-50):') + const s = await prisma.settings.findFirst({ where: { telegramId: chatId } }) + const currentMax = s?.maxApplies ?? '--' + const maxMsg = await bot.sendMessage( + chatId, + `π’ Π’Π΅ΠΊΡΡΠ΅Π΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅: ${currentMax}\n\nΠΠ²Π΅Π΄ΠΈ Π½ΠΎΠ²ΠΎΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΎΡΠΊΠ»ΠΈΠΊΠΎΠ² (1β50) ΠΈΠ»ΠΈ ΠΎΡΡΠ°Π²Ρ ΡΠ΅ΠΊΡΡΠ΅Π΅:`, + { + parse_mode: 'HTML', + reply_markup: { + inline_keyboard: [[ + { text: `β ΠΡΡΠ°Π²ΠΈΡΡ ${currentMax}`, callback_data: 'hh_keep_max' }, + ]], + }, + }, + ) + state.maxPromptMessageId = maxMsg.message_id break + } case BTN.AUTO_TOGGLE: { const s = getState(chatId) @@ -446,8 +533,18 @@ export function registerHHCommands() { case BTN.PROMPT: { state.awaitingPrompt = true const user = await prisma.user.findUnique({ where: { telegramId: chatId } }) - const current = user?.prompt ? `\n\nΠ’Π΅ΠΊΡΡΠΈΠΉ:\n
${escapeHtml(user.prompt)}` : ''
- await bot.sendMessage(chatId, `π ΠΠ²Π΅Π΄ΠΈ Π½ΠΎΠ²ΡΠΉ ΠΏΡΠΎΠΌΡ Π΄Π»Ρ AI:${current}`, { parse_mode: 'HTML' })
+ const currentPrompt = user?.prompt
+ const promptText = currentPrompt
+ ? `π Π’Π΅ΠΊΡΡΠΈΠΉ ΠΏΡΠΎΠΌΡ:\n${escapeHtml(currentPrompt)}\n\nΠΠ²Π΅Π΄ΠΈ Π½ΠΎΠ²ΡΠΉ ΠΈΠ»ΠΈ ΠΎΡΡΠ°Π²Ρ ΡΠ΅ΠΊΡΡΠΈΠΉ:`
+ : 'π ΠΠ²Π΅Π΄ΠΈ ΠΏΡΠΎΠΌΡ Π΄Π»Ρ AI (ΠΏΠΎΠΊΠ° Π½Π΅ Π·Π°Π΄Π°Π½):'
+ const keepButton = currentPrompt
+ ? [[{ text: 'β
ΠΡΡΠ°Π²ΠΈΡΡ ΡΠ΅ΠΊΡΡΠΈΠΉ ΠΏΡΠΎΠΌΡ', callback_data: 'hh_keep_prompt' }]]
+ : []
+ const promptMsg = await bot.sendMessage(chatId, promptText, {
+ parse_mode: 'HTML',
+ reply_markup: { inline_keyboard: keepButton },
+ })
+ state.promptPromptMessageId = promptMsg.message_id
break
}