* environment variable to enable/disable processing links in messages (for downloading videos)
* bot will not automatically download video from youtube or load it from cache. It will fetch video info first, then suggest to download or get video from cache (with retry options) * some rewriting in sending/editing/replying to messages
This commit is contained in:
@@ -80,7 +80,7 @@ export class GeminiChat extends ChatCommand {
|
||||
try {
|
||||
waitMessage = await bot.sendMessage({
|
||||
chat_id: chatId,
|
||||
text: Environment.waitText,
|
||||
text: Environment.waitThinkText,
|
||||
reply_parameters: {
|
||||
chat_id: chatId,
|
||||
message_id: msg.message_id
|
||||
|
||||
@@ -53,7 +53,7 @@ export class GeminiGenerateImage extends Command {
|
||||
await replyToMessage({
|
||||
message: waitMessage,
|
||||
text: `Произошла ошибка!\n${e.toString()}`,
|
||||
disableLinkPreview: true
|
||||
link_preview_options: {is_disabled: true}
|
||||
}).catch(logError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ export class MistralChat extends ChatCommand {
|
||||
chat_id: chatId,
|
||||
text: imagesCount ?
|
||||
imagesCount > 1 ? Environment.analyzingPicturesText : Environment.analyzingPictureText
|
||||
: Environment.waitText,
|
||||
: Environment.waitThinkText,
|
||||
|
||||
reply_parameters: {
|
||||
chat_id: chatId,
|
||||
|
||||
@@ -96,7 +96,7 @@ export class OllamaChat extends ChatCommand {
|
||||
message: msg,
|
||||
text: (!think && imagesCount) ?
|
||||
imagesCount > 1 ? Environment.analyzingPicturesText : Environment.analyzingPictureText
|
||||
: Environment.waitText
|
||||
: Environment.waitThinkText
|
||||
});
|
||||
|
||||
const stream = await ollama.chat({
|
||||
|
||||
@@ -37,7 +37,7 @@ export class OllamaPrompt extends Command {
|
||||
|
||||
waitMessage = await bot.sendMessage({
|
||||
chat_id: chatId,
|
||||
text: Environment.waitText,
|
||||
text: Environment.waitThinkText,
|
||||
reply_parameters: {
|
||||
chat_id: chatId,
|
||||
message_id: msg.message_id
|
||||
|
||||
@@ -4,7 +4,7 @@ import {Requirement} from "../base/requirement";
|
||||
import {Message} from "typescript-telegram-bot-api";
|
||||
import {bot, ollama} from "../index";
|
||||
import {WebSearchResponse} from "../model/web-search-response";
|
||||
import {editMessageText, logError} from "../util/utils";
|
||||
import {oldEditMessageText, logError} from "../util/utils";
|
||||
import {Environment} from "../common/environment";
|
||||
|
||||
export class OllamaSearch extends Command {
|
||||
@@ -23,7 +23,7 @@ export class OllamaSearch extends Command {
|
||||
try {
|
||||
const wait = await bot.sendMessage({
|
||||
chat_id: chatId,
|
||||
text: Environment.waitText,
|
||||
text: Environment.waitThinkText,
|
||||
reply_parameters: {
|
||||
chat_id: chatId,
|
||||
message_id: msg.message_id
|
||||
@@ -40,7 +40,7 @@ export class OllamaSearch extends Command {
|
||||
message += `${index + 1}. ${r.url}\n`;
|
||||
});
|
||||
|
||||
await editMessageText(chatId, wait.message_id, message);
|
||||
await oldEditMessageText(chatId, wait.message_id, message);
|
||||
} catch (error) {
|
||||
logError(error);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ export class OpenAIChat extends ChatCommand {
|
||||
try {
|
||||
waitMessage = await bot.sendMessage({
|
||||
chat_id: chatId,
|
||||
text: Environment.waitText,
|
||||
text: Environment.waitThinkText,
|
||||
reply_parameters: {
|
||||
chat_id: chatId,
|
||||
message_id: msg.message_id
|
||||
|
||||
@@ -5,7 +5,7 @@ import {Requirement} from "../base/requirement";
|
||||
import {bot, openAi, photoGenDir} from "../index";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import {editMessageText, logError, replyToMessage} from "../util/utils";
|
||||
import {oldEditMessageText, logError, replyToMessage} from "../util/utils";
|
||||
import {Environment} from "../common/environment";
|
||||
import {APIError} from "openai";
|
||||
|
||||
@@ -102,7 +102,7 @@ export class OpenAIGenImage extends ChatCommand {
|
||||
const text = "❌ Мне запрещено такое генерировать 😠";
|
||||
|
||||
if (waitMessage) {
|
||||
await editMessageText(msg.chat.id, waitMessage.message_id, text).catch(logError);
|
||||
await oldEditMessageText(msg.chat.id, waitMessage.message_id, text).catch(logError);
|
||||
} else {
|
||||
await replyToMessage({message: msg, text: text}).catch(logError);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import {Command} from "../base/command";
|
||||
import {Message} from "typescript-telegram-bot-api";
|
||||
import {logError, replyToMessage} from "../util/utils";
|
||||
import {bot} from "../index";
|
||||
import {downloadVideoFromYouTube} from "../util/ytdl";
|
||||
import {editMessageText, logError, replyToMessage} from "../util/utils";
|
||||
import {bot, botUser} from "../index";
|
||||
import {DownloadOptions, downloadVideoFromYouTube, getYouTubeVideoId} from "../util/ytdl";
|
||||
import {Environment} from "../common/environment";
|
||||
import {TryAgain} from "../callback_commands/try-again";
|
||||
|
||||
export class YouTubeDownload extends Command {
|
||||
command = ["ytdl", "youtube"];
|
||||
@@ -10,16 +12,22 @@ export class YouTubeDownload extends Command {
|
||||
|
||||
async execute(msg: Message, match?: RegExpExecArray): Promise<void> {
|
||||
const url = match?.[3];
|
||||
return this.downloadYouTubeVideo(msg, url);
|
||||
return this.downloadYouTubeVideo(msg, {url: url});
|
||||
}
|
||||
|
||||
async downloadYouTubeVideo(msg: Message, url: string): Promise<void> {
|
||||
let waitMessage: Message | null = null;
|
||||
async downloadYouTubeVideo(msg: Message, options: DownloadOptions): Promise<void> {
|
||||
// TODO: 02.03.2026, Danil Nikolaev: add check for date
|
||||
let waitMessage: Message | null = (msg.from.id === botUser.id) ? msg : null;
|
||||
const videoId = "videoId" in options ? options.videoId : getYouTubeVideoId(options.url);
|
||||
|
||||
try {
|
||||
waitMessage = await replyToMessage({message: msg, text: "⏳ Секунду..."});
|
||||
if (!waitMessage) {
|
||||
waitMessage = await replyToMessage({message: msg, text: Environment.waitText});
|
||||
} else {
|
||||
await editMessageText({message: msg, text: Environment.waitText});
|
||||
}
|
||||
|
||||
const {time, exists, buffer} = await downloadVideoFromYouTube(url);
|
||||
const {time, exists, buffer} = await downloadVideoFromYouTube({videoId: videoId});
|
||||
if (buffer) {
|
||||
const start = Date.now();
|
||||
waitMessage = await bot.editMessageMedia({
|
||||
@@ -35,7 +43,7 @@ export class YouTubeDownload extends Command {
|
||||
waitMessage = await bot.editMessageCaption({
|
||||
chat_id: msg.chat.id,
|
||||
message_id: waitMessage.message_id,
|
||||
caption: `✅ [Видео](${url})` + (exists ? " загружено из кэша" : " успешно скачано") + " за " + (time + diff) + "мс",
|
||||
caption: "✅ [Видео]" + (exists ? " загружено из кэша" : " успешно скачано") + " за " + (time + diff) + "мс",
|
||||
parse_mode: "MarkdownV2"
|
||||
}) as Message;
|
||||
}
|
||||
@@ -46,7 +54,12 @@ export class YouTubeDownload extends Command {
|
||||
await bot.editMessageText({
|
||||
chat_id: msg.chat.id,
|
||||
message_id: waitMessage.message_id,
|
||||
text: `⚠️ Произошла ошибка.\n${e}`,
|
||||
text: Environment.errorText,
|
||||
reply_markup: {
|
||||
inline_keyboard: [[
|
||||
TryAgain.withData("/ytdl " + videoId).asButton()
|
||||
]]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user