forked from Kakashig1112/Beyond
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathspotify.ts
52 lines (50 loc) · 1.84 KB
/
spotify.ts
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
import { MessageType } from "@adiwajshing/baileys";
import MessageHandler from "../../Handlers/MessageHandler";
import BaseCommand from "../../lib/BaseCommand";
import request from "../../lib/request";
import Spotify from "../../lib/Spotify";
import WAClient from "../../lib/WAClient";
import { ISimplifiedMessage } from "../../typings";
export default class Command extends BaseCommand {
constructor(client: WAClient, handler: MessageHandler) {
super(client, handler, {
command: "spotify",
description:
"This will download the given spotify track and sends it as Audio",
category: "music",
usage: `${client.config.prefix}spotify [URL]`,
baseXp: 20,
aliases: ["sp"],
});
}
run = async (M: ISimplifiedMessage): Promise<void> => {
if (!M.urls.length)
return void M.reply(
`🔎 Provide the Spotify Track URL that you want to download`
);
const url = M.urls[0];
const track = new Spotify(url);
const info = await track.getInfo();
if (info.error)
return void M.reply(
`⚓ Error Fetching: ${url}. Check if the url is valid and try again`
);
const caption = `🎧 *Title:* ${info.name || ""}\n🎤 *Artists:* ${(
info.artists || []
).join(",")}\n💽 *Album:* ${info.album_name}\n📆 *Release Date:* ${
info.release_date || ""
}`;
M.reply(
await request.buffer(info?.cover_url as string),
MessageType.image,
undefined,
undefined,
caption
// eslint-disable-next-line @typescript-eslint/no-explicit-any
).catch((reason: any) => M.reply(`✖ An error occurred, Reason: ${reason}`));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
M.reply(await track.getAudio(), MessageType.audio).catch((reason: any) =>
M.reply(`✖ An error occurred, Reason: ${reason}`)
);
};
}