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

Function gt

gt/gt.ts:14–182  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

12 const translateModule = await import("@vitalets/google-translate-api");
13 translate = translateModule.translate || translateModule.default;
14
15 if (!translate || typeof translate !== "function") {
16 await msg.edit({
17 text: "❌ 翻译服务未正确加载,请检查网络连接或重启程序",
18 parseMode: "html",
19 });
20 return;
21 }
22 } catch (importError: any) {
23 console.error("Failed to import translation service:", importError);
24 await msg.edit({
25 text: `❌ <b>翻译服务加载失败:</b> ${htmlEscape(String(importError.message || importError))}`,
26 parseMode: "html",
27 });
28 return;
29 }
30
31 try {
32 const args = msg.message.split(" ").slice(1); // Remove command part
33 let text = "";
34 let target = "zh-CN";
35
36 // Check for help command
37 if (args.length > 0 && ["h", "help"].includes(args[0].toLowerCase())) {
38 await msg.edit({
39 text: `📘 <b>使用说明:</b>
40
41<b>基本用法:</b>
42• <code>gt [文本]</code> - 翻译为中文(默认)
43• <code>gt en [文本]</code> - 翻译为英文
44
45<b>回复消息翻译:</b>
46• <code>gt</code> 或 <code>gt en</code>
47
48<b>示例:</b>
491. <code>gt Hello world</code>
502. <code>gt en 你好,世界</code>
513. 回复英文消息后 <code>gt</code>`,
52 parseMode: "html",
53 });
54 return;
55 }
56
57 // Check if first argument is "en" for English translation
58 if (args.length > 0 && args[0].toLowerCase() === "en") {
59 target = "en";
60 text = args.slice(1).join(" ");
61 } else {
62 text = args.join(" ");
63 }
64
65 // If no text provided, try to get from replied message
66 if (!text.trim()) {
67 try {
68 const reply = await safeGetReplyMessage(msg);
69 if (reply && reply.text) {
70 text = reply.text.trim();
71 } else {

Callers

nothing calls this directly

Calls 4

errorMethod · 0.80
warnMethod · 0.80
htmlEscapeFunction · 0.70
editMethod · 0.45

Tested by

no test coverage detected