← back to browse
goat command

jamai

random jamai

2
views
0
likes
2
installs

Aliases: hubby

raw source
const axios = require("axios");
const fs = require("fs-extra");
const path = require("path");

module.exports = {
  config: {
    name: "jamai",
    aliases: ["hubby"],
    version: "0.0.8",
    author: "ariyan",
    countDown: 5,
    role: 0,
    shortDescription: { en: "random jamai" },
    longDescription: { en: "Random Jamai from group" },
    category: "fun",
    guide: "{pn}"
  },

  onStart: async ({ api, event, usersData }) => {
    const { threadID, messageID } = event;

    try {
      const info = await api.getThreadInfo(threadID);

      const maleOnly = info.userInfo.filter(user => {
        const g = user.gender;
        if (!g) return false;
        if (typeof g === "number") return g % 2 === 0;
        if (typeof g === "string") return g.trim().charAt(0).toLowerCase() === "m";
        if (g && g.isMale === true) return true;
        return false;
      });

      if (!maleOnly.length) {
        return api.sendMessage("๐ŸŽฉ ๐๐จ ๐ฆ๐š๐ฅ๐ž ๐ฎ๐ฌ๐ž๐ซ๐ฌ ๐Ÿ๐จ๐ฎ๐ง๐ ๐ข๐ง ๐ญ๐ก๐ข๐ฌ ๐ ๐ซ๐จ๐ฎ๐ฉ!", threadID, messageID);
      }

      const pick = maleOnly[Math.floor(Math.random() * maleOnly.length)];
      const uid = pick.id;

      let avatar = await usersData.getAvatarUrl(uid);
      if (!avatar) avatar = `https://graph.facebook.com/${uid}/picture?width=600`;

      const folder = path.join(__dirname, "cache");
      await fs.ensureDir(folder);

      const imgPath = path.join(folder, `${uid}.jpg`);
      const img = await axios.get(avatar, { responseType: "arraybuffer" });
      await fs.writeFile(imgPath, img.data);

      const infoUser = await api.getUserInfo(uid);
      const name = infoUser[uid]?.name || "๐”๐ง๐ค๐ง๐จ๐ฐ๐ง";
      const link = `https://facebook.com/${uid}`;

      const msg =
`๐ŸŽฉ ๐˜๐Ž๐”๐‘ ๐‡๐”๐’๐๐€๐๐ƒ ๐ˆ๐’ ๐‡๐„๐‘๐„! ๐ŸŽฉ

๐ŸŽฉ ๐๐š๐ฆ๐ž: ${name}
๐Ÿ†” ๐”๐ˆ๐ƒ: ${uid}
๐ŸŒ ๐๐ซ๐จ๐Ÿ๐ข๐ฅ๐ž: ${link}

๐ŸŽฉ ๐“๐ซ๐ž๐š๐ญ ๐ก๐ข๐ฆ ๐ฐ๐ž๐ฅ๐ฅ! ๐ŸŽฉ`;

      api.sendMessage(
        { body: msg, attachment: fs.createReadStream(imgPath) },
        threadID,
        () => fs.unlinkSync(imgPath)
      );

    } catch (err) {
      api.sendMessage("๐ŸŽฉ ๐„๐ซ๐ซ๐จ๐ซ ๐จ๐œ๐œ๐ฎ๐ซ๐ซ๐ž๐!", threadID, messageID);
    }
  }
};

View raw file