2022-06-07 03:08:27 +07:00
|
|
|
import { I18n } from "i18n";
|
2022-03-03 23:57:30 +07:00
|
|
|
import { Message, CommandInteraction, Interaction, MessageActionRow, ButtonInteraction, MessageSelectMenu, MessageSelectOptionData } from "discord.js";
|
|
|
|
|
|
2022-06-07 03:08:27 +07:00
|
|
|
import DiscordMusicPlayer, { DiscordMusicPlayerLoopMode } from "../../providers/DiscordMusicPlayer";
|
|
|
|
|
import Locale from "../../services/Locale";
|
|
|
|
|
|
|
|
|
|
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
|
|
|
|
import { makeErrorEmbed, makeSuccessEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
2022-03-03 23:57:30 +07:00
|
|
|
const EMBEDS = {
|
2022-06-07 03:08:27 +07:00
|
|
|
INVALID_LOOP_MODE: (data: HybridInteractionMessage, locale: I18n) => {
|
2022-03-03 23:57:30 +07:00
|
|
|
return makeErrorEmbed({
|
2022-06-07 03:08:27 +07:00
|
|
|
title: locale.__('musicplayer_loop.invalid'),
|
|
|
|
|
user: data.getUser()
|
2022-03-03 23:57:30 +07:00
|
|
|
});
|
|
|
|
|
},
|
2022-06-07 03:08:27 +07:00
|
|
|
LOOP_STATUS: (data: HybridInteractionMessage, locale: I18n, loopMode: DiscordMusicPlayerLoopMode) => {
|
2022-03-03 23:57:30 +07:00
|
|
|
let embed = makeInfoEmbed({
|
2022-06-27 20:28:01 +07:00
|
|
|
title: locale.__('musicplayer_loop.info', {
|
|
|
|
|
MODE: loopMode
|
|
|
|
|
}),
|
2022-06-07 03:08:27 +07:00
|
|
|
description: locale.__('musicplayer_loop.valid_args'),
|
|
|
|
|
user: data.getUser()
|
2022-03-03 23:57:30 +07:00
|
|
|
});
|
|
|
|
|
return embed;
|
|
|
|
|
},
|
2022-06-07 03:08:27 +07:00
|
|
|
LOOP_SET: (data: HybridInteractionMessage, locale: I18n, loopMode: DiscordMusicPlayerLoopMode) => {
|
2022-03-03 23:57:30 +07:00
|
|
|
let embed = makeSuccessEmbed({
|
2022-06-27 20:28:01 +07:00
|
|
|
title: locale.__('musicplayer_loop.loop_set', {
|
|
|
|
|
MODE: loopMode
|
|
|
|
|
}),
|
2022-06-07 03:08:27 +07:00
|
|
|
user: data.getUser()
|
2022-03-03 23:57:30 +07:00
|
|
|
});
|
|
|
|
|
return embed;
|
|
|
|
|
},
|
2022-06-07 03:08:27 +07:00
|
|
|
USER_NOT_IN_VOICECHANNEL: (data: HybridInteractionMessage, locale: I18n) => {
|
2022-03-03 23:57:30 +07:00
|
|
|
return makeErrorEmbed({
|
2022-06-07 03:08:27 +07:00
|
|
|
title: locale.__('musicplayer.not_in_voice'),
|
|
|
|
|
user: data.getUser()
|
2022-03-03 23:57:30 +07:00
|
|
|
});
|
|
|
|
|
},
|
2022-06-07 03:08:27 +07:00
|
|
|
USER_NOT_IN_SAME_VOICECHANNEL: (data: HybridInteractionMessage, locale: I18n) => {
|
2022-03-03 23:57:30 +07:00
|
|
|
return makeErrorEmbed({
|
2022-06-07 03:08:27 +07:00
|
|
|
title: locale.__('musicplayer.different_voice_channel'),
|
|
|
|
|
user: data.getUser()
|
2022-03-03 23:57:30 +07:00
|
|
|
});
|
|
|
|
|
},
|
2022-06-07 03:08:27 +07:00
|
|
|
NO_MUSIC_PLAYING: (data: HybridInteractionMessage, locale: I18n) => {
|
2022-03-03 23:57:30 +07:00
|
|
|
return makeErrorEmbed({
|
2022-06-07 03:08:27 +07:00
|
|
|
title: locale.__('musicplayer.no_music_playing'),
|
|
|
|
|
user: data.getUser()
|
2022-03-03 23:57:30 +07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export default class Loop extends DiscordModule {
|
|
|
|
|
|
|
|
|
|
public id = "Discord_MusicPlayer_Loop";
|
|
|
|
|
public commands = ["loop"];
|
|
|
|
|
public commandInteractionName = "loop";
|
|
|
|
|
|
|
|
|
|
async GuildOnModuleCommand(args: any, message: Message) {
|
|
|
|
|
await this.run(new HybridInteractionMessage(message), args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
|
|
|
|
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async run(data: HybridInteractionMessage, args: any) {
|
|
|
|
|
|
|
|
|
|
const guild = data.getGuild();
|
|
|
|
|
const user = data.getUser();
|
|
|
|
|
const member = data.getMember();
|
|
|
|
|
const channel = data.getChannel();
|
|
|
|
|
|
|
|
|
|
if (!guild || !user || !member || !channel) return;
|
2022-06-07 03:08:27 +07:00
|
|
|
const locale = await Locale.getGuildLocale(guild.id);
|
2022-03-03 23:57:30 +07:00
|
|
|
|
|
|
|
|
let query;
|
|
|
|
|
|
|
|
|
|
if (data.isMessage()) {
|
|
|
|
|
if (args.length !== 0)
|
|
|
|
|
query = args.join(' ');
|
|
|
|
|
}
|
|
|
|
|
else if (data.isSlashCommand())
|
|
|
|
|
query = args.getSubcommand();
|
|
|
|
|
|
|
|
|
|
const voiceChannel = member.voice.channel;
|
|
|
|
|
|
|
|
|
|
if (!voiceChannel)
|
2022-06-07 03:08:27 +07:00
|
|
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
2022-03-03 23:57:30 +07:00
|
|
|
|
|
|
|
|
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
|
|
|
|
|
|
|
|
|
if (!instance)
|
2022-06-07 03:08:27 +07:00
|
|
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
2022-03-03 23:57:30 +07:00
|
|
|
|
|
|
|
|
if (instance.voiceChannel.id !== voiceChannel.id)
|
2022-06-07 03:08:27 +07:00
|
|
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
|
2022-03-03 23:57:30 +07:00
|
|
|
|
|
|
|
|
if (instance.queue.track.length === 0)
|
2022-06-07 03:08:27 +07:00
|
|
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
2022-03-03 23:57:30 +07:00
|
|
|
|
|
|
|
|
if (!query)
|
2022-06-07 03:08:27 +07:00
|
|
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_STATUS(data, locale, instance.getLoopMode())] });
|
2022-03-03 23:57:30 +07:00
|
|
|
|
|
|
|
|
let enumKey = Object.keys(DiscordMusicPlayerLoopMode)[Object.values(DiscordMusicPlayerLoopMode).indexOf(query.toLowerCase())];
|
|
|
|
|
|
|
|
|
|
if(enumKey) {
|
|
|
|
|
instance.setLoopMode(DiscordMusicPlayerLoopMode[enumKey as keyof typeof DiscordMusicPlayerLoopMode]);
|
2022-06-07 03:08:27 +07:00
|
|
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_SET(data, locale, instance.getLoopMode())] });
|
2022-03-03 23:57:30 +07:00
|
|
|
}
|
|
|
|
|
|
2022-06-07 03:08:27 +07:00
|
|
|
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_LOOP_MODE(data, locale)] });
|
2022-03-03 23:57:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|