🛠️ refactor(file/topic): Рефакторинг кода для показа меню сообщений.

This commit is contained in:
Oscar
2026-05-26 17:23:16 +03:00
parent de6e193512
commit 6bd70a2e75
5 changed files with 339 additions and 208 deletions

View File

@@ -1,7 +1,7 @@
import bot from '@bot'
import prisma from '@prisma'
import { sendMenu } from './bot-menu'
import { triggerHHStart } from './hh/bot-commands.js'
import { registerHHCommands } from './hh/bot-commands.js'
registerHHCommands()
@@ -10,17 +10,11 @@ bot.onText(/\/start/, async (msg) => {
const chatId = msg.chat.id
const telegramId = BigInt(chatId)
const existingUser = await prisma.user.findUnique({
where: { telegramId },
})
const isFirstTime = !existingUser
const existingUser = await prisma.user.findUnique({ where: { telegramId } })
await prisma.user.upsert({
where: { telegramId },
update: {
username: msg.from?.username ?? null,
},
update: { username: msg.from?.username ?? null },
create: {
telegramId,
username: msg.from?.username ?? null,
@@ -29,7 +23,14 @@ bot.onText(/\/start/, async (msg) => {
},
})
await sendMenu(chatId, isFirstTime)
if (!existingUser) {
await bot.sendMessage(
chatId,
`👋 Привет, ${msg.from?.first_name ?? 'друг'}!\n\nЭто бот для авто-откликов на hh.ru.\nНачни с логина — нажми 🔑 Логин.`,
)
}
await triggerHHStart(chatId)
})
console.log('Bot started 🚀')