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

Class StickerPlugin

sticker/sticker.ts:149–511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147 description: string = help_text;
148
149 cmdHandlers: Record<string, (msg: Api.Message) => Promise<void>> = {
150 sticker: async (msg: Api.Message) => await this.handleSticker(msg),
151 };
152
153 private async handleSticker(msg: Api.Message): Promise<void> {
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,

Callers

nothing calls this directly

Calls 1

handleStickerMethod · 0.95

Tested by

no test coverage detected