goat
command
sing2
No description
0
views
0
likes
0
installs
Aliases: sing2, music
raw source
const A = require("axios");
const B = require("fs-extra");
const C = require("path");
const S = require("yt-search");
const LOCKED_AUTHOR = "Farhan-Khan";
// ๐ AUTHOR CHECK FUNCTION
function checkAuthor(config) {
if (!config || config.author !== LOCKED_AUTHOR) {
throw new Error("๐ซ Author tampered! This command is disabled.");
}
}
const p = C.join(__dirname, "cache", `${Date.now()}.mp3`);
const nix = "https://raw.githubusercontent.com/aryannix/stuffs/master/raw/apis.json";
module.exports = {
config: {
name: "sing2",
aliases: ["sing2", "music"],
version: "0.0.1",
author: "Farhan-Khan",
countDown: 10,
role: 0,
category: "media"
},
onStart: async function ({ api, event, args }) {
const { threadID: t, messageID: m } = event;
const q = args.join(" ");
if (!q) return api.sendMessage("โ Please provide a song name or link.", t, m);
// ๐ AUTHOR LOCK ACTIVE
checkAuthor(module.exports.config);
api.setMessageReaction("โณ", m, () => {}, true);
try {
const D = await A.get(nix);
const E = D.data.api;
let u = q;
if (!q.startsWith("http")) {
const r = await S(q);
const v = r.videos[0];
if (!v) throw new Error("Error ytdl issue ๐ง");
u = v.url;
}
const F = await A.get(`${E}/ytdl`, {
params: { url: u, type: "audio" }
});
if (!F.data.status || !F.data.downloadUrl) throw new Error("API Error");
const DL = F.data.downloadUrl;
const title = F.data.title || "Song";
const res = await A.get(DL, { responseType: "arraybuffer" });
await B.outputFile(p, Buffer.from(res.data));
api.setMessageReaction("โ
", m, () => {}, true);
return api.sendMessage({
body: `๐ต Title: ${title}`,
attachment: B.createReadStream(p)
}, t, () => {
if (B.existsSync(p)) B.unlinkSync(p);
}, m);
} catch (e) {
api.setMessageReaction("โ", m, () => {}, true);
return api.sendMessage(`โ Error: ${e.message}`, t, m);
}
}
};