updates
This commit is contained in:
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,12 +17,12 @@ export class Environment {
|
|||||||
static USE_DAD: boolean;
|
static USE_DAD: boolean;
|
||||||
static USE_FU: boolean;
|
static USE_FU: boolean;
|
||||||
|
|
||||||
static OLLAMA_MODEL: string;
|
static OLLAMA_MODEL?: string;
|
||||||
static OLLAMA_ADDRESS: string;
|
static OLLAMA_ADDRESS?: string;
|
||||||
static OLLAMA_API_KEY?: 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 = "⏳ Дайте-ка подумать...";
|
static waitText = "⏳ Дайте-ка подумать...";
|
||||||
|
|
||||||
@@ -33,17 +33,17 @@ export class Environment {
|
|||||||
Environment.BOT_PREFIX = process.env.BOT_PREFIX || "";
|
Environment.BOT_PREFIX = process.env.BOT_PREFIX || "";
|
||||||
Environment.CREATOR_ID = parseInt(process.env.CREATOR_ID || "");
|
Environment.CREATOR_ID = parseInt(process.env.CREATOR_ID || "");
|
||||||
Environment.IS_DOCKER = process.env.IS_DOCKER == "true";
|
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.DB_PATH = "file:" + path.join(Environment.DATA_PATH, Environment.DB_FILE_NAME);
|
||||||
|
|
||||||
Environment.USE_MOM = process.env.USE_MOM == "true";
|
Environment.USE_MOM = process.env.USE_MOM == "true";
|
||||||
Environment.USE_DAD = process.env.USE_DAD == "true";
|
Environment.USE_DAD = process.env.USE_DAD == "true";
|
||||||
Environment.USE_FU = process.env.USE_FU == "true";
|
Environment.USE_FU = process.env.USE_FU == "true";
|
||||||
|
|
||||||
Environment.OLLAMA_MODEL = process.env.OLLAMA_MODEL || "llama3.2";
|
Environment.OLLAMA_MODEL = process.env.OLLAMA_MODEL;
|
||||||
Environment.OLLAMA_ADDRESS = process.env.OLLAMA_ADDRESS || "127.0.0.1";
|
Environment.OLLAMA_ADDRESS = process.env.OLLAMA_ADDRESS;
|
||||||
Environment.OLLAMA_API_KEY = process.env.OLLAMA_API_KEY;
|
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;
|
Environment.GEMINI_API_KEY = process.env.GEMINI_API_KEY;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-12
@@ -46,8 +46,6 @@ import {Choice} from "./commands/choice";
|
|||||||
import {Coin} from "./commands/coin";
|
import {Coin} from "./commands/coin";
|
||||||
import {Qr} from "./commands/qr";
|
import {Qr} from "./commands/qr";
|
||||||
import {Distort} from "./commands/distort";
|
import {Distort} from "./commands/distort";
|
||||||
import {CacheSize} from "./commands/cache-size";
|
|
||||||
import {CacheClear} from "./commands/cache-clear";
|
|
||||||
import {Dice} from "./commands/dice";
|
import {Dice} from "./commands/dice";
|
||||||
import {Unban} from "./commands/unban";
|
import {Unban} from "./commands/unban";
|
||||||
import {Title} from "./commands/title";
|
import {Title} from "./commands/title";
|
||||||
@@ -113,18 +111,20 @@ export const chatCommands: ChatCommand[] = [
|
|||||||
|
|
||||||
new Shutdown(),
|
new Shutdown(),
|
||||||
new Leave(),
|
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() {
|
async function main() {
|
||||||
console.log(`TEST_ENVIRONMENT: ${Environment.TEST_ENVIRONMENT}\nDATA_PATH: ${Environment.DATA_PATH}`);
|
console.log(`TEST_ENVIRONMENT: ${Environment.TEST_ENVIRONMENT}\nDATA_PATH: ${Environment.DATA_PATH}`);
|
||||||
|
|
||||||
|
|||||||
+31
-3
@@ -229,10 +229,18 @@ export async function sendErrorPlaceholder(message: Message): Promise<Message> {
|
|||||||
export async function initSystemSpecs(): Promise<void> {
|
export async function initSystemSpecs(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const [os, cpu, mem] = await Promise.all([si.osInfo(), si.cpu(), si.mem()]);
|
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` +
|
`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();
|
return Promise.resolve();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Promise.reject(e);
|
return Promise.reject(e);
|
||||||
@@ -729,3 +737,23 @@ export function buildExcludedSet<
|
|||||||
|
|
||||||
return Object.fromEntries(entries) as Record<Exclude<K, E[number]>, SQL>;
|
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 ?? "") };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user