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

Class KkpPlugin

kkp/kkp.ts:37–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 startTime: number;
36 handler: (event: any) => void;
37 }
38 > = new Map();
39
40 cmdHandlers: Record<string, (msg: Api.Message) => Promise<void>> = {
41 kkp: async (msg: Api.Message) => {
42 const client = await getGlobalClient();
43 if (!client) {
44 await msg.edit({ text: "❌ 客户端未初始化", parseMode: "html" });
45 return;
46 }
47
48 const lines = msg.text?.trim()?.split(/\r?\n/g) || [];
49 const parts = lines?.[0]?.split(/\s+/) || [];
50 const [, ...args] = parts;
51 const sub = (args[0] || "").toLowerCase();
52
53 try {
54 if (sub === "help" || sub === "h") {
55 await msg.edit({ text: help_text, parseMode: "html" });
56 return;
57 }
58
59 if (sub && sub !== "help" && sub !== "h") {
60 await msg.edit({
61 text: `❌ <b>未知命令:</b> <code>${htmlEscape(
62 sub,
63 )}</code>`,
64 parseMode: "html",
65 });
66 return;
67 }
68
69 await this.getRandomVideo(msg, client);
70 } catch (error: any) {
71 console.error("[kkp] 插件执行失败:", error);
72 await msg.edit({
73 text: `❌ <b>插件执行失败:</b> ${htmlEscape(
74 error.message || "未知错误",
75 )}`,
76 parseMode: "html",
77 });
78 }
79 },
80 };
81
82 private extractPlainText(message: Api.Message): string {
83 const fullText = message.message || "";
84 if (!fullText) return "";
85
86 // 如果没有实体,直接返回文本
87 if (!message.entities || message.entities.length === 0) return fullText;
88
89 // 简化的纯文本提取,这里我们只关心拿到文字内容
90 // 原有的逻辑过滤了 URL 等,这里保持原样
91 // ... (保持原逻辑以防破坏其他需求) ...
92 const excludedRanges: Array<{ offset: number; length: number }> = [];
93 for (const entity of message.entities) {
94 if (

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected