goat
command
meme
No description
0
views
0
likes
0
installs
Aliases: meme
raw source
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("๐
๐๐ญ๐๐ก ๐
๐๐ข๐ฅ๐๐.");
}
}
};