Support localization

This commit is contained in:
2022-06-07 03:08:27 +07:00
parent fb6808fa59
commit 6919bb7d90
19 changed files with 932 additions and 580 deletions
+24 -21
View File
@@ -4,36 +4,38 @@ import { Message, CommandInteraction, Interaction } from "discord.js";
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
import DiscordProvider from "../../providers/Discord";
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
import { I18n } from "i18n";
import Locale from "../../services/Locale";
const EMBEDS = {
SKIPPED: (data: Message | Interaction) => {
SKIPPED: (data: HybridInteractionMessage, locale: I18n) => {
return makeSuccessEmbed({
title: `Skipped`,
user: (data instanceof Interaction) ? data.user : data.author
title: locale.__('musicplayer_skip.skipped'),
user: data.getUser()
});
},
SKIPPED_LASTSONG: (data: Message | Interaction) => {
SKIPPED_LASTSONG: (data: HybridInteractionMessage, locale: I18n) => {
return makeSuccessEmbed({
title: `Skipped, that was the last song`,
user: (data instanceof Interaction) ? data.user : data.author
title: locale.__('musicplayer_skip.skipped_last_song'),
user: data.getUser()
});
},
NO_MUSIC_PLAYING: (data: Message | Interaction) => {
NO_MUSIC_PLAYING: (data: HybridInteractionMessage, locale: I18n) => {
return makeErrorEmbed({
title: `There are no music playing`,
user: (data instanceof Interaction) ? data.user : data.author
title: locale.__('musicplayer.no_music_playing'),
user: data.getUser()
});
},
USER_NOT_IN_VOICECHANNEL: (data: Message | Interaction) => {
USER_NOT_IN_VOICECHANNEL: (data: HybridInteractionMessage, locale: I18n) => {
return makeErrorEmbed({
title: `You need to be in the voice channel first!`,
user: (data instanceof Interaction) ? data.user : data.author
title: locale.__('musicplayer.not_in_voice'),
user: data.getUser()
});
},
USER_NOT_IN_SAME_VOICECHANNEL: (data: Message | Interaction) => {
USER_NOT_IN_SAME_VOICECHANNEL: (data: HybridInteractionMessage, locale: I18n) => {
return makeErrorEmbed({
title: `You are not in the same voice channel!`,
user: (data instanceof Interaction) ? data.user : data.author
title: locale.__('musicplayer.different_voice_channel'),
user: data.getUser()
});
}
}
@@ -59,27 +61,28 @@ export default class Skip extends DiscordModule{
if (!guild || !member) return;
const locale = await Locale.getGuildLocale(guild.id);
const voiceChannel = member.voice.channel;
if (!voiceChannel)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data.getRaw())] });
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
if(!instance)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
if(instance.voiceChannel.id !== voiceChannel.id)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data.getRaw())] }, true);
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] }, true);
if(instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
instance.skipTrack();
if(instance.queue.track.length === 0)
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED_LASTSONG(data.getRaw())] });
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED_LASTSONG(data, locale)] });
else
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data.getRaw())] });
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data, locale)] });
}
}