← back to browse
goat command

tag

No description

0
views
0
likes
0
installs
raw source
module.exports = {
  config: {
    name: "tag",
    category: "box chat",
    role: 0,
    author: "๐Œ๐š๐‘๐ฎ๐…",
    countDown: 3,
    description: {
      en: "Tag members by name, reply or everyone"
    },
    guide: {
      en: "{p}tag [name] [msg]\n{p}tag all [msg]\nReply + {p}tag [msg]"
    }
  },

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

    try {
      const threadData = await threadsData.get(threadID);

      const members = (threadData.members || [])
        .filter(member => member.inGroup)
        .map(member => ({
          name: member.name || "Unknown User",
          id: member.userID
        }));

      let tagUsers = [];
      let text = "";

      if (messageReply) {
        const uid = messageReply.senderID;
        const name = await usersData.getName(uid);

        tagUsers.push({
          name: name || "Unknown User",
          id: uid
        });

        text = args.join(" ");
      }

      else if (
        args[0] &&
        ["all", "everyone", "cdi"].includes(args[0].toLowerCase())
      ) {
        tagUsers = members;
        text = args.slice(1).join(" ");
      }

      else {
        if (!args[0]) {
          return api.sendMessage(
            {
              body:
                "โ•ญโ”โ”โ”ใ€” โš ๏ธ ๐“๐€๐† ใ€•โ”โ”โ”โ•ฎ\n" +
                "โ”ƒ\n" +
                "โ”ƒ ๐”๐ฌ๐ž ๐ซ๐ž๐ฉ๐ฅ๐ฒ, ๐ง๐š๐ฆ๐ž ๐จ๐ซ ๐š๐ฅ๐ฅ\n" +
                "โ”ƒ ๐ญ๐จ ๐ญ๐š๐  ๐ฆ๐ž๐ฆ๐›๐ž๐ซ๐ฌ.\n" +
                "โ”ƒ\n" +
                "โ”ฃโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n" +
                "โ”ƒ ๐Ÿ’ก ๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž๐ฌ:\n" +
                "โ”ƒ\n" +
                "โ”ƒ โ€ข tag Maruf Hello\n" +
                "โ”ƒ โ€ข tag all Hello everyone\n" +
                "โ”ƒ โ€ข Reply + tag Hello\n" +
                "โ”ƒ\n" +
                "โ•ฐโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•ฏ"
            },
            threadID,
            messageID
          );
        }

        const searchName = args[0].toLowerCase();
        text = args.slice(1).join(" ");

        tagUsers = members.filter(member =>
          member.name.toLowerCase().includes(searchName)
        );

        if (tagUsers.length === 0) {
          return api.sendMessage(
            {
              body:
                "โ•ญโ”โ”โ”ใ€” โŒ ๐๐Ž๐“ ๐…๐Ž๐”๐๐ƒ ใ€•โ”โ”โ”โ•ฎ\n" +
                "โ”ƒ\n" +
                `โ”ƒ ๐Ÿ”Ž ๐’๐ž๐š๐ซ๐œ๐ก: ${args[0]}\n` +
                "โ”ƒ\n" +
                "โ”ƒ ๐๐จ ๐ฆ๐š๐ญ๐œ๐ก๐ข๐ง๐  ๐ฆ๐ž๐ฆ๐›๐ž๐ซ ๐ฐ๐š๐ฌ ๐Ÿ๐จ๐ฎ๐ง๐.\n" +
                "โ”ƒ\n" +
                "โ•ฐโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•ฏ"
            },
            threadID,
            messageID
          );
        }
      }

      if (tagUsers.length === 0) {
        return api.sendMessage(
          {
            body:
              "โ•ญโ”โ”โ”ใ€” โš ๏ธ ๐“๐€๐† ใ€•โ”โ”โ”โ•ฎ\n" +
              "โ”ƒ\n" +
              "โ”ƒ ๐๐จ ๐ฆ๐ž๐ฆ๐›๐ž๐ซ๐ฌ ๐š๐ซ๐ž ๐š๐ฏ๐š๐ข๐ฅ๐š๐›๐ฅ๐ž ๐ญ๐จ ๐ญ๐š๐ .\n" +
              "โ”ƒ\n" +
              "โ•ฐโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•ฏ"
          },
          threadID,
          messageID
        );
      }

      const mentions = tagUsers.map(user => ({
        tag: user.name,
        id: user.id
      }));

      const namesText = tagUsers
        .map((user, index) => `โ”ƒ ${index + 1}. ${user.name}`)
        .join("\n");

      const body = text
        ? (
          "โ•ญโ”โ”โ”ใ€” ๐Ÿ”” ๐“๐€๐† ๐๐Ž๐“๐ˆ๐‚๐„ ใ€•โ”โ”โ”โ•ฎ\n" +
          "โ”ƒ\n" +
          namesText + "\n" +
          "โ”ƒ\n" +
          "โ”ฃโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n" +
          `โ”ƒ ๐Ÿ’ฌ ${text}\n` +
          "โ”ƒ\n" +
          "โ•ฐโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•ฏ"
        )
        : (
          "โ•ญโ”โ”โ”ใ€” ๐Ÿ”” ๐“๐€๐† ๐๐Ž๐“๐ˆ๐‚๐„ ใ€•โ”โ”โ”โ•ฎ\n" +
          "โ”ƒ\n" +
          namesText + "\n" +
          "โ”ƒ\n" +
          "โ•ฐโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•ฏ"
        );

      return api.sendMessage(
        {
          body,
          mentions
        },
        threadID,
        messageReply ? messageReply.messageID : messageID
      );

    } catch (error) {
      return api.sendMessage(
        {
          body:
            "โ•ญโ”โ”โ”ใ€” โŒ ๐„๐‘๐‘๐Ž๐‘ ใ€•โ”โ”โ”โ•ฎ\n" +
            "โ”ƒ\n" +
            "โ”ƒ ๐’๐จ๐ฆ๐ž๐ญ๐ก๐ข๐ง๐  ๐ฐ๐ž๐ง๐ญ ๐ฐ๐ซ๐จ๐ง๐ .\n" +
            "โ”ƒ\n" +
            `โ”ƒ โš™๏ธ ${error.message}\n` +
            "โ”ƒ\n" +
            "โ•ฐโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•ฏ"
        },
        threadID,
        messageID
      );
    }
  }
};

View raw file