Files
Yumi/src/discord/MusicPlayer/NowPlaying.ts
T

65 lines
2.6 KiB
TypeScript
Raw Normal View History

2022-03-03 20:56:49 +07:00
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
2022-02-05 00:32:02 +07:00
import { Message, CommandInteraction, Interaction, MessageActionRow, TextChannel, MessageButton } from "discord.js";
2022-03-03 20:56:49 +07:00
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
2022-02-05 00:32:02 +07:00
import DiscordProvider from "../../providers/Discord";
2022-02-28 11:50:47 +07:00
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
2022-02-05 00:32:02 +07:00
const EMBEDS = {
NOW_PLAYING: (data: Message | Interaction, track: ValidTracks) => {
const embed = makeInfoEmbed({
title: 'Now playing',
icon: '🎵',
description: `${track.title}`,
user: DiscordProvider.client.user
});
2022-03-04 00:29:50 +07:00
const highestResolutionThumbnail = track.thumbnails.reduce((prev, current) => (prev.height * prev.width > current.height * current.width) ? prev : current)
if(highestResolutionThumbnail)
embed.setImage(highestResolutionThumbnail.url);
2022-02-05 00:32:02 +07:00
return embed;
},
NO_MUSIC_PLAYING: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `There are no music playing`,
user: (data instanceof Interaction) ? data.user : data.author
});
}
}
2022-03-03 20:56:49 +07:00
export default class NowPlaying extends DiscordModule {
public id = "Discord_MusicPlayer_NowPlaying";
public commands = ["nowplaying", "np"];
public commandInteractionName = "nowplaying";
2022-02-05 00:32:02 +07:00
2022-03-03 20:56:49 +07:00
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
2022-02-05 00:32:02 +07:00
}
2022-03-03 20:56:49 +07:00
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
await this.run(new HybridInteractionMessage(interaction), interaction.options);
2022-02-05 00:32:02 +07:00
}
2022-03-03 20:56:49 +07:00
async run(data: HybridInteractionMessage, args: any) {
2022-02-05 00:32:02 +07:00
2022-03-03 20:56:49 +07:00
const guild = data.getGuild();
if(!guild) return;
2022-02-05 00:32:02 +07:00
2022-03-03 20:56:49 +07:00
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
if(!instance || !instance.queue.track[0]) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
2022-02-05 00:32:02 +07:00
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setEmoji('▶️')
.setLabel('Open on YouTube')
.setURL(encodeURI(`https://www.youtube.com/watch?v=${instance.queue.track[0].id}`))
.setStyle('LINK'),
)
2022-03-03 20:56:49 +07:00
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOW_PLAYING(data.getRaw(), instance.queue.track[0])], components: [row] });
2022-02-05 00:32:02 +07:00
}
}