MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/igs.js:222–296  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

220 description: 'Convert Instagram post/reel to sticker',
221 usage: '.igs <instagram URL>',
222 async handler(sock, message, args, context) {
223 const { chatId, channelInfo } = context;
224 try {
225 const text = message.message?.conversation || message.message?.extendedTextMessage?.text || '';
226 const urlMatch = text.match(/https?:\/\/\S+/);
227 if (!urlMatch) {
228 await sock.sendMessage(chatId, {
229 text: `Send an Instagram post/reel link.\nUsage: .igs <url>`,
230 ...channelInfo
231 }, { quoted: message });
232 return;
233 }
234 await sock.sendMessage(chatId, { react: { text: '🔄', key: message.key } });
235 const downloadData = await igdl(urlMatch[0]).catch(() => null);
236 if (!downloadData || !downloadData.data) {
237 await sock.sendMessage(chatId, {
238 text: '❌ Failed to fetch media from Instagram link.',
239 ...channelInfo
240 }, { quoted: message });
241 return;
242 }
243 const rawItems = (downloadData?.data || []).filter((m) => m && m.url);
244 const seenUrls = new Set();
245 const items = [];
246 for (const m of rawItems) {
247 if (!seenUrls.has(m.url)) {
248 seenUrls.add(m.url);
249 items.push(m);
250 }
251 }
252 if (items.length === 0) {
253 await sock.sendMessage(chatId, {
254 text: '❌ No media found at the provided link.',
255 ...channelInfo
256 }, { quoted: message });
257 return;
258 }
259 const maxItems = Math.min(items.length, 10);
260 const seenHashes = new Set();
261 for (let i = 0; i < maxItems; i++) {
262 try {
263 const media = items[i];
264 const mediaUrl = media.url;
265 const isVideo = (media?.type === 'video') || /\.(mp4|mov|avi|mkv|webm)$/i.test(mediaUrl);
266 const buffer = await fetchBufferFromUrl(mediaUrl);
267 const { createHash } = await import('crypto');
268 const hash = createHash('sha1').update(buffer).digest('hex');
269 if (seenHashes.has(hash)) {
270 continue;
271 }
272 seenHashes.add(hash);
273 let finalSticker = await forceMiniSticker(buffer, isVideo, false);
274 if (!finalSticker)
275 finalSticker = await convertBufferToStickerWebp(buffer, isVideo, false);
276 await sock.sendMessage(chatId, {
277 sticker: finalSticker,
278 ...channelInfo
279 }, { quoted: message });

Callers

nothing calls this directly

Calls 3

forceMiniStickerFunction · 0.85
fetchBufferFromUrlFunction · 0.70

Tested by

no test coverage detected