← back to browse
goat command

segs

๐‡๐ƒ ๐•๐ข๐๐ž๐จ ๐’๐ž๐š๐ซ๐œ๐ก & ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐

0
views
0
likes
0
installs
raw source
const axios = require("axios");
const fs = require("fs");

let userSession = {};
let botMessages = {};

module.exports = {
  config: {
    name: "segs",
    version: "1.5",
    author: "Azadx69x",
    role: 1,
    category: "18+",
    shortDescription: "๐‡๐ƒ ๐•๐ข๐๐ž๐จ ๐’๐ž๐š๐ซ๐œ๐ก & ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐",
    longDescription: "๐’๐ž๐š๐ซ๐œ๐ก ๐Ÿ๐จ๐ซ ๐‡๐ƒ ๐ฏ๐ข๐๐ž๐จ๐ฌ ๐š๐ง๐ ๐๐จ๐ฐ๐ง๐ฅ๐จ๐š๐"
  },

  onStart: async ({ api, event, args }) => {
    const keyword = args.join(" ");
    const thread = event.threadID;
    const sender = event.senderID;
      
    if (botMessages[thread]) {
      clearBotMessages(api, thread);
    }
    botMessages[thread] = [];

    if (!keyword) {
      const msg = await api.sendMessage("๐Ÿ”ด ๐™บ๐™ด๐šˆ๐š†๐™พ๐š๐™ณ ", thread);
      botMessages[thread].push(msg.messageID);
      return api.setMessageReaction("โŒ", event.messageID, () => {}, true);
    }

    const searchMsg = await api.sendMessage("๐Ÿ” ๐š‚๐™ด๐™ฐ๐š๐™ฒ๐™ท๐™ธ๐™ฝ๐™ถ...", thread);
    botMessages[thread].push(searchMsg.messageID);
    api.setMessageReaction("โณ", event.messageID, () => {}, true);

    try {
      const res = await axios.get(
        `https://azadx69x-segs.vercel.app/api/search?q=${encodeURIComponent(keyword)}`
      );

      const results = res.data.list;

      if (!results.length) {
        const noResultMsg = await api.sendMessage("โŒ ๐™ฝ๐™พ ๐š๐™ด๐š‚๐š„๐™ป๐šƒ๐š‚ ", thread);
        botMessages[thread].push(noResultMsg.messageID);
        return api.setMessageReaction("โŒ", event.messageID, () => {}, true);
      }

      userSession[sender] = {
        results,
        expires: Date.now() + 90_000,
        threadID: thread,
        keyword: keyword
      };
        
      setTimeout(() => {
        api.unsendMessage(searchMsg.messageID);
      }, 500);

      sendList(api, thread, sender, event.messageID);

    } catch (e) {
      const errorMsg = await api.sendMessage("โŒ ๐™ด๐š๐š๐™พ๐š ", thread);
      botMessages[thread].push(errorMsg.messageID);
      api.setMessageReaction("โŒ", event.messageID, () => {}, true);
    }
  },

  onChat: async ({ api, event }) => {
    const sender = event.senderID;
    const thread = event.threadID;
    const msg = event.body.trim();

    if (!userSession[sender]) return;
    
    if (userSession[sender].threadID !== thread) return;

    if (Date.now() > userSession[sender].expires) {
      clearBotMessages(api, thread);
      delete userSession[sender];
      const timeoutMsg = await api.sendMessage("โฐ ๐šƒ๐™ธ๐™ผ๐™ด๐™พ๐š„๐šƒ ", thread);
      setTimeout(() => {
        api.unsendMessage(timeoutMsg.messageID);
      }, 3000);
      return api.setMessageReaction("โณ", event.messageID, () => {}, true);
    }

    const session = userSession[sender];

    if (/^\d+$/.test(msg)) {
      const number = parseInt(msg);
      const index = number - 1;

      if (number < 1 || number > session.results.length || !session.results[index]) {
        const invalidMsg = await api.sendMessage("โŒ ๐™ธ๐™ฝ๐š…๐™ฐ๐™ป๐™ธ๐™ณ ๐™ฝ๐š„๐™ผ๐™ฑ๐™ด๐š โŒ", thread);
        setTimeout(() => {
          api.unsendMessage(invalidMsg.messageID);
        }, 3000);
        return api.setMessageReaction("โŒ", event.messageID, () => {}, true);
      }

      const item = session.results[index];

      api.setMessageReaction("๐Ÿ“ค", event.messageID, () => {}, true);
        
      clearBotMessages(api, thread);

      try {
        const filePath = __dirname + "/video.mp4";

        const video = await axios.get(item.video, {
          responseType: "arraybuffer",
          headers: { "User-Agent": "Mozilla/5.0" }
        });

        fs.writeFileSync(filePath, video.data);

        const videoInfo = `โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐•๐ˆ๐ƒ๐„๐Ž ๐ƒ๐Ž๐–๐๐‹๐Ž๐€๐ƒ๐„๐ƒ โœ…
โ•ญโ”€โ•ผโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•พโ”€โ•ฎ
โ”‚ ๐ŸŽฌ  ${item.name}
โ”‚ โฑ  ${item.time}
โ”‚ ๐Ÿ”ข  ${number}
โ”‚ ๐Ÿ“Š  ${session.results.length} results
โ”‚ ๐Ÿ”  "${session.keyword}"
โ•ฐโ”€โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•พโ”€โ•ฏ
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”`;

        const videoMsg = await api.sendMessage(
          {
            body: videoInfo,
            attachment: fs.createReadStream(filePath)
          },
          thread
        );

        fs.unlinkSync(filePath);
        api.setMessageReaction("โœ…", event.messageID, () => {}, true);
          
        if (!botMessages[thread]) botMessages[thread] = [];
        botMessages[thread].push(videoMsg.messageID);
          
        delete userSession[sender];

      } catch (e) {
        const errorMsg = await api.sendMessage("โŒ ๐™ณ๐™พ๐š†๐™ฝ๐™ป๐™พ๐™ฐ๐™ณ ๐™ด๐š๐š๐™พ๐š โŒ", thread);
        botMessages[thread].push(errorMsg.messageID);
        api.setMessageReaction("โŒ", event.messageID, () => {}, true);
      }

      return;
    }

    const invalidMsg = await api.sendMessage("โŒ ๐™ธ๐™ฝ๐š…๐™ฐ๐™ป๐™ธ๐™ณ ๐™ธ๐™ฝ๐™ฟ๐š„๐šƒ โŒ", thread);
    setTimeout(() => {
      api.unsendMessage(invalidMsg.messageID);
    }, 3000);
    api.setMessageReaction("โŒ", event.messageID, () => {}, true);
  }
};

function sendList(api, thread, user, messageID) {
  const s = userSession[user];
  
  let listMessage = `โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐’๐„๐€๐‘๐‚๐‡ ๐‘๐„๐’๐”๐‹๐“๐’
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n\n`;
  
  const showCount = Math.min(20, s.results.length);
  
  for (let i = 0; i < showCount; i++) {
    const item = s.results[i];
    const number = i + 1;
    
    const title = item.name.length > 50 ? item.name.substring(0, 47) + "..." : item.name;
    
    listMessage += `ใ€${number}ใ€‘ ${title}\n      โฑ ${item.time}\n\n`;
  }

  listMessage += `โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐’๐„๐‹๐„๐‚๐“: ๐Ÿ-${showCount}
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”`;

  api.sendMessage(listMessage, thread).then(msg => {
    if (!botMessages[thread]) botMessages[thread] = [];
    botMessages[thread].push(msg.messageID);
    
    if (messageID) {
      api.setMessageReaction("โœ…", messageID, () => {}, true);
    }
  });
}

function clearBotMessages(api, thread) {
  if (botMessages[thread]) {
    botMessages[thread].forEach(messageID => {
      try {
        api.unsendMessage(messageID);
      } catch (e) {
      }
    });
    botMessages[thread] = [];
  }
}

View raw file