Spaces:
Paused
Paused
𝗗𝗔𝗥𝗥𝗘𝗟𝗟 𝗠𝗨𝗖𝗛𝗘𝗥𝗜 ⚡
commited on
Create tg-sticker.js
Browse files- plugins/tg-sticker.js +87 -0
plugins/tg-sticker.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// telegram stickers fetch
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
const { cmd } = require('../command');
|
| 28 |
+
const axios = require('axios');
|
| 29 |
+
const { getBuffer, sleep } = require('../lib/functions'); // Importez vos fonctions utilitaires nécessaires
|
| 30 |
+
|
| 31 |
+
const botToken = '891038791:AAHWB1dQd-vi0IbH2NjKYUk-hqQ8rQuzPD4'; // Remplacez par le token de votre bot Telegram
|
| 32 |
+
|
| 33 |
+
cmd({
|
| 34 |
+
pattern: 'tgs',
|
| 35 |
+
react: '🤖',
|
| 36 |
+
desc: 'Download and send stickers from a Telegram sticker pack',
|
| 37 |
+
category: 'media',
|
| 38 |
+
use: '.tgs <sticker_pack_link>',
|
| 39 |
+
filename: __filename
|
| 40 |
+
}, async (conn, mek, m, { from, l, quoted, body, args }) => {
|
| 41 |
+
try {
|
| 42 |
+
// Vérifier que l'URL est fournie
|
| 43 |
+
if (!args[0]) {
|
| 44 |
+
return conn.sendMessage(from, { text: '❌ Please provide a valid sticker pack URL.' }, { quoted: mek });
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
const packUrl = args[0];
|
| 48 |
+
const packName = packUrl.split('/').pop(); // Récupérer le nom du pack de stickers à partir de l'URL
|
| 49 |
+
|
| 50 |
+
// Appel à l'API Telegram pour récupérer les stickers du pack
|
| 51 |
+
const apiUrl = `https://api.telegram.org/bot${botToken}/getStickerSet?name=${packName}`;
|
| 52 |
+
const response = await axios.get(apiUrl);
|
| 53 |
+
|
| 54 |
+
// Vérifier si l'API a retourné un pack valide
|
| 55 |
+
if (!response.data.ok) {
|
| 56 |
+
return conn.sendMessage(from, { text: '❌ Unable to find the sticker pack. Please check the URL.' }, { quoted: mek });
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
const stickers = response.data.result.stickers;
|
| 60 |
+
if (stickers.length === 0) {
|
| 61 |
+
return conn.sendMessage(from, { text: '❌ This sticker pack does not contain any stickers.' }, { quoted: mek });
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// Envoi de chaque sticker dans le chat
|
| 65 |
+
for (let i = 0; i < stickers.length; i++) {
|
| 66 |
+
const stickerFileId = stickers[i].file_id;
|
| 67 |
+
const stickerData = await axios.get(`https://api.telegram.org/bot${botToken}/getFile?file_id=${stickerFileId}`);
|
| 68 |
+
const filePath = stickerData.data.result.file_path;
|
| 69 |
+
const stickerUrl = `https://api.telegram.org/file/bot${botToken}/${filePath}`;
|
| 70 |
+
|
| 71 |
+
// Télécharger le sticker
|
| 72 |
+
const stickerBuffer = await getBuffer(stickerUrl);
|
| 73 |
+
|
| 74 |
+
// Envoyer le sticker dans le chat
|
| 75 |
+
await conn.sendMessage(from, { sticker: stickerBuffer }, { quoted: mek });
|
| 76 |
+
|
| 77 |
+
// Attendre un peu avant d'envoyer le prochain sticker
|
| 78 |
+
await sleep(1000);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// Message de confirmation
|
| 82 |
+
conn.sendMessage(from, { text: '✅ Stickers have been successfully sent!' }, { quoted: mek });
|
| 83 |
+
} catch (e) {
|
| 84 |
+
console.error(e);
|
| 85 |
+
conn.sendMessage(from, { text: '❌ An error occurred while fetching the sticker pack. Please try again.' }, { quoted: mek });
|
| 86 |
+
}
|
| 87 |
+
});
|