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 getUsername(user: Api.User): string {
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(

Callers

nothing calls this directly

Calls 1

handleStickerMethod · 0.95

Tested by

no test coverage detected