mirror of
https://github.com/hempyhemp/hh-auto-reply.git
synced 2026-06-08 18:04:57 +00:00
🛠️ refactor(file/topic): Рефакторинг кода для показа меню сообщений.
This commit is contained in:
21
src/index.ts
21
src/index.ts
@@ -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 🚀')
|
||||
|
||||
Reference in New Issue
Block a user