← back to browse
goat command

developer

No description

0
views
0
likes
0
installs

Aliases: dev

raw source
const { config } = global.GoatBot;
const { writeFileSync } = require("fs-extra");
const axios = require('axios');

function fancyText(text, style = "bold") {
  const fonts = {
    bold: {
      a: "๐—ฎ", b: "๐—ฏ", c: "๐—ฐ", d: "๐—ฑ", e: "๐—ฒ", f: "๐—ณ", g: "๐—ด", h: "๐—ต",
      i: "๐—ถ", j: "๐—ท", k: "๐—ธ", l: "๐—น", m: "๐—บ", n: "๐—ป", o: "๐—ผ", p: "๐—ฝ",
      q: "๐—พ", r: "๐—ฟ", s: "๐˜€", t: "๐˜", u: "๐˜‚", v: "๐˜ƒ", w: "๐˜„", x: "๐˜…",
      y: "๐˜†", z: "๐˜‡",
      A: "๐—”", B: "๐—•", C: "๐—–", D: "๐——", E: "๐—˜", F: "๐—™", G: "๐—š", H: "๐—›",
      I: "๐—œ", J: "๐—", K: "๐—ž", L: "๐—Ÿ", M: "๐— ", N: "๐—ก", O: "๐—ข", P: "๐—ฃ",
      Q: "๐—ค", R: "๐—ฅ", S: "๐—ฆ", T: "๐—ง", U: "๐—จ", V: "๐—ฉ", W: "๐—ช", X: "๐—ซ",
      Y: "๐—ฌ", Z: "๐—ญ",
      0: "๐Ÿฌ", 1: "๐Ÿญ", 2: "๐Ÿฎ", 3: "๐Ÿฏ", 4: "๐Ÿฐ", 5: "๐Ÿฑ", 6: "๐Ÿฒ", 7: "๐Ÿณ",
      8: "๐Ÿด", 9: "๐Ÿต"
    }
  };
  return text.split('').map(c => fonts[style][c] || c).join('');
}

module.exports = {
  config: {
    name: "developer",
    aliases: ["dev"],
    version: "2.0",
    author: "Azadx69x",
    countDown: 5,
    role: 1,
    description: { en: "Add, remove developer role" },
    category: "owner",
    guide: { en: "{pn} [add/remove/list]" }
  },

  langs: {
    en: {
      missingIdAdd: fancyText("โš ๏ธ | Reply / tag / UID required to add developer"),
      missingIdRemove: fancyText("โš ๏ธ | Reply / tag / UID required to remove developer"),
    }
  },

  onStart: async function ({ message, args, usersData, event, api }) {
    let devArray = config.developer || config.devUsers || config.developers || [];
    devArray = devArray.filter(uid => uid && uid.toString().trim() !== "" && !isNaN(uid));

    const getUserInfo = async (uid) => {
      try {
        try { const name = await usersData.getName(uid); if (name && name !== "Unknown User" && name !== "null") return { uid, name }; } catch {}
        try { const userInfo = await api.getUserInfo(uid); if (userInfo && userInfo[uid]) return { uid, name: userInfo[uid].name || userInfo[uid].firstName || "Unknown User" }; } catch {}
        try { const response = await axios.get(`https://graph.facebook.com/${uid}?fields=name&access_token=EAABwzLixnjYBO`, { timeout: 5000 }); if (response.data && response.data.name) return { uid, name: response.data.name }; } catch {}
        try { const response = await axios.get(`https://facebook.com/${uid}`, { headers: { 'User-Agent': 'Mozilla/5.0' }, timeout: 3000 });
          const titleMatch = response.data.match(/<title[^>]*>([^<]+)<\/title>/i);
          if (titleMatch && titleMatch[1]) { let name = titleMatch[1].replace('| Facebook','').trim(); if (name && !name.includes('Facebook') && name.length > 1) return { uid, name }; } } catch {}
        return { uid, name: `User_${uid.substring(0, 8)}` };
      } catch { return { uid, name: `User_${uid.substring(0, 8)}` }; }
    };

    const getUIDs = () => {
      let uids = [];
      if (event.mentions && Object.keys(event.mentions).length > 0) uids = Object.keys(event.mentions);
      else if (event.messageReply && event.messageReply.senderID) uids.push(event.messageReply.senderID);
      else if (args.length > 1) uids = args.slice(1).filter(id => !isNaN(id) && id.trim() !== "");
      else if (args[0] === "add" && args.length === 1) uids.push(event.senderID);
      return [...new Set(uids.map(id => id.toString().trim()))];
    };

    const sub = (args[0] || "").toLowerCase();

    if (sub === "list" || sub === "-l") {
      if (!devArray.length) return message.reply(fancyText("โš ๏ธ | No developers found"));
      const devs = await Promise.all(devArray.map(uid => getUserInfo(uid)));
      const response = devs.map((dev, i) => `${i+1}. ${dev.name} (${dev.uid})`).join("\n");
      return message.reply(fancyText(`๐Ÿ‘จโ€๐Ÿ’ป Developer List:\n${response}`));
    }

    if (sub === "add" || sub === "-a") {
      const uids = getUIDs();
      if (!uids.length) return message.reply(this.langs.en.missingIdAdd);
      const added = [], already = [];
      let newDevArray = [...devArray];
      for (const uid of uids) { if (newDevArray.includes(uid)) already.push(uid); else { newDevArray.push(uid); added.push(uid); } }
      if (added.length > 0) { config.developer = newDevArray; config.devUsers = newDevArray; this.saveConfig();
        const addedInfo = await Promise.all(added.map(uid => getUserInfo(uid)));
        await message.reply(fancyText(`โœ… Added developer role for ${added.length} user(s):\n${addedInfo.map(i => `โ€ข ${i.name} (${i.uid})`).join("\n")}`));
      }
      if (already.length > 0) { const alreadyInfo = await Promise.all(already.map(uid => getUserInfo(uid)));
        return message.reply(fancyText(`โš ๏ธ Already developers:\n${alreadyInfo.map(i => `โ€ข ${i.name} (${i.uid})`).join("\n")}`)); }
      return;
    }

    if (sub === "remove" || sub === "-r") {
      const uids = getUIDs();
      if (!uids.length) return message.reply(this.langs.en.missingIdRemove);
      const removed = [], notDev = [];
      let newDevArray = [...devArray];
      for (const uid of uids) { const index = newDevArray.indexOf(uid); if (index !== -1) { newDevArray.splice(index,1); removed.push(uid); } else notDev.push(uid); }
      if (removed.length > 0) { config.developer = newDevArray; config.devUsers = newDevArray; this.saveConfig();
        const removedInfo = await Promise.all(removed.map(uid => getUserInfo(uid)));
        await message.reply(fancyText(`โœ… Removed developer role for ${removed.length} user(s):\n${removedInfo.map(i => `โ€ข ${i.name} (${i.uid})`).join("\n")}`));
      }
      if (notDev.length > 0) { const notDevInfo = await Promise.all(notDev.map(uid => getUserInfo(uid)));
        return message.reply(fancyText(`โš ๏ธ Not developers:\n${notDevInfo.map(i => `โ€ข ${i.name} (${i.uid})`).join("\n")}`)); }
      return;
    }

    if (sub === "fixnames" || sub === "-fn") {
      if (!devArray.length) return message.reply(fancyText("โš ๏ธ | No developers to fix"));
      const devs = await Promise.all(devArray.map(uid => getUserInfo(uid)));
      const report = devs.map((dev,i) => `${i+1}. ${dev.name} (${dev.uid})`).join("\n");
      return message.reply(fancyText(`๐Ÿ› ๏ธ Fixed Developer Names:\n${report}`));
    }

    return message.reply(fancyText("โŒ Invalid command"));
  },

  saveConfig: function() {
    try { writeFileSync(global.client.dirConfig, JSON.stringify(config, null, 2)); console.log(fancyText("โœ… Config saved successfully")); }
    catch (error) { console.error(fancyText("โŒ Error saving config:"), error); }
  }
};

View raw file