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

Method processEncoding

encode/encode.ts:98–142  ·  view source on GitHub ↗
(
    msg: Api.Message,
    typeName: string, 
    icon: string,
    operation: string,
    processors: { encode: (text: string) => string; decode: (text: string) => string }
  )

Source from the content-addressed store, hash-verified

96 operation: string,
97 processors: { encode: (text: string) => string; decode: (text: string) => string }
98 ): Promise<void> {
99 const client = await getGlobalClient();
100 if (!client) {
101 await msg.edit({ text: "❌ 客户端未初始化", parseMode: "html" });
102 return;
103 }
104
105 // 标准参数解析
106 const lines = msg.text?.trim()?.split(/\r?\n/g) || [];
107 const parts = lines?.[0]?.split(/\s+/) || [];
108 const [, ...args] = parts; // 跳过命令本身
109
110 try {
111 // 获取要处理的文本
112 const text = await this.getTextFromArgsOrReply(msg, args, operation);
113 if (!text) return; // 错误已在方法内处理
114
115 // 显示处理中状态
116 await msg.edit({
117 text: `🔄 <b>${typeName} ${operation === "encode" ? "编码" : "解码"}中...</b>`,
118 parseMode: "html"
119 });
120
121 // 执行编码/解码
122 const result = operation === "encode"
123 ? processors.encode(text)
124 : processors.decode(text);
125
126 // 显示结果
127 await this.showResult(msg, text, result, typeName, operation, icon);
128
129 } catch (error: any) {
130 console.error(`[${typeName.toLowerCase()}${operation}] 插件执行失败:`, error);
131 await msg.edit({
132 text: `❌ <b>${typeName} ${operation === "encode" ? "编码" : "解码"}失败:</b> ${htmlEscape(error.message)}`,
133 parseMode: "html"
134 });
135 }
136 }
137
138 // 从参数或回复消息获取文本
139 private async getTextFromArgsOrReply(msg: Api.Message, args: string[], operation: string): Promise<string | null> {
140 let text = args.join(" ");
141
142 // 如果没有提供文本,尝试从回复消息获取
143 if (!text.trim()) {
144 try {
145 const reply = await safeGetReplyMessage(msg);

Callers 1

EncodePluginClass · 0.95

Calls 5

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

Tested by

no test coverage detected