const axios = require("axios"); const fs = require("fs"); const path = require("path"); const FormData = require("form-data"); function decode(x) { return Buffer.from(x, "base64").toString("utf8"); } const DB_API = decode("aHR0cHM6Ly9tb25nb2RiLWFwaS1wc2kudmVyY2VsLmFwcC9tZW1l"); const IMGUR_ID = decode("ZDcwMzA1ZTdjM2FjNWM2"); function getText(event) { return ( event.body || event.message?.body || event.message?.text || event.message || "" ) .toString() .trim() .toLowerCase(); } async function getName(api, uid) { try { if (api.getUserInfo) { const info = await api.getUserInfo(uid); return info?.[uid]?.name || uid; } } catch {} return uid; } module.exports = { config: { name: "meme", aliases: ["meme"], version: "25.0", author: "Arafat", countDown: 3, role: 0, category: "fun" }, onStart: async function ({ message, event, api }) { const userMessage = getText(event); const { senderID, messageReply } = event; if (userMessage === "#meme list" || userMessage === "/meme list" || userMessage === "meme list") { try { const res = await axios.get(DB_API); const list = res.data?.data || []; if (!list.length) return message.reply("ššØ š¦šžš¦šžš¬ š®š©š„šØššššžš š²šžš­."); const count = {}; for (const m of list) count[m.uploader] = (count[m.uploader] || 0) + 1; const sorted = Object.entries(count).sort((a, b) => b[1] - a[1]); let text = "šŸ‘‘ šŒšžš¦šž š‹šžššššžš«š›šØššš«š šŸ‘‘\n\n"; let rank = 1; for (const [uid, total] of sorted) { const name = await getName(api, uid); if (rank === 1) text += `šŸ„‡ ${name} — ${total} š”š©š„šØšššš¬\n`; else if (rank === 2) text += `🄈 ${name} — ${total} š”š©š„šØšššš¬\n`; else if (rank === 3) text += `šŸ„‰ ${name} — ${total} š”š©š„šØšššš¬\n`; else text += `• ${rank}) ${name} — ${total} š”š©š„šØšššš¬\n`; rank++; } text += `\nšŸ† š“šØš­ššš„ šŒšžš¦šžš¬: ${list.length}`; return message.reply(text); } catch { return message.reply("š…ššš¢š„šžš š­šØ š„šØššš š„šžššššžš«š›šØššš«š."); } } if (messageReply?.attachments?.length > 0) { try { const fileUrl = messageReply.attachments[0].url; const file = await axios.get(fileUrl, { responseType: "arraybuffer", headers: { "User-Agent": "Mozilla/5.0" } }); const form = new FormData(); form.append("image", Buffer.from(file.data), "meme"); const up = await axios.post("https://api.imgur.com/3/upload", form, { headers: { Authorization: `Client-ID ${IMGUR_ID}`, ...form.getHeaders() } }); const link = up.data?.data?.link || up.data?.data?.mp4 || up.data?.data?.gifv; if (!link) return message.reply("š”š©š„šØššš š…ššš¢š„šžš."); const uploaderName = await getName(api, senderID); const old = await axios.get(DB_API); const before = old.data?.data?.length || 0; await axios.post(DB_API, { url: link, uploader: senderID, createdAt: Date.now() }); const now = await axios.get(DB_API); const totalNow = now.data?.data?.length || before + 1; const date = new Date().toLocaleString("en-US", { timeZone: "Asia/Dhaka" }); const msg = `š”š©š„šØššš š’š®šœšœšžš¬š¬šŸš®š„ š”š©š„šØššššžš«: ${uploaderName} š”š¢š: ${senderID} šƒššš­šž: ${date}`; return message.reply(msg); } catch { return message.reply("š”š©š„šØššš š…ššš¢š„šžš."); } } try { const res = await axios.get(DB_API); const list = res.data?.data || []; if (!list.length) return message.reply("ššØ š¦šžš¦šžš¬ š¬šššÆšžš š²šžš­."); const pick = list[Math.floor(Math.random() * list.length)]; const uploaderName = await getName(api, pick.uploader); const uploadDate = new Date(pick.createdAt).toLocaleString("en-US", { timeZone: "Asia/Dhaka" }); const img = await axios.get(pick.url, { responseType: "arraybuffer", headers: { "User-Agent": "Mozilla/5.0" } }); const ext = path.extname(pick.url.split("?")[0]) || ".jpg"; const filePath = path.join(__dirname, `meme_${Date.now()}${ext}`); fs.writeFileSync(filePath, img.data); const bodyText = `šŸŽ­ š‡šžš«šž š¢š¬ š²šØš®š« š‘ššš§ššØš¦ šŒšžš¦šž šŸŽ­ š”š©š„šØššššžš«: ${uploaderName} š”šˆšƒ: ${pick.uploader} šƒššš­šž: ${uploadDate}`; await message.reply({ body: bodyText, attachment: fs.createReadStream(filePath) }); setTimeout(() => fs.unlinkSync(filePath), 5000); } catch { return message.reply("š…šžš­šœš” š…ššš¢š„šžš."); } } };