From 8fe68573456a94e29a3a0f4fc4bde3ba390499ba Mon Sep 17 00:00:00 2001 From: Danil Nikolaev Date: Mon, 12 Jan 2026 16:44:21 +0300 Subject: [PATCH] updates --- src/commands/cache-clear.ts | 18 ------------------ src/commands/cache-size.ts | 17 ----------------- src/common/environment.ts | 16 ++++++++-------- src/index.ts | 24 ++++++++++++------------ src/util/utils.ts | 34 +++++++++++++++++++++++++++++++--- 5 files changed, 51 insertions(+), 58 deletions(-) delete mode 100644 src/commands/cache-clear.ts delete mode 100644 src/commands/cache-size.ts diff --git a/src/commands/cache-clear.ts b/src/commands/cache-clear.ts deleted file mode 100644 index c29560a..0000000 --- a/src/commands/cache-clear.ts +++ /dev/null @@ -1,18 +0,0 @@ -import {ChatCommand} from "../base/chat-command"; -import {Message} from "typescript-telegram-bot-api"; -import {MessageStore} from "../common/message-store"; -import {logError, sendMessage} from "../util/utils"; -import {Requirements} from "../base/requirements"; -import {Requirement} from "../base/requirement"; - -export class CacheClear extends ChatCommand { - regexp = /^\/clearcache$/i; - - requirements = Requirements.Build(Requirement.BOT_CREATOR); - - async execute(msg: Message): Promise { - const size = MessageStore.all().size; - MessageStore.clear(); - await sendMessage({chatId: msg.chat.id, text: `Было удалено сообщений: ${size}`}).catch(logError); - } -} \ No newline at end of file diff --git a/src/commands/cache-size.ts b/src/commands/cache-size.ts deleted file mode 100644 index 82b1e27..0000000 --- a/src/commands/cache-size.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {ChatCommand} from "../base/chat-command"; -import {Message} from "typescript-telegram-bot-api"; -import {logError, sendMessage} from "../util/utils"; -import {MessageStore} from "../common/message-store"; - -export class CacheSize extends ChatCommand { - regexp = /^\/cachesize$/i; - - async execute(msg: Message): Promise { - const cacheSize = MessageStore.all(); - - await sendMessage({ - chatId: msg.chat.id, - text: `Количество сохранённых сообщений: ${cacheSize.size}` - }).catch(logError); - } -} \ No newline at end of file diff --git a/src/common/environment.ts b/src/common/environment.ts index 970b3c2..7fb14a0 100644 --- a/src/common/environment.ts +++ b/src/common/environment.ts @@ -17,12 +17,12 @@ export class Environment { static USE_DAD: boolean; static USE_FU: boolean; - static OLLAMA_MODEL: string; - static OLLAMA_ADDRESS: string; + static OLLAMA_MODEL?: string; + static OLLAMA_ADDRESS?: string; static OLLAMA_API_KEY?: string; - static SYSTEM_PROMPT: string; + static SYSTEM_PROMPT?: string; - static GEMINI_API_KEY: string; + static GEMINI_API_KEY?: string; static waitText = "⏳ Дайте-ка подумать..."; @@ -33,17 +33,17 @@ export class Environment { Environment.BOT_PREFIX = process.env.BOT_PREFIX || ""; Environment.CREATOR_ID = parseInt(process.env.CREATOR_ID || ""); Environment.IS_DOCKER = process.env.IS_DOCKER == "true"; - Environment.DATA_PATH = Environment.IS_DOCKER ? "/" + path.join("", "config", "data") : "data"; + Environment.DATA_PATH = Environment.IS_DOCKER ? "/" + path.join("config", "data") : "data"; Environment.DB_PATH = "file:" + path.join(Environment.DATA_PATH, Environment.DB_FILE_NAME); Environment.USE_MOM = process.env.USE_MOM == "true"; Environment.USE_DAD = process.env.USE_DAD == "true"; Environment.USE_FU = process.env.USE_FU == "true"; - Environment.OLLAMA_MODEL = process.env.OLLAMA_MODEL || "llama3.2"; - Environment.OLLAMA_ADDRESS = process.env.OLLAMA_ADDRESS || "127.0.0.1"; + Environment.OLLAMA_MODEL = process.env.OLLAMA_MODEL; + Environment.OLLAMA_ADDRESS = process.env.OLLAMA_ADDRESS; Environment.OLLAMA_API_KEY = process.env.OLLAMA_API_KEY; - Environment.SYSTEM_PROMPT = (process.env.SYSTEM_PROMPT?.trim()) || ""; + Environment.SYSTEM_PROMPT = process.env.SYSTEM_PROMPT?.trim(); Environment.GEMINI_API_KEY = process.env.GEMINI_API_KEY; } diff --git a/src/index.ts b/src/index.ts index e7366af..22c47f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,8 +46,6 @@ import {Choice} from "./commands/choice"; import {Coin} from "./commands/coin"; import {Qr} from "./commands/qr"; import {Distort} from "./commands/distort"; -import {CacheSize} from "./commands/cache-size"; -import {CacheClear} from "./commands/cache-clear"; import {Dice} from "./commands/dice"; import {Unban} from "./commands/unban"; import {Title} from "./commands/title"; @@ -113,18 +111,20 @@ export const chatCommands: ChatCommand[] = [ new Shutdown(), new Leave(), - - new OllamaChat(), - new OllamaSearch(), - new OllamaPrompt(), - new OllamaKill(), - - new GeminiChat(), - - new CacheSize(), - new CacheClear() ]; +if (Environment.OLLAMA_ADDRESS && Environment.OLLAMA_MODEL && Environment.SYSTEM_PROMPT) { + chatCommands.push(new OllamaChat(), new OllamaPrompt(), new OllamaKill()); +} + +if (Environment.OLLAMA_API_KEY) { + chatCommands.push(new OllamaSearch()); +} + +if (Environment.GEMINI_API_KEY) { + chatCommands.push(new GeminiChat()); +} + async function main() { console.log(`TEST_ENVIRONMENT: ${Environment.TEST_ENVIRONMENT}\nDATA_PATH: ${Environment.DATA_PATH}`); diff --git a/src/util/utils.ts b/src/util/utils.ts index cdfdd61..fcc4105 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -229,10 +229,18 @@ export async function sendErrorPlaceholder(message: Message): Promise { export async function initSystemSpecs(): Promise { try { const [os, cpu, mem] = await Promise.all([si.osInfo(), si.cpu(), si.mem()]); - setSystemSpecs(`OS: ${os.distro}\n` + + const run = getRuntimeInfo(); + + const ramSize = (mem.total / 1024 / 1024 / 1024).toFixed(2); + + const text = + `OS: ${os.distro}\n` + + `RUNTIME: ${run.runtime} ${run.version}\n` + + `DOCKER: ${Environment.IS_DOCKER}\n` + `CPU: ${cpu.manufacturer} ${cpu.brand} ${cpu.physicalCores} cores ${cpu.cores} threads\n` + - `RAM: ${Math.round(mem.total / Math.pow(2, 30))} GB` - ); + `RAM: ${ramSize} GB`; + + setSystemSpecs(text); return Promise.resolve(); } catch (e) { return Promise.reject(e); @@ -728,4 +736,24 @@ export function buildExcludedSet< }); return Object.fromEntries(entries) as Record, SQL>; +} + +type RuntimeInfo = + | { runtime: "bun"; version: string } + | { runtime: "node"; version: string } + | { runtime: "unknown"; version: string }; + +export function getRuntimeInfo(): RuntimeInfo { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const v = (process as any).versions ?? {}; + + if (typeof v.bun === "string") { + return { runtime: "bun", version: v.bun }; + } + if (typeof v.node === "string") { + return { runtime: "node", version: v.node }; + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return { runtime: "unknown", version: String((process as any).version ?? "") }; } \ No newline at end of file