MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / UAIPlugin

Class UAIPlugin

uai/uai.ts:327–646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325 description = () => getHelpText();
326
327 cmdHandlers = {
328 uai: async (msg: Api.Message) => {
329 const text = (msg.message || "").trim();
330 const parts = text.split(/\s+/).slice(1);
331 const subCmd = parts[0]?.toLowerCase() || "";
332
333 const db = await getDB();
334
335 // 帮助
336 if (!subCmd || subCmd === "help") {
337 await msg.edit({ text: getHelpText(), parseMode: "html" });
338 return;
339 }
340
341 // 折叠开关配置
342 if (subCmd === "collapse") {
343 const action = parts[1]?.toLowerCase();
344 if (action === "on") {
345 db.data.collapse = true;
346 await db.write();
347 await msg.edit({
348 text: "✅ 已开启AI回答折叠显示\n\nAI回答将显示在可折叠的块引用中",
349 parseMode: "html"
350 });
351 return;
352 } else if (action === "off") {
353 db.data.collapse = false;
354 await db.write();
355 await msg.edit({
356 text: "✅ 已关闭AI回答折叠显示\n\nAI回答将正常显示",
357 parseMode: "html"
358 });
359 return;
360 } else {
361 await msg.edit({
362 text: `📊 当前折叠状态: <b>${db.data.collapse ? "开启" : "关闭"}</b>\n\n使用: <code>${mainPrefix}uai collapse on/off</code>`,
363 parseMode: "html"
364 });
365 return;
366 }
367 }
368
369 // 配置命令
370 if (subCmd === "add" && parts.length >= 5) {
371 const [, name, baseUrl, apiKey, typeStr] = parts;
372 const type = typeStr.toLowerCase() as ApiType;
373 if (type !== "openai" && type !== "gemini") {
374 await msg.edit({ text: "❌ type 必须是 openai 或 gemini", parseMode: "html" });
375 return;
376 }
377 const authMethod: AuthMethod = type === "gemini" ? "query_param" : "bearer_token";
378 const defaultModel = type === "gemini" ? "gemini-2.0-flash" : "gpt-4o";
379 db.data.providers[name] = { name, base_url: baseUrl, api_key: apiKey, model: defaultModel, type, auth_method: authMethod };
380 if (!db.data.default_provider) db.data.default_provider = name;
381 await db.write();
382 await msg.edit({ text: `✅ 供应商 <code>${htmlEscape(name)}</code> 已添加`, parseMode: "html" });
383 return;
384 }

Callers

nothing calls this directly

Calls 12

parseTimeLimitFunction · 0.85
getPromptFunction · 0.85
callAIFunction · 0.85
applyWrapFunction · 0.85
writeMethod · 0.80
getHelpTextFunction · 0.70
getDBFunction · 0.70
htmlEscapeFunction · 0.70
collectMessagesFunction · 0.70
formatMessagesForAIFunction · 0.70
editMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected