mirror of
https://github.com/hempyhemp/hh-auto-reply.git
synced 2026-06-08 18:04:57 +00:00
init
This commit is contained in:
35
src/index.ts
Normal file
35
src/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import bot from '@bot'
|
||||
import prisma from '@prisma'
|
||||
|
||||
import { sendMenu } from './bot-menu'
|
||||
import { registerHHCommands } from './hh/bot-commands.js'
|
||||
|
||||
registerHHCommands()
|
||||
|
||||
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
|
||||
|
||||
await prisma.user.upsert({
|
||||
where: { telegramId },
|
||||
update: {
|
||||
username: msg.from?.username ?? null,
|
||||
},
|
||||
create: {
|
||||
telegramId,
|
||||
username: msg.from?.username ?? null,
|
||||
firstName: msg.from?.first_name ?? null,
|
||||
Settings: { create: {} },
|
||||
},
|
||||
})
|
||||
|
||||
await sendMenu(chatId, isFirstTime)
|
||||
})
|
||||
|
||||
console.log('Bot started 🚀')
|
||||
Reference in New Issue
Block a user