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] = [];
}
}