File size: 2,409 Bytes
2821330 | 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 | const axios = require("axios");
const path = require("path");
const fs = require("fs-extra");
module.exports.config = {
name: "lyrics",
version: "1.0",
hasPermission: 0,
description: "Get lyrics and artist image",
credits: "Jonell Magallanes",
usePrefix: true,
commandCategory: "Search",
usages: "[song title]",
cooldowns: 0,
};
module.exports.run = async function ({ api, event, args }) {
try {
const title = args.join(" ");
if (!title) {
return api.sendMessage(
"β Invalid Usage\nβββββββββββββββ\n\nPlease provide a song title to search for lyrics.",
event.threadID,
event.messageID
);
}
api.sendMessage("π Searching for lyrics", event.threadID, event.messageID);
const apiUrl = `https://aemt.me/lirik?text=${encodeURIComponent(title)}`;
console.log(`Fetching data from API: ${apiUrl}`);
const res = await axios.get(apiUrl);
const data = res.data.result;
if (!data || !data.lyrics) {
return api.sendMessage(
`No lyrics found for "${title}". Please try with a different song.`,
event.threadID,
event.messageID
);
}
const artistImageResponse = await axios.get(data.artistImage, { responseType: "arraybuffer" });
const imageFileName = `${data.title.replace(/\s/g, "_").toLowerCase()}_image.jpg`;
const imagePath = path.join(__dirname, "images", imageFileName);
await fs.outputFile(imagePath, artistImageResponse.data);
const message = `π΅ Lyrics for "${data.title}" by ${data.artist}\nβββββββββββββββ\n\n${data.lyrics}`;
const imgData = fs.createReadStream(imagePath);
await api.sendMessage({
body: message,
attachment: imgData,
}, event.threadID);
console.log(`Lyrics and image successfully sent for "${data.title}"`);
await fs.remove(imagePath);
console.log(`Image file ${imagePath} removed.`);
} catch (error) {
console.error("Error fetching lyrics:", error);
return api.sendMessage(
"An error occurred while fetching lyrics. Please try again later.",
event.threadID,
event.messageID
);
}
};
|