This commit is contained in:
2026-01-12 16:44:21 +03:00
parent c6faa19cb0
commit 8fe6857345
5 changed files with 51 additions and 58 deletions
-18
View File
@@ -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<void> {
const size = MessageStore.all().size;
MessageStore.clear();
await sendMessage({chatId: msg.chat.id, text: `Было удалено сообщений: ${size}`}).catch(logError);
}
}
-17
View File
@@ -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<void> {
const cacheSize = MessageStore.all();
await sendMessage({
chatId: msg.chat.id,
text: `Количество сохранённых сообщений: ${cacheSize.size}`
}).catch(logError);
}
}
+8 -8
View File
@@ -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;
}
+12 -12
View File
@@ -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}`);
+31 -3
View File
@@ -229,10 +229,18 @@ export async function sendErrorPlaceholder(message: Message): Promise<Message> {
export async function initSystemSpecs(): Promise<void> {
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);
@@ -729,3 +737,23 @@ export function buildExcludedSet<
return Object.fromEntries(entries) as Record<Exclude<K, E[number]>, 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 ?? "") };
}