-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathcar.js
More file actions
98 lines (85 loc) · 4.72 KB
/
Copy pathcar.js
File metadata and controls
98 lines (85 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const axios = require("axios");
const fs = require("fs");
const path = require("path");
const mahmud = async () => {
const response = await axios.get("https://raw.githubusercontent.com/mahmudx7/HINATA/main/baseApiUrl.json");
return response.data.mahmud;
};
module.exports = {
config: {
name: "car",
aliases: ["carvideo", "carvid", "গাড়ি"],
version: "1.7",
author: "MahMUD",
countDown: 10,
role: 0,
description: {
bn: "র্যান্ডম কার এডিট ভিডিও পান",
en: "Get a random car edit video",
vi: "Lấy một video chỉnh sửa xe hơi ngẫu nhiên"
},
category: "media",
guide: {
bn: ' {pn}: একটি র্যান্ডম কার ভিডিও দেখতে ব্যবহার করুন',
en: ' {pn}: Use to get a random car video',
vi: ' {pn}: Sử dụng để lấy một video xe hơi ngẫu nhiên'
}
},
langs: {
bn: {
noVideo: "× কোনো ভিডিও খুঁজে পাওয়া যায়নি",
success: "𝐇𝐞𝐫𝐞'𝐬 𝐲𝐨𝐮𝐫 𝐂𝐚𝐫 𝐯𝐢𝐝𝐞𝐨 𝐛𝐚𝐛𝐲 <😘",
error: "× সমস্যা হয়েছে: %1। প্রয়োজনে Contact MahMUD।"
},
en: {
noVideo: "× No videos found",
success: "𝐇𝐞𝐫𝐞'𝐬 𝐲𝐨𝐮𝐫 𝐂𝐚𝐫 𝐯𝐢𝐝𝐞𝐨 𝐛𝐚𝐛𝐲 <😘",
error: "× API error: %1. Contact MahMUD for help."
},
vi: {
noVideo: "× Không tìm thấy video nàn",
success: "Video xe hơi của cưng đây <😘",
error: "× Lỗi: %1. Liên hệ MahMUD để hỗ trợ."
}
},
onStart: async function ({ api, event, message, getLang }) {
const authorName = String.fromCharCode(77, 97, 104, 77, 85, 68);
if (this.config.author !== authorName) {
return api.sendMessage("You are not authorized to change the author name.", event.threadID, event.messageID);
}
const filePath = path.join(__dirname, "cache", `car_${Date.now()}.mp4`);
if (!fs.existsSync(path.dirname(filePath))) fs.mkdirSync(path.dirname(filePath), { recursive: true });
try {
api.setMessageReaction("⏳", event.messageID, () => {}, true);
const apiUrl = await mahmud();
const res = await axios.get(`${apiUrl}/api/album/mahmud/videos/car?userID=${event.senderID}`);
if (!res.data.success || !res.data.videos.length) {
return message.reply(getLang("noVideo"));
}
const url = res.data.videos[Math.floor(Math.random() * res.data.videos.length)];
const videoRes = await axios({
url,
method: "GET",
responseType: "stream",
headers: { 'User-Agent': 'Mozilla/5.0' }
});
const writer = fs.createWriteStream(filePath);
videoRes.data.pipe(writer);
writer.on("finish", () => {
return message.reply({
body: getLang("success"),
attachment: fs.createReadStream(filePath)
}, () => {
api.setMessageReaction("✅", event.messageID, () => {}, true);
if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
});
});
writer.on("error", (err) => { throw err; });
} catch (err) {
console.error("Car Error:", err);
api.setMessageReaction("❌", event.messageID, () => {}, true);
if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
return message.reply(getLang("error", err.message));
}
}
};