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

Method handleSticker

sticker/sticker.ts:156–290  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

154 const client = await getGlobalClient();
155 if (!client) {
156 await msg.edit({ text: "❌ <b>客户端未初始化</b>", parseMode: "html" });
157 return;
158 }
159
160 try {
161 // 标准参数解析
162 const lines = msg.text?.trim()?.split(/\r?\n/g) || [];
163 const parts = lines?.[0]?.split(/\s+/) || [];
164 const [, ...args] = parts; // 跳过命令本身
165 const sub = (args[0] || "").toLowerCase();
166 const repliedMsg = await safeGetReplyMessage(msg);
167
168 // 处理 help 在前的情况:.s help 或 .s h
169 if (sub === "help" || sub === "h") {
170 await msg.edit({ text: help_text, parseMode: "html", linkPreview: false });
171 return;
172 }
173
174 // Case 1: No reply, handle configuration
175 if (!repliedMsg || !repliedMsg.sticker) {
176 await this.handleConfiguration(msg, args, client);
177 return;
178 }
179
180 // Case 2: Replied to a sticker, handle saving
181 await msg.edit({ text: "🤔 <b>正在处理贴纸...</b>", parseMode: "html" });
182
183 const sticker = repliedMsg.sticker;
184 if (!(sticker instanceof Api.Document)) {
185 throw new StickerError("回复的消息不是有效的贴纸。");
186 }
187
188 // 更准确的贴纸类型检测
189 const mimeType = sticker.mimeType || "";
190 const isAnimated = mimeType === "application/x-tgsticker";
191 const isVideo = mimeType === "video/webm";
192 const isStatic = !isAnimated && !isVideo && (mimeType === "image/webp" || mimeType === "image/png");
193
194 const stickerInfo = {
195 isAnimated,
196 isVideo,
197 isStatic,
198 emoji: (() => {
199 const alt = sticker.attributes.find(
200 (a): a is Api.DocumentAttributeSticker => a instanceof Api.DocumentAttributeSticker
201 )?.alt?.trim();
202 return alt && alt.length > 0 ? alt : getRandomBaseEmoji();
203 })(),
204 document: new Api.InputDocument({
205 id: sticker.id,
206 accessHash: sticker.accessHash,
207 fileReference: sticker.fileReference,
208 }),
209 };
210
211 let targetPackName = "";
212 if (args.length === 2 && args[0].toLowerCase() === "to") {
213 targetPackName = args[1];

Callers 1

StickerPluginClass · 0.95

Calls 11

handleConfigurationMethod · 0.95
findOrCreatePackMethod · 0.95
createStickerSetMethod · 0.95
addToStickerSetMethod · 0.95
getRandomBaseEmojiFunction · 0.85
lifecycleSleepFunction · 0.85
errorMethod · 0.80
htmlEscapeFunction · 0.70
editMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected