← back to browse
goat command

bou

oilo bou / bow

0
views
0
likes
0
installs

Aliases: bow

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

module.exports = {
  config: {
    name: "bou",
    aliases: ["bow"],
    version: "0.0.8",
    author: "Azadx69x",
    countDown: 5,
    role: 0,
    shortDescription: { en: "oilo bou / bow" },
    longDescription: { en: "Random Bow from group" },
    category: "fun",
    guide: "{pn}"
  },

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

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

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

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

      const pick = femaleOnly[Math.floor(Math.random() * femaleOnly.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