🔧 refactor(bot-commands): Убран лишний код, оптимизированы импорты и функции.

This commit is contained in:
Oscar
2026-05-26 17:46:51 +03:00
parent 6bd70a2e75
commit d2a49cb1eb
9 changed files with 180 additions and 210 deletions

77
src/hh/ui.ts Normal file
View File

@@ -0,0 +1,77 @@
import bot from '@bot'
export const MAIN_MARKUP = {
inline_keyboard: [
[{ text: '🚀 Откликнуться сейчас', callback_data: 'hh_apply' }],
[
{ text: '🔍 Изменить запрос', callback_data: 'hh_query' },
{ text: '🔢 Макс откликов', callback_data: 'hh_max' },
],
[
{ text: '⏰ Авто вкл', callback_data: 'hh_auto_start' },
{ text: '⛔ Авто выкл', callback_data: 'hh_auto_stop' },
],
[
{ text: '🔑 Логин', callback_data: 'hh_login' },
{ text: '⚙️ Статус', callback_data: 'hh_status' },
],
[
{ text: '📄 Выбрать резюме', callback_data: 'hh_resume_list' },
{ text: '📋 Моё резюме', callback_data: 'hh_my_resume' },
],
],
}
export const LOGIN_MARKUP = {
inline_keyboard: [
[{ text: '🔑 Войти через hh.ru', callback_data: 'hh_login' }],
],
}
export const BACK_MARKUP = {
inline_keyboard: [[{ text: '◀️ Назад', callback_data: 'hh_back' }]],
}
export function escapeHtml(text: string): string {
return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
}
export async function showResult(chatId: number, messageId: number, text: string): Promise<void> {
await bot.editMessageText(text, {
chat_id: chatId,
message_id: messageId,
reply_markup: BACK_MARKUP,
})
}
export interface StatusReporter {
status: (text: string) => Promise<void>
keep: (text: string) => Promise<void>
clear: () => Promise<void>
}
export function createStatusReporter(chatId: number, initialMsgId?: number | null): StatusReporter {
let msgId: number | null = initialMsgId ?? null
async function deleteCurrent(): Promise<void> {
if (msgId) {
await bot.deleteMessage(chatId, msgId).catch(() => {})
msgId = null
}
}
return {
async status(text): Promise<void> {
await deleteCurrent()
const msg = await bot.sendMessage(chatId, text)
msgId = msg.message_id
},
async keep(text): Promise<void> {
await deleteCurrent()
await bot.sendMessage(chatId, text, { parse_mode: 'HTML' })
},
async clear(): Promise<void> {
await deleteCurrent()
},
}
}