diff --git a/src/commands/system-info.ts b/src/commands/system-info.ts index 5b1a5c9..6ffc084 100644 --- a/src/commands/system-info.ts +++ b/src/commands/system-info.ts @@ -1,13 +1,18 @@ import {ChatCommand} from "../base/chat-command"; -import {logError, oldSendMessage} from "../util/utils"; +import {logError, replyToMessage} from "../util/utils"; import {Message} from "typescript-telegram-bot-api"; -import {systemInfoText} from "../index"; export class SystemInfo extends ChatCommand { title = "/systemInfo"; description = "System information"; + private static systemInfoText: string; + + static setSystemInfo(info: string) { + SystemInfo.systemInfoText = info; + } + async execute(msg: Message) { - await oldSendMessage(msg, systemInfoText).catch(logError); + await replyToMessage({message: msg, text: SystemInfo.systemInfoText}).catch(logError); } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 83c854a..d8075cc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -117,12 +117,6 @@ export function abortOllamaRequest(uuid: string): boolean { } } -export let systemInfoText: string = ""; - -export function setSystemInfo(info: string) { - systemInfoText = info; -} - export const chatCommands: ChatCommand[] = [ new Start(), new Help(), diff --git a/src/util/utils.ts b/src/util/utils.ts index 1454258..7a56240 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -12,7 +12,7 @@ import { } from "typescript-telegram-bot-api"; import {Environment} from "../common/environment"; import {TelegramError} from "typescript-telegram-bot-api/dist/errors"; -import {bot, botUser, messageDao, setSystemInfo} from "../index"; +import {bot, botUser, messageDao} from "../index"; import os from "os"; import axios from "axios"; import {MessagePart} from "../common/message-part"; @@ -24,6 +24,7 @@ import {sql, type SQL} from "drizzle-orm"; import fs from "node:fs"; import path from "node:path"; import {MessageStore} from "../common/message-store"; +import {SystemInfo} from "../commands/system-info"; export const ignore = () => { }; @@ -252,6 +253,7 @@ export type SendOptions = { message_id?: number; text: string, parse_mode?: ParseMode, + disableLinkPreview?: boolean }; export async function oldSendMessage(message: Message, text: string, parseMode?: ParseMode): Promise { @@ -268,7 +270,10 @@ export async function sendMessage(options: SendOptions): Promise { const response = await bot.sendMessage({ chat_id: options.chat_id ?? options.message?.chat?.id, text: options.text, - parse_mode: options.parse_mode + parse_mode: options.parse_mode, + link_preview_options: { + is_disabled: options.disableLinkPreview + } }); return Promise.resolve(response); @@ -281,6 +286,9 @@ export async function replyToMessage(options: SendOptions): Promise { parse_mode: options.parse_mode, reply_parameters: { message_id: options.message_id || options.message?.message_id + }, + link_preview_options: { + is_disabled: options.disableLinkPreview } }); @@ -318,7 +326,7 @@ export async function initSystemSpecs(): Promise { `CPU: ${cpu.manufacturer} ${cpu.brand} ${cpu.physicalCores} cores ${cpu.cores} threads\n` + `RAM: ${ramSize} GB`; - setSystemInfo(text); + SystemInfo.setSystemInfo(text); return Promise.resolve(); } catch (e) { return Promise.reject(e);