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

Method addToStickerSet

sticker/sticker.ts:446–510  ·  view source on GitHub ↗
(
    client: TelegramClient,
    stickerMsg: Api.Message,
    packName: string,
    emoji: string
  )

Source from the content-addressed store, hash-verified

444 client: TelegramClient,
445 stickerMsg: Api.Message,
446 packName: string,
447 emoji: string
448 ): Promise<void> {
449 const stickersBot = "stickers";
450 try {
451 // Helper to get the latest message from the bot
452 const getLatestBotResponse = async () => {
453 const history = await safeGetMessages(client, stickersBot, { limit: 1 });
454 return history[0];
455 };
456
457 // Start conversation
458 await client.sendMessage(stickersBot, { message: "/addsticker" });
459 await lifecycleSleep(1500, "sticker:bot-start-delay"); // Wait for bot to respond
460
461 // Send pack name
462 await client.sendMessage(stickersBot, { message: packName });
463 await lifecycleSleep(1500, "sticker:bot-pack-delay");
464 let response = await getLatestBotResponse();
465 if (response?.message.toLowerCase().includes("invalid set")) {
466 throw new StickerError(`贴纸包 <code>${htmlEscape(packName)}</code> 无效或您不是该包的所有者。`);
467 }
468
469 // 修复: 转发消息需要提供 fromPeer
470 await client.forwardMessages(stickersBot, {
471 messages: [stickerMsg.id],
472 fromPeer: stickerMsg.peerId,
473 });
474 await lifecycleSleep(2500, "sticker:bot-process-delay"); // Wait for processing and response
475 response = await getLatestBotResponse();
476
477 if (response?.message) {
478 const responseText = response.message.toLowerCase();
479 if (responseText.includes("sorry, the video is too long") || responseText.includes("duration of the video must be 3 seconds or less")) {
480 throw new StickerError("视频贴纸时长不能超过3秒。");
481 }
482 if (responseText.includes("the sticker's dimensions should be")) {
483 throw new StickerError("静态贴纸尺寸必须为 512xN 或 Nx512。");
484 }
485 if (!responseText.includes("thanks! now send me an emoji")) {
486 throw new StickerError(`添加贴纸时机器人返回未知信息: "${htmlEscape(response.message)}"`);
487 }
488 } else {
489 throw new StickerError("添加贴纸后没有收到 @Stickers 机器人的回复。");
490 }
491
492 // Send emoji
493 await client.sendMessage(stickersBot, { message: emoji });
494 await lifecycleSleep(1500, "sticker:bot-emoji-delay");
495
496 // Finish
497 await client.sendMessage(stickersBot, { message: "/done" });
498
499 } catch (error: any) {
500 // Try to cancel the operation with the bot on failure
501 await client.sendMessage(stickersBot, { message: "/cancel" });
502 if (error instanceof StickerError) {
503 throw error; // Re-throw our custom, user-friendly error

Callers 1

handleStickerMethod · 0.95

Calls 2

lifecycleSleepFunction · 0.85
htmlEscapeFunction · 0.70

Tested by

no test coverage detected