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

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