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

Class SoutuPlugin

soutu/soutu.ts:31–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30 description: string = `回复图片进行搜图\n\n${help_text}`;
31
32 cmdHandlers = {
33 [pluginName]: async (msg: Api.Message) => {
34 // 按照规范的参数解析模式
35 const lines = msg.text?.trim()?.split(/\r?\n/g) || [];
36 const parts = lines?.[0]?.split(/\s+/) || [];
37 const [, ...args] = parts;
38 const sub = (args[0] || "").toLowerCase();
39
40 try {
41 // 无参数或help:执行搜图功能
42 if (!sub) {
43 await this.handleSearch(msg);
44 return;
45 }
46
47 // help 在前:.soutu help
48 if (sub === "help" || sub === "h") {
49 await msg.edit({ text: help_text, parseMode: "html" });
50 return;
51 }
52
53 // help 在后:.soutu [sub] help
54 if (args[1] && (args[1].toLowerCase() === "help" || args[1].toLowerCase() === "h")) {
55 await msg.edit({ text: help_text, parseMode: "html" });
56 return;
57 }
58
59 // 默认行为:执行搜图
60 await this.handleSearch(msg);
61
62 } catch (error: any) {
63 console.error('[soutu] 插件执行失败:', error);
64 await msg.edit({ text: `❌ <b>操作失败:</b> ${htmlEscape(error.message)} (${htmlEscape(pluginName)})`, parseMode: "html" });
65 }
66 },
67 };
68
69 private async handleSearch(msg: Api.Message) {
70 if (!msg.replyTo) {
71 await msg.edit({ text: "❌ <b>错误:</b> 请回复一张图片后使用此命令", parseMode: "html" });
72 return;
73 }
74
75 const replied = await safeGetReplyMessage(msg);
76 if (!replied?.photo) {
77 await msg.edit({ text: "❌ <b>错误:</b> 回复的消息不包含图片", parseMode: "html" });
78 return;
79 }
80
81 await msg.edit({ text: "⏳ 正在下载并上传图片...", parseMode: "html" });
82
83 try {
84 const buffer = await replied.downloadMedia();
85 if (!Buffer.isBuffer(buffer) || buffer.length === 0) {
86 await msg.edit({ text: "❌ <b>错误:</b> 图片下载失败或为空", parseMode: "html" });
87 return;
88 }

Callers

nothing calls this directly

Calls 4

handleSearchMethod · 0.95
errorMethod · 0.80
htmlEscapeFunction · 0.70
editMethod · 0.45

Tested by

no test coverage detected