← back to browse
goat command

unban

Unban a user

0
views
0
likes
0
installs
raw source
const { config } = global.GoatBot;
const { writeFileSync } = require("fs-extra");

module.exports = {
  config: {
    name: "unban",
    version: "2.0.0",
    author: "SHAHADAT SAHU",
    countDown: 3,
    role: 0,
    shortDescription: {
      en: "Unban a user"
    },
    longDescription: {
      en: "Remove a user from ban list"
    },
    category: "owner",
    guide: {
      en: "{pn} <UID/@tag/reply>"
    }
  },

  onStart: async function ({ event, args, usersData, message }) {
    const devUsers = (config.devUsers || []).map(String);
    const senderID = String(event.senderID);

    if (!devUsers.includes(senderID)) {
      return message.reply("🔒 | এই কমান্ড শুধুমাত্র Developer ব্যবহার করতে পারবেন।");
    }

    if (!Array.isArray(config.bannedUsers)) {
      config.bannedUsers = [];
    }

    const saveConfig = () => {
      writeFileSync(
        global.client.dirConfig,
        JSON.stringify(config, null, 2)
      );
    };

    let targetID = null;

    if (event.messageReply) {
      targetID = event.messageReply.senderID;
    } else if (event.mentions && Object.keys(event.mentions).length > 0) {
      targetID = Object.keys(event.mentions)[0];
    } else if (args[0] && /^\d+$/.test(args[0])) {
      targetID = args[0];
    }

    if (!targetID) {
      return message.reply("❌ | ব্যবহার: unban <UID/@tag/reply>");
    }

    targetID = String(targetID);

    const index = config.bannedUsers
      .map(String)
      .indexOf(targetID);

    if (index === -1) {
      return message.reply("⚠️ | এই user ban করা নেই।");
    }

    let nameTarget = targetID;

    try {
      nameTarget = await usersData.getName(targetID);
    } catch (e) {}

    config.bannedUsers.splice(index, 1);
    saveConfig();

    return message.reply(
      `✅ | USER UNBANNED\n━━━━━━━━━━━━━━\n` +
      `👤 ${nameTarget}\n` +
      `🆔 ${targetID}\n\n` +
      `🔓 এখন আবার বট ব্যবহার করতে পারবে।`
    );
  }
};

View raw file