From d8046cc88d2b05a3352f66499d219e1a39e8fc69 Mon Sep 17 00:00:00 2001 From: devmhand Date: Fri, 27 Feb 2026 18:12:00 +0400 Subject: [PATCH] armyan update --- .gitignore | 3 +- bot.js | 75 ++++++++++++++++++++++++++++++++++++++++++-- package.json | 1 + src/routes/upload.js | 6 +++- 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index f05270a..4645c4e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ dist package-lock.json *.ogg *.wav -*.mp3 \ No newline at end of file +*.mp3 +*.oga \ No newline at end of file diff --git a/bot.js b/bot.js index 66ac1c2..fd19f4c 100644 --- a/bot.js +++ b/bot.js @@ -1,6 +1,9 @@ import TelegramBot from "node-telegram-bot-api"; import dotenv from "dotenv"; import axios from "axios"; +import FormData from 'form-data'; +import fs from 'fs'; + import { UserRepository } from "./user.repository.js"; @@ -24,6 +27,11 @@ bot.onText(/\/info/, (msg)=>{ bot.sendMessage(chatId, message) }) +bot.onText(/\/armyan (.+)/, async(msg, match)=>{ + const chatId = msg.chat.id; + const textAfterCommand = match[1]; +}) + bot.onText(/\/start/, async(msg) => { const chatId = msg.chat.id; @@ -46,22 +54,61 @@ bot.on('message', async(msg) => { const chatId = msg.chat.id; const user = msg.from + console.log(user) + console.log(msg) if (msg.text && msg.text.startsWith('/')) { return; } if (msg.photo) { - bot.sendMessage(chatId, 'Красиво, но такое мне не надо'); + bot.sendMessage(chatId, 'Красиво, но такое мне не надо', {reply_to_message_id: msg.message_id}); return; } if (msg.document) { - bot.sendMessage(chatId, 'Такое мне не надо'); + bot.sendMessage(chatId, 'Такое мне не надо', {reply_to_message_id: msg.message_id}); return; } - if (msg.text) { + if (msg.from.is_bot){ + bot.sendMessage(chatId, 'Пошел нахуй бот ебанный, не мешай слушать брата', {reply_to_message_id: msg.message_id}); + return; + } + + if (msg.voice ){ + const fileId = msg.voice.file_id; + + const filePath = await bot.downloadFile(fileId, './voices'); + + const form = new FormData(); + form.append('file', fs.createReadStream(filePath)); + + const response = await axios.post( + 'http://10.8.1.2:3000/upload', + form, + { + headers: form.getHeaders() + } + ); + + if(response.status === 200){ + const recognizedText = response.data.text; + bot.sendMessage(chatId, recognizedText, {reply_to_message_id: msg.message_id}); + }else{ + bot.sendMessage(chatId, 'Что-то пошло не так', {reply_to_message_id: msg.message_id}); + } + return; + } + + if (msg.text && user.id === 5536333712){ + console.log('Армянин, переключаем модель') + const response = await switchToRussian(msg.text); + bot.sendMessage(chatId, response.message, {reply_to_message_id: msg.message_id}); + return; + } + + if (msg.text && msg.chat.type === 'private') { //bot.sendMessage(chatId, `Ты написал: ${msg.text}`); try{ const last_msg_context = await UserRepository.getContext(user.id) || '' @@ -84,6 +131,28 @@ bot.on('message', async(msg) => { } }); +async function switchToRussian(message){ + try{ + const options = { + method:'POST', + url:`https://agent.timeweb.cloud/api/v1/cloud-ai/agents/${accessId}/call`, + headers: { + Authorization: `Bearer ${tokenAi}`, + 'x-proxy-source': '', + 'Content-Type': 'application/json' + }, + data:{ + message: `Убери ошибки в тексте и поставь знаки препинания: "${message}". Если текст короткий или без явных ошибок ничего не делай и отвечай просто "Армянин молодец", особо не размышляй над содержимым текста, просто выполняй свою задачу. Так же делай рядом версию с переводом на армянский язык`, + parent_message_id: '' + } + } + const response = await axios.request(options); + return response.data; + }catch(err){ + console.error('Ошибка при получении ответа от AI:', err); + } +} + async function getAIResponse(message, context) { try{ const options = { diff --git a/package.json b/package.json index 9306b44..18d6934 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "cors": "^2.8.6", "dotenv": "^17.2.3", "express": "^5.2.1", + "form-data": "^4.0.5", "jsonwebtoken": "^9.0.3", "multer": "^2.0.2", "node-telegram-bot-api": "^0.67.0", diff --git a/src/routes/upload.js b/src/routes/upload.js index 12b0ccf..dffd27a 100644 --- a/src/routes/upload.js +++ b/src/routes/upload.js @@ -23,7 +23,7 @@ async function shneine(fileName, mimeType){ model: "gemini-3-flash-preview", contents: createUserContent([ createPartFromUri(myfile.uri, myfile.mimeType), - 'Нужно сделать анализ аудиофайла, краткую выжимку самого важного, вывести тезисы.' + 'Что дословно говорится в этом аудиофайле? отвечай сухо, чисто текст, может исправить ошибки в тексте и поставить знаки препинания. Если звуковая дорожка маленькая 1-2 секунды и в ней нету слов или не понятна, отвечай "Армянин молодец, напердел". Так же делай рядом версию с переводом на армянский язык' ]) }) return response.text; @@ -82,5 +82,9 @@ router.post( } ); +router.post('/voice', async(req, res) => { + +}) + export default router;