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

92 lines
3.8 KiB
TypeScript
Raw Normal View History

2022-01-30 20:10:28 +07:00
import { Message, CommandInteraction, Interaction, VoiceChannel } from "discord.js";
2022-01-30 22:42:00 +07:00
import { getEmotes, makeSuccessEmbed, makeErrorEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
2022-01-30 20:10:28 +07:00
import DiscordProvider from "../../providers/Discord";
import Users from "../../services/Users"
import Environment from "../../providers/Environment";
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
const EMBEDS = {
SKIPPED: (data: Message | Interaction) => {
return makeSuccessEmbed({
title: `Skipped`,
user: (data instanceof Interaction) ? data.user : data.author
});
2022-01-30 22:42:00 +07:00
},
2022-02-04 22:42:59 +07:00
SKIPPED_LASTSONG: (data: Message | Interaction) => {
return makeSuccessEmbed({
title: `Skipped, that was the last song`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
2022-01-30 22:42:00 +07:00
NO_MUSIC_PLAYING: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `There are no music playing`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
USER_NOT_IN_VOICECHANNEL: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `You need to be in the voice channel first!`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
USER_NOT_IN_SAME_VOICECHANNEL: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `You are not in the same voice channel!`,
user: (data instanceof Interaction) ? data.user : data.author
});
2022-01-30 20:10:28 +07:00
}
}
export default class Skip {
async onCommand(command: string, args: any, message: Message) {
if (command.toLowerCase() !== 'skip') return;
await this.process(message, args);
}
async interactionCreate(interaction: CommandInteraction) {
if (interaction.isCommand()) {
if (typeof interaction.commandName === 'undefined') return;
if ((interaction.commandName).toLowerCase() !== 'skip') return;
await this.process(interaction, interaction.options);
}
}
async process(data: Interaction | Message, args: any) {
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
const isMessage = data instanceof Message;
if (!isSlashCommand && !isMessage) return;
if (!data.member) return;
if (!data.guildId) return;
const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
2022-01-30 22:42:00 +07:00
if (!data.member.voice.channel)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
2022-01-30 20:10:28 +07:00
if (!channel) return;
let voiceChannel = data.member.voice.channel;
2022-01-30 22:42:00 +07:00
if(!DiscordMusicPlayer.isGuildInstanceExists(data.guildId))
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
2022-01-30 20:10:28 +07:00
const instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
2022-01-30 22:42:00 +07:00
if(instance!.voiceChannel.id !== data.member.voice.channel.id)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] }, true);
2022-02-04 22:42:59 +07:00
if(instance?.queue.track.length === 0)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
2022-01-30 20:10:28 +07:00
instance!.skipTrack();
2022-02-04 22:42:59 +07:00
if(instance?.queue.track.length === 0)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SKIPPED_LASTSONG(data)] });
else
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SKIPPED(data)] });
2022-01-30 20:10:28 +07:00
}
}