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

98 lines
3.5 KiB
TypeScript
Raw Normal View History

2023-03-05 14:46:25 +07:00
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
2022-03-03 20:56:49 +07:00
2023-03-05 14:46:25 +07:00
import { Message, CommandInteraction } from 'discord.js';
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
2022-07-05 14:58:27 +07:00
2024-06-16 00:34:31 +07:00
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayerTempFix';
2023-03-05 14:46:25 +07:00
import { I18n } from 'i18n';
import Locale from '../../services/Locale';
2022-01-30 20:10:28 +07:00
const EMBEDS = {
2022-06-07 03:08:27 +07:00
SKIPPED: (data: HybridInteractionMessage, locale: I18n) => {
2022-01-30 20:10:28 +07:00
return makeSuccessEmbed({
2022-06-07 03:08:27 +07:00
title: locale.__('musicplayer_skip.skipped'),
user: data.getUser()
2022-01-30 20:10:28 +07:00
});
2022-01-30 22:42:00 +07:00
},
2022-06-07 03:08:27 +07:00
SKIPPED_LASTSONG: (data: HybridInteractionMessage, locale: I18n) => {
2022-02-04 22:42:59 +07:00
return makeSuccessEmbed({
2022-06-07 03:08:27 +07:00
title: locale.__('musicplayer_skip.skipped_last_song'),
user: data.getUser()
2022-02-04 22:42:59 +07:00
});
},
2022-06-07 03:08:27 +07:00
NO_MUSIC_PLAYING: (data: HybridInteractionMessage, locale: I18n) => {
2022-01-30 22:42:00 +07:00
return makeErrorEmbed({
2022-06-07 03:08:27 +07:00
title: locale.__('musicplayer.no_music_playing'),
user: data.getUser()
2022-01-30 22:42:00 +07:00
});
},
2022-06-07 03:08:27 +07:00
USER_NOT_IN_VOICECHANNEL: (data: HybridInteractionMessage, locale: I18n) => {
2022-01-30 22:42:00 +07:00
return makeErrorEmbed({
2022-06-07 03:08:27 +07:00
title: locale.__('musicplayer.not_in_voice'),
user: data.getUser()
2022-01-30 22:42:00 +07:00
});
},
2022-06-07 03:08:27 +07:00
USER_NOT_IN_SAME_VOICECHANNEL: (data: HybridInteractionMessage, locale: I18n) => {
2022-01-30 22:42:00 +07:00
return makeErrorEmbed({
2022-06-07 03:08:27 +07:00
title: locale.__('musicplayer.different_voice_channel'),
user: data.getUser()
2022-01-30 22:42:00 +07:00
});
2022-01-30 20:10:28 +07:00
}
2023-03-05 14:46:25 +07:00
};
2022-01-30 20:10:28 +07:00
2023-03-05 14:46:25 +07:00
export default class Skip extends DiscordModule {
public id = 'Discord_MusicPlayer_Skip';
public commands = ['skip'];
public commandInteractionName = 'skip';
2022-03-03 20:56:49 +07:00
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
2022-01-30 20:10:28 +07:00
}
2023-03-05 14:46:25 +07:00
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
2022-03-03 20:56:49 +07:00
await this.run(new HybridInteractionMessage(interaction), interaction.options);
2022-01-30 20:10:28 +07:00
}
2022-03-03 20:56:49 +07:00
async run(data: HybridInteractionMessage, args: any) {
const guild = data.getGuild();
const member = data.getMember();
2022-01-30 20:10:28 +07:00
2022-03-03 20:56:49 +07:00
if (!guild || !member) return;
2022-01-30 20:10:28 +07:00
2022-06-07 03:08:27 +07:00
const locale = await Locale.getGuildLocale(guild.id);
2022-03-03 20:56:49 +07:00
const voiceChannel = member.voice.channel;
2022-01-30 20:10:28 +07:00
2022-03-03 20:56:49 +07:00
if (!voiceChannel)
2023-03-05 14:46:25 +07:00
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
});
2022-01-30 22:42:00 +07:00
2022-03-03 20:56:49 +07:00
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
2022-01-30 22:42:00 +07:00
2023-03-05 14:46:25 +07:00
if (!instance)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
2022-02-04 22:42:59 +07:00
2023-03-05 14:46:25 +07:00
if (instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(
data,
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] },
true
);
2022-01-30 20:10:28 +07:00
2023-03-05 14:46:25 +07:00
if (instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
});
2022-03-03 20:56:49 +07:00
instance.skipTrack();
2023-03-05 14:46:25 +07:00
if (instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.SKIPPED_LASTSONG(data, locale)]
});
else return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data, locale)] });
2022-01-30 20:10:28 +07:00
}
2023-03-05 14:46:25 +07:00
}