mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 10:49:20 +00:00
Support localization
This commit is contained in:
@@ -30,6 +30,8 @@ RUN yarn
|
||||
COPY --from=build /home/node/app/prisma ./prisma/
|
||||
RUN yarn prisma generate
|
||||
|
||||
COPY --from=build /home/node/app/locales ./locales/
|
||||
|
||||
COPY --from=build /home/node/app/dist .
|
||||
|
||||
CMD [ "node", "index.js"]
|
||||
+112
-10
@@ -1,12 +1,114 @@
|
||||
{
|
||||
"stats": {
|
||||
"title": "Stats",
|
||||
"description": "Stats of the bot",
|
||||
"uptime_since": "Uptime since",
|
||||
"users": "Users",
|
||||
"x_servers": "%s servers",
|
||||
"x_users": "%s users",
|
||||
"server_uptime_x": "Server %s",
|
||||
"process_uptime_x": "Process %s"
|
||||
}
|
||||
"common": {
|
||||
"available_args": "Available arguments",
|
||||
"no_permissions": "No permission",
|
||||
"no_permissions_description": "You need ``%s`` permission on this guild!"
|
||||
},
|
||||
"stats": {
|
||||
"title": "Stats",
|
||||
"info": "Current stats of the bot",
|
||||
"users": "Users",
|
||||
"x_servers": "%s servers",
|
||||
"x_users": "%s users",
|
||||
"uptime_since": "Uptime since",
|
||||
"server_uptime_x": "Server %s",
|
||||
"process_uptime_x": "Process %s"
|
||||
},
|
||||
"userinfo": {
|
||||
"title": "User Information",
|
||||
"info": "Show user information",
|
||||
"valid_args": "(``@Mention or User ID``)",
|
||||
"user_not_found": "Unable to find any matching user",
|
||||
"online": "Online",
|
||||
"idle": "Idle",
|
||||
"dnd": "Do not disturb",
|
||||
"offline": "Recently Offline",
|
||||
"unknown": "Offline / Unknown",
|
||||
"user_guild_info": "Information on this guild",
|
||||
"join_date_unknown": "Cannot determine join date",
|
||||
"join_date": "Joined %s",
|
||||
"guild_owner": "Owner of this guild",
|
||||
"custom_status": "Custom Status",
|
||||
"playing_x": "Playing %s",
|
||||
"streaming_x": "Streaming %s",
|
||||
"listening_x": "Listening to %s",
|
||||
"watching_x": "Watching %s",
|
||||
"competing_x": "Competing %s"
|
||||
},
|
||||
"say": {
|
||||
"title": "Say",
|
||||
"info": "Send a message as the bot",
|
||||
"valid_args": "``(Text message)``",
|
||||
"success": "Successfully sent a message",
|
||||
"error": "Unable to send the message"
|
||||
},
|
||||
"invite": {
|
||||
"title": "Invite",
|
||||
"info": "[Invite %s to your server!](%s)",
|
||||
"private": "%s's invite is currently private. Only the developers can add me to another server"
|
||||
},
|
||||
"musicplayer": {
|
||||
"now_playing": "Now playing",
|
||||
"now_playing_repeating": "Now playing (Repeating)",
|
||||
"no_music_playing": "There are no music playing",
|
||||
"not_in_voice": "You need to be in the voice channel first!",
|
||||
"different_voice_channel": "You are not in the same voice channel!",
|
||||
"track_error": "Error while playing music, skipping this track"
|
||||
},
|
||||
"musicplayer_join": {
|
||||
"success": "Successfully joined the voice channel",
|
||||
"error": "Unable to join the voice channel",
|
||||
"disconnected": "Disconnected",
|
||||
"disconnected_reason_disconnected": "I got disconnected from the voice channel",
|
||||
"in_use": "I can't join mutiple voice channel on the same guild.\n There are also somebody listening to the music in the voice channel I'm currently in.",
|
||||
"in_use_wait": "Wait until I finish playing there or I'm alone there. Better yet, join them!",
|
||||
"can_force_move": "\n\n**Or... just (ab)use your admin permissions and move me to where you want!**",
|
||||
"already_joined_title": "I'm already here",
|
||||
"already_joined_description": "Already in the voice channel you are currently connected to"
|
||||
},
|
||||
"musicplayer_leave": {
|
||||
"success": "Successfully left the voice channel"
|
||||
},
|
||||
"musicplayer_loop": {
|
||||
"info": "Current loop mode is %s",
|
||||
"valid_args": "Available loop mode: ``None`` ``Current``",
|
||||
"invalid": "Invalid loop mode",
|
||||
"loop_set": "Loop mode is now set to %s"
|
||||
},
|
||||
"musicplayer_pause": {
|
||||
"paused": "Paused",
|
||||
"already_paused": "Already paused"
|
||||
},
|
||||
"musicplayer_resume": {
|
||||
"resumed": "Resumed",
|
||||
"not_paused": "The music is not paused"
|
||||
},
|
||||
"musicplayer_play": {
|
||||
"title": "Play",
|
||||
"info": "Play a song",
|
||||
"valid_args": "``(Search query or Link)``",
|
||||
"queue_added_song": "Song added to queue!",
|
||||
"queue_added_songs": "Songs added to queue!",
|
||||
"queue_added_songs_description": "Added %s songs to the queue",
|
||||
"error": "Error while looking up the song"
|
||||
},
|
||||
"musicplayer_queue": {
|
||||
"title": "Queue",
|
||||
"empty": "The queue is empty!",
|
||||
"now_playing": "Now playing",
|
||||
"upcoming_song": "Upcoming song",
|
||||
"looping_current": "(Looping current)",
|
||||
"song_x_in_queue": "There are %s song in the queue!"
|
||||
},
|
||||
"musicplayer_search": {
|
||||
"title": "Search",
|
||||
"info": "Search for a song",
|
||||
"valid_args": "``(Search query)``",
|
||||
"title_result": "Search result",
|
||||
"x_results_found": "%s results found"
|
||||
},
|
||||
"musicplayer_skip": {
|
||||
"skipped": "Skipped",
|
||||
"skipped_last_song": "Skipped, that was the last song"
|
||||
}
|
||||
}
|
||||
+112
-10
@@ -1,12 +1,114 @@
|
||||
{
|
||||
"stats": {
|
||||
"title": "stats.title",
|
||||
"description": "stats.description",
|
||||
"uptime_since": "stats.uptime_since",
|
||||
"users": "stats.users",
|
||||
"x_servers": "%s stats.x_servers",
|
||||
"x_users": "%s stats.x_users",
|
||||
"server_uptime_x": "stats.server_uptime_x %s",
|
||||
"process_uptime_x": "stats.process_uptime_x %s"
|
||||
}
|
||||
"common": {
|
||||
"available_args": "Available arguments",
|
||||
"no_permissions": "許可していない",
|
||||
"no_permissions_description": "このギルドでは ``%s`` の許可が必要です!"
|
||||
},
|
||||
"stats": {
|
||||
"title": "統計情報",
|
||||
"info": "現在のボットの統計情報",
|
||||
"users": "ユーザー",
|
||||
"x_servers": "%s サーヴァーズ",
|
||||
"x_users": "%s ユーザー",
|
||||
"uptime_since": "アップタイム",
|
||||
"server_uptime_x": "サーヴァーズ %s",
|
||||
"process_uptime_x": "プロセス %s"
|
||||
},
|
||||
"userinfo": {
|
||||
"title": "ユーザー情報",
|
||||
"info": "ユーザー情報を表示する",
|
||||
"valid_args": "(``@メンションまたはユーザーID``)",
|
||||
"user_not_found": "一致するユーザーを見つけることができません",
|
||||
"online": "オンライン",
|
||||
"idle": "アイドル",
|
||||
"dnd": "起こさないで",
|
||||
"offline": "最近のオフライン",
|
||||
"unknown": "オフライン/不明",
|
||||
"user_guild_info": "このギルドの情報",
|
||||
"join_date_unknown": "このギルドの加入日が特定できない",
|
||||
"join_date": "加入 %s",
|
||||
"guild_owner": "このギルドのオーナー",
|
||||
"custom_status": "カスタムステータス",
|
||||
"playing_x": "%sをプレイ中",
|
||||
"streaming_x": "%sをストリーミング中",
|
||||
"listening_x": "%sを再生中",
|
||||
"watching_x": "%s鑑賞中",
|
||||
"competing_x": "%sに参戦中です"
|
||||
},
|
||||
"say": {
|
||||
"title": "言うこと",
|
||||
"info": "ボットとしてメッセージを送信する",
|
||||
"valid_args": "``(テキストメッセージ)``",
|
||||
"success": "メッセージの送信に成功しました",
|
||||
"error": "メッセージを送信できない"
|
||||
},
|
||||
"invite": {
|
||||
"title": "招待状リンク",
|
||||
"info": "[あなたのサーバに%sを招待してください](%s)",
|
||||
"private": "%sの招待は現在非公開です。開発者だけが私を別のサーバーに追加することができます"
|
||||
},
|
||||
"musicplayer": {
|
||||
"now_playing": "再生中",
|
||||
"now_playing_repeating": "再生中(リピート再生)",
|
||||
"no_music_playing": "音楽が流れていない",
|
||||
"not_in_voice": "まず音声チャンネルに入る必要がある!",
|
||||
"different_voice_channel": "音声チャンネルが違うぞ!",
|
||||
"track_error": "音楽再生中にエラーが発生し、このトラックをスキップしています。"
|
||||
},
|
||||
"musicplayer_join": {
|
||||
"success": "音声チャネルへの参加に成功",
|
||||
"error": "音声チャネルに参加できない",
|
||||
"disconnected": "ディスコネクト",
|
||||
"disconnected_reason_disconnected": "音声チャネルから切断された",
|
||||
"in_use": "同じギルドで複数のボイスチャンネルに参加することができません。\n今入っているボイスチャンネルで音楽を聴いている人がいます。",
|
||||
"in_use_wait": "そこで遊び終わるか、そこで一人になるまで待ってください。いっそのこと、参加しちゃいましょう",
|
||||
"can_force_move": "\n\n**もしくは...管理者権限を悪用して、私を好きな場所に移動させてください!**",
|
||||
"already_joined_title": "もうここにいる",
|
||||
"already_joined_description": "現在接続している音声チャンネルですでに"
|
||||
},
|
||||
"musicplayer_leave": {
|
||||
"success": "音声チャネルからの離脱に成功"
|
||||
},
|
||||
"musicplayer_loop": {
|
||||
"info": "現在のループモードは「%s」です。",
|
||||
"valid_args": "使用可能なループモード: ``None`` ``Current``",
|
||||
"invalid": "ループモードが正しくない",
|
||||
"loop_set": "ループモードが「%s」になりました。"
|
||||
},
|
||||
"musicplayer_pause": {
|
||||
"paused": "一時停止",
|
||||
"already_paused": "すでに一時停止中"
|
||||
},
|
||||
"musicplayer_resume": {
|
||||
"resumed": "再開しました",
|
||||
"not_paused": "現在、音楽は一時停止していません"
|
||||
},
|
||||
"musicplayer_play": {
|
||||
"title": "プレイ",
|
||||
"info": "曲を再生する",
|
||||
"valid_args": "``(検索クエリまたはリンク)``",
|
||||
"queue_added_song": "キューに曲を追加しました",
|
||||
"queue_added_songs": "たくさんの曲をキューに追加しました",
|
||||
"queue_added_songs_description": "キューに%s曲を追加",
|
||||
"error": "曲の検索中にエラーが発生"
|
||||
},
|
||||
"musicplayer_queue": {
|
||||
"title": "キュー",
|
||||
"empty": "キューは空です!",
|
||||
"now_playing": "再生中",
|
||||
"upcoming_song": "次の曲",
|
||||
"looping_current": "(この曲の繰り返し)",
|
||||
"song_x_in_queue": "%s曲も並んでいますよ。"
|
||||
},
|
||||
"musicplayer_search": {
|
||||
"title": "検索",
|
||||
"info": "楽曲を検索する",
|
||||
"valid_args": "``(検索クエリ)``",
|
||||
"title_result": "検索結果",
|
||||
"x_results_found": "%s件見つかりました。"
|
||||
},
|
||||
"musicplayer_skip": {
|
||||
"skipped": "スキップした",
|
||||
"skipped_last_song": "スキップした、それは最後の曲だった"
|
||||
}
|
||||
}
|
||||
+14
-8
@@ -1,24 +1,25 @@
|
||||
import { Message, CommandInteraction, Interaction } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import Environment from '../providers/Environment';
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
import Users from '../services/Users';
|
||||
import Locale from '../services/Locale';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from '../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
INVITE_INFO: (data: Message | Interaction) => {
|
||||
INVITE_INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
const user = data.getUser();
|
||||
let message;
|
||||
if (Users.isDeveloper(data.member?.user.id!) || !Environment.get().PRIVATE_BOT)
|
||||
message = `[Invite ${DiscordProvider.client.user?.username} to your server!](https://discord.com/api/oauth2/authorize?client_id=${DiscordProvider.client.user?.id}&permissions=0&scope=bot%20applications.commands)`;
|
||||
if (!Environment.get().PRIVATE_BOT || user != null && Users.isDeveloper(user.id))
|
||||
message = locale.__('invite.info', DiscordProvider.client.user!.username, `https://discord.com/api/oauth2/authorize?client_id=${DiscordProvider.client.user?.id}&permissions=0&scope=bot%20applications.commands`);
|
||||
|
||||
return makeInfoEmbed({
|
||||
title: `Invite`,
|
||||
description:
|
||||
message ||
|
||||
`${DiscordProvider.client.user?.username}'s invite is currently private. Only the developers can add me to another server`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
description: message || locale.__('invite.private', DiscordProvider.client.user!.username),
|
||||
user
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -37,8 +38,13 @@ export default class Invite extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
const guild = data.getGuild();
|
||||
if (!guild) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INVITE_INFO(data.getRaw())]
|
||||
embeds: [EMBEDS.INVITE_INFO(data, locale)]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
|
||||
import {
|
||||
Message,
|
||||
CommandInteraction,
|
||||
@@ -14,6 +12,8 @@ import {
|
||||
TextChannel,
|
||||
VoiceBasedChannel
|
||||
} from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import {
|
||||
makeSuccessEmbed,
|
||||
makeErrorEmbed,
|
||||
@@ -31,65 +31,57 @@ import DiscordMusicPlayer, {
|
||||
DiscordMusicPlayerLoopMode
|
||||
} from '../../providers/DiscordMusicPlayer';
|
||||
|
||||
const EMBEDS = {
|
||||
VOICECHANNEL_JOINED: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed({
|
||||
title: `Success`,
|
||||
description: `Joined voice channel`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
VOICECHANNEL_DISCONNECTED: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed({
|
||||
title: `Disconnected`,
|
||||
description: `I got disconnected from the voice channel`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
VOICECHANNEL_INUSE: (data: Message | Interaction) => {
|
||||
let haveForceMove =
|
||||
data instanceof Message
|
||||
? (data as Message).member!.permissions.has([Permissions.FLAGS.MOVE_MEMBERS])
|
||||
: ((data as Interaction).member! as GuildMember).permissions.has([Permissions.FLAGS.MOVE_MEMBERS]);
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
const EMBEDS = {
|
||||
VOICECHANNEL_JOINED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeSuccessEmbed({
|
||||
title: locale.__('musicplayer_join.success'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
VOICECHANNEL_DISCONNECTED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeSuccessEmbed({
|
||||
title: locale.__('musicplayer_join.disconnected'),
|
||||
description: locale.__('musicplayer_join.disconnected_reason_disconnected'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
VOICECHANNEL_INUSE: (data: HybridInteractionMessage, locale: I18n, haveForceMove: boolean) => {
|
||||
return makeErrorEmbed({
|
||||
title: `I can't open portal to parallel universe`,
|
||||
description: `I can't join mutiple voice channel on the same guild.
|
||||
I wish I had a superpower, maybe... one day I will.
|
||||
|
||||
There are also somebody listening to the music in the voice channel I'm currently in.${
|
||||
!haveForceMove
|
||||
? ` Wait until I finish playing there or I'm alone there. Better yet, join them!`
|
||||
: " Wait until I finish playing there or I'm alone there. Better yet, join them! \n\n**Or... just (ab)use your admin permissions and move me to where you want!**"
|
||||
title: locale.__('musicplayer_join.error'),
|
||||
description: `${locale.__('musicplayer_join.in_use')}\n\n${locale.__('musicplayer_join.in_use_wait')}${
|
||||
haveForceMove ? locale.__('musicplayer_join.can_force_move') : ''
|
||||
}`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
VOICECHANNEL_ALREADY_JOINED: (data: Message | Interaction) => {
|
||||
VOICECHANNEL_ALREADY_JOINED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeInfoEmbed({
|
||||
title: `I'm already here`,
|
||||
description: `Already in the voice channel you are currently connected to`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
title: locale.__('musicplayer_join.already_joined_title'),
|
||||
description: locale.__('musicplayer_join.already_joined_description'),
|
||||
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()
|
||||
});
|
||||
},
|
||||
MUSIC_ERROR: (data: Message | Interaction, err: Error) => {
|
||||
MUSIC_ERROR: (data: HybridInteractionMessage, locale: I18n, error: Error) => {
|
||||
return makeErrorEmbed({
|
||||
title: `Error while playing music, skipping this track`,
|
||||
description: `${err.message}`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
title: locale.__('musicplayer.track_error'),
|
||||
description: error.message,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
NOW_PLAYING: (data: Message | Interaction, track: ValidTracks) => {
|
||||
NOW_PLAYING: (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
const embed = makeInfoEmbed({
|
||||
title: ' Now playing',
|
||||
icon: '🎵',
|
||||
description: `${track.title}`,
|
||||
title: locale.__('musicplayer.now_playing'),
|
||||
icon: '🎵 ',
|
||||
description: track.title,
|
||||
user: DiscordProvider.client.user
|
||||
});
|
||||
|
||||
@@ -101,10 +93,10 @@ const EMBEDS = {
|
||||
|
||||
return embed;
|
||||
},
|
||||
NOW_REPEATING: (data: Message | Interaction, track: ValidTracks) => {
|
||||
NOW_REPEATING: (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
const embed = makeInfoEmbed({
|
||||
title: ' Now playing (Repeating)',
|
||||
icon: '🎵',
|
||||
title: locale.__('musicplayer.now_playing_repeating'),
|
||||
icon: '🎵 ',
|
||||
description: `${track.title}`,
|
||||
user: DiscordProvider.client.user
|
||||
});
|
||||
@@ -144,6 +136,8 @@ export async function joinVoiceChannelProcedure(
|
||||
const bot = guild.me;
|
||||
if (!bot) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
// If already in VoiceChannel
|
||||
if (bot.voice.channelId) {
|
||||
// But, no music instance yet (The bot might just restarted)
|
||||
@@ -161,7 +155,7 @@ export async function joinVoiceChannelProcedure(
|
||||
instance!.joinVoiceChannel(voiceChannel, channel);
|
||||
if (!isAcceptableInteraction)
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.VOICECHANNEL_JOINED(data.getRaw())]
|
||||
embeds: [EMBEDS.VOICECHANNEL_JOINED(data, locale)]
|
||||
});
|
||||
}
|
||||
// And, already have instance on the guild
|
||||
@@ -170,7 +164,7 @@ export async function joinVoiceChannelProcedure(
|
||||
if (channel.id === instance.voiceChannel.id) {
|
||||
if (!isAcceptableInteraction)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.VOICECHANNEL_ALREADY_JOINED(data.getRaw())]
|
||||
embeds: [EMBEDS.VOICECHANNEL_ALREADY_JOINED(data, locale)]
|
||||
});
|
||||
else return;
|
||||
}
|
||||
@@ -181,7 +175,13 @@ export async function joinVoiceChannelProcedure(
|
||||
if (activeMembers.size > 0) {
|
||||
if (!isAcceptableInteraction)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.VOICECHANNEL_INUSE(data.getRaw())]
|
||||
embeds: [
|
||||
EMBEDS.VOICECHANNEL_INUSE(
|
||||
data,
|
||||
locale,
|
||||
member.permissions.has([Permissions.FLAGS.MOVE_MEMBERS])
|
||||
)
|
||||
]
|
||||
});
|
||||
else return;
|
||||
}
|
||||
@@ -191,7 +191,7 @@ export async function joinVoiceChannelProcedure(
|
||||
await bot.voice.setChannel(voiceChannel);
|
||||
if (!isAcceptableInteraction)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.VOICECHANNEL_JOINED(data.getRaw())]
|
||||
embeds: [EMBEDS.VOICECHANNEL_JOINED(data, locale)]
|
||||
});
|
||||
else return;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ export async function joinVoiceChannelProcedure(
|
||||
|
||||
instance!.joinVoiceChannel(voiceChannel, channel);
|
||||
if (!isAcceptableInteraction)
|
||||
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.VOICECHANNEL_JOINED(data.getRaw())] });
|
||||
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.VOICECHANNEL_JOINED(data, locale)] });
|
||||
}
|
||||
|
||||
if (!instance) return;
|
||||
@@ -235,12 +235,12 @@ export async function joinVoiceChannelProcedure(
|
||||
if (event.instance.getLoopMode() === DiscordMusicPlayerLoopMode.Current) {
|
||||
isLoopMessageSent = true;
|
||||
await sendMessage(event.instance.textChannel, undefined, {
|
||||
embeds: [EMBEDS.NOW_REPEATING(data.getRaw(), event.instance.queue.track[0])],
|
||||
embeds: [EMBEDS.NOW_REPEATING(data, locale, event.instance.queue.track[0])],
|
||||
components: [row]
|
||||
});
|
||||
} else {
|
||||
await sendMessage(event.instance.textChannel, undefined, {
|
||||
embeds: [EMBEDS.NOW_PLAYING(data.getRaw(), event.instance.queue.track[0])],
|
||||
embeds: [EMBEDS.NOW_PLAYING(data, locale, event.instance.queue.track[0])],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
@@ -250,7 +250,7 @@ export async function joinVoiceChannelProcedure(
|
||||
instance.events.on('error', async (event: PlayerErrorEvent) => {
|
||||
if (event.instance.textChannel) {
|
||||
await sendMessage(event.instance.textChannel, undefined, {
|
||||
embeds: [EMBEDS.MUSIC_ERROR(data.getRaw(), event.error)]
|
||||
embeds: [EMBEDS.MUSIC_ERROR(data, locale, event.error)]
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -258,7 +258,7 @@ export async function joinVoiceChannelProcedure(
|
||||
instance.events.on('disconnect', async (event: VoiceDisconnectedEvent) => {
|
||||
if (event.instance.textChannel) {
|
||||
await sendMessage(event.instance.textChannel, undefined, {
|
||||
embeds: [EMBEDS.VOICECHANNEL_DISCONNECTED(data.getRaw())]
|
||||
embeds: [EMBEDS.VOICECHANNEL_DISCONNECTED(data, locale)]
|
||||
});
|
||||
}
|
||||
|
||||
@@ -285,15 +285,15 @@ export default class Join 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())]
|
||||
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
console.log(data.isButton);
|
||||
await joinVoiceChannelProcedure(data, instance, voiceChannel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,35 @@
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction } from "discord.js";
|
||||
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
|
||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordProvider from "../../providers/Discord";
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
|
||||
const EMBEDS = {
|
||||
VOICECHANNEL_LEFT: (data: Message | Interaction) => {
|
||||
VOICECHANNEL_LEFT: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeSuccessEmbed({
|
||||
title: `Success`,
|
||||
description: `Left the voice channel`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_leave.success'),
|
||||
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()
|
||||
});
|
||||
},
|
||||
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_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()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -54,20 +55,22 @@ export default class Leave 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)] });
|
||||
|
||||
let 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())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] });
|
||||
|
||||
|
||||
DiscordMusicPlayer.destoryGuildInstance(guild.id);
|
||||
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.VOICECHANNEL_LEFT(data.getRaw())] });
|
||||
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.VOICECHANNEL_LEFT(data, locale)] });
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,47 +1,49 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction, Interaction, MessageActionRow, ButtonInteraction, MessageSelectMenu, MessageSelectOptionData } from "discord.js";
|
||||
import { makeErrorEmbed, makeSuccessEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||
import DiscordMusicPlayer, { DiscordMusicPlayerLoopMode } from "../../providers/DiscordMusicPlayer";
|
||||
|
||||
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";
|
||||
const EMBEDS = {
|
||||
INVALID_LOOP_MODE: (data: Message | Interaction) => {
|
||||
INVALID_LOOP_MODE: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: `Invalid loop mode`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_loop.invalid'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
LOOP_STATUS: (data: Message | Interaction, loopMode: DiscordMusicPlayerLoopMode) => {
|
||||
LOOP_STATUS: (data: HybridInteractionMessage, locale: I18n, loopMode: DiscordMusicPlayerLoopMode) => {
|
||||
let embed = makeInfoEmbed({
|
||||
title: `Current loop mode is ${loopMode}`,
|
||||
description: "Available loop mode: ``None`` ``Current``",
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_loop.info', loopMode),
|
||||
description: locale.__('musicplayer_loop.valid_args'),
|
||||
user: data.getUser()
|
||||
});
|
||||
return embed;
|
||||
},
|
||||
LOOP_SET: (data: Message | Interaction, loopMode: DiscordMusicPlayerLoopMode) => {
|
||||
LOOP_SET: (data: HybridInteractionMessage, locale: I18n, loopMode: DiscordMusicPlayerLoopMode) => {
|
||||
let embed = makeSuccessEmbed({
|
||||
title: `Loop mode is now set to ${loopMode}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_loop.loop_set', loopMode),
|
||||
user: data.getUser()
|
||||
});
|
||||
return embed;
|
||||
},
|
||||
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()
|
||||
});
|
||||
},
|
||||
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()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -67,6 +69,7 @@ export default class Loop extends DiscordModule {
|
||||
const channel = data.getChannel();
|
||||
|
||||
if (!guild || !user || !member || !channel) return;
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
let query;
|
||||
|
||||
@@ -80,30 +83,30 @@ export default class Loop extends DiscordModule {
|
||||
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)] });
|
||||
|
||||
if (!query)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_STATUS(data.getRaw(), instance.getLoopMode())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_STATUS(data, locale, instance.getLoopMode())] });
|
||||
|
||||
let enumKey = Object.keys(DiscordMusicPlayerLoopMode)[Object.values(DiscordMusicPlayerLoopMode).indexOf(query.toLowerCase())];
|
||||
|
||||
if(enumKey) {
|
||||
instance.setLoopMode(DiscordMusicPlayerLoopMode[enumKey as keyof typeof DiscordMusicPlayerLoopMode]);
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_SET(data.getRaw(), instance.getLoopMode())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_SET(data, locale, instance.getLoopMode())] });
|
||||
}
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_LOOP_MODE(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_LOOP_MODE(data, locale)] });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { Message, CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
|
||||
import { I18n } from "i18n";
|
||||
|
||||
import { Message, CommandInteraction, Interaction, MessageActionRow, TextChannel, MessageButton } from "discord.js";
|
||||
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordProvider from "../../providers/Discord";
|
||||
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
|
||||
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
|
||||
const EMBEDS = {
|
||||
NOW_PLAYING: (data: Message | Interaction, track: ValidTracks) => {
|
||||
NOW_PLAYING: (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
const embed = makeInfoEmbed({
|
||||
title: ' Now playing',
|
||||
icon: '🎵',
|
||||
description: `${track.title}`,
|
||||
title: locale.__('musicplayer.now_playing'),
|
||||
icon: '🎵 ',
|
||||
description: track.title,
|
||||
user: DiscordProvider.client.user
|
||||
});
|
||||
|
||||
@@ -21,10 +24,10 @@ const EMBEDS = {
|
||||
|
||||
return embed;
|
||||
},
|
||||
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()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -48,8 +51,9 @@ export default class NowPlaying extends DiscordModule {
|
||||
const guild = data.getGuild();
|
||||
if(!guild) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if(!instance || !instance.queue.track[0]) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
|
||||
if(!instance || !instance.queue.track[0]) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
@@ -60,6 +64,6 @@ export default class NowPlaying extends DiscordModule {
|
||||
.setStyle('LINK'),
|
||||
)
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOW_PLAYING(data.getRaw(), instance.queue.track[0])], components: [row] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOW_PLAYING(data, locale, instance.queue.track[0])], components: [row] });
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,43 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
|
||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import { I18n } from "i18n";
|
||||
|
||||
import DiscordProvider from "../../providers/Discord";
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
|
||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
|
||||
const EMBEDS = {
|
||||
PAUSED: (data: Message | Interaction) => {
|
||||
PAUSED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeSuccessEmbed({
|
||||
title: `Paused`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_pause.paused'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
ALREADY_PAUSED: (data: Message | Interaction) => {
|
||||
ALREADY_PAUSED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeInfoEmbed({
|
||||
title: `Already paused`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_pause.already_paused'),
|
||||
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()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -58,27 +62,28 @@ export default class Pause extends DiscordModule{
|
||||
const member = data.getMember();
|
||||
|
||||
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)] });
|
||||
|
||||
if(instance.isPaused())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ALREADY_PAUSED(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ALREADY_PAUSED(data, locale)] });
|
||||
|
||||
instance.pausePlayer();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PAUSED(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PAUSED(data, locale)] });
|
||||
}
|
||||
}
|
||||
+170
-115
@@ -1,92 +1,98 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import {
|
||||
Message,
|
||||
CommandInteraction,
|
||||
Interaction,
|
||||
VoiceChannel,
|
||||
MessageActionRow,
|
||||
MessageButton,
|
||||
SelectMenuInteraction,
|
||||
ButtonInteraction
|
||||
} from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import { Message, CommandInteraction, Interaction, VoiceChannel, MessageActionRow, MessageButton, SelectMenuInteraction, ButtonInteraction } from "discord.js";
|
||||
import { makeErrorEmbed, makeSuccessEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||
import DiscordProvider from "../../providers/Discord";
|
||||
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import { joinVoiceChannelProcedure } from "./Join";
|
||||
import { joinVoiceChannelProcedure } from './Join';
|
||||
|
||||
import DiscordProvider from '../../providers/Discord';
|
||||
import DiscordMusicPlayer, { ValidTracks } from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeErrorEmbed,
|
||||
makeSuccessEmbed,
|
||||
sendHybridInteractionMessageResponse,
|
||||
makeInfoEmbed
|
||||
} from '../../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
PLAY_INFO: (data: Message | Interaction) => {
|
||||
PLAY_INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Play',
|
||||
description: `Play a song`,
|
||||
title: locale.__('musicplayer_play.title'),
|
||||
description: locale.__('musicplayer_play.info'),
|
||||
fields: [
|
||||
{
|
||||
name: 'Arguments',
|
||||
value: '``Search query or Link``'
|
||||
name: locale.__('common.available_args'),
|
||||
value: locale.__('musicplayer_play.valid_args'),
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
YOUTUBE_ONLY: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: `Only youtube.com link is supported for now`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
});
|
||||
},
|
||||
INVALID_LINK: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: `Invalid Link`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
});
|
||||
},
|
||||
ADDED_QUEUE: (data: Message | Interaction, track: ValidTracks) => {
|
||||
ADDED_QUEUE: (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
let embed = makeSuccessEmbed({
|
||||
title: `Song added to queue!`,
|
||||
description: `${track.title}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_play.queue_added_song'),
|
||||
description: track.title,
|
||||
user: data.getUser()
|
||||
});
|
||||
|
||||
const highestResolutionThumbnail = track.thumbnails.reduce((prev, current) => (prev.height * prev.width > current.height * current.width) ? prev : current)
|
||||
const highestResolutionThumbnail = track.thumbnails.reduce((prev, current) =>
|
||||
prev.height * prev.width > current.height * current.width ? prev : current
|
||||
);
|
||||
|
||||
if (highestResolutionThumbnail) embed.setImage(highestResolutionThumbnail.url);
|
||||
|
||||
if(highestResolutionThumbnail)
|
||||
embed.setImage(highestResolutionThumbnail.url);
|
||||
|
||||
return embed;
|
||||
},
|
||||
ADDED_SONGS_QUEUE: (data: Message | Interaction, track: ValidTracks[]) => {
|
||||
ADDED_SONGS_QUEUE: (data: HybridInteractionMessage, locale: I18n, track: ValidTracks[]) => {
|
||||
let embed = makeSuccessEmbed({
|
||||
title: `Songs added to queue!`,
|
||||
description: `Added ${track.length} songs to queue`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_play.queue_added_songs'),
|
||||
description: locale.__('musicplayer_play.queue_added_songs_description', track.length.toString()),
|
||||
user: data.getUser()
|
||||
});
|
||||
return embed;
|
||||
},
|
||||
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()
|
||||
});
|
||||
},
|
||||
LOOKUP_ERROR: (data: Message | Interaction, error: Error) => {
|
||||
LOOKUP_ERROR: (data: HybridInteractionMessage, locale: I18n, error: Error) => {
|
||||
let errorMessage = '';
|
||||
|
||||
let errorMessage = "";
|
||||
|
||||
if(error.message === "While getting info from url\nPrivate video")
|
||||
errorMessage = "This is a private video";
|
||||
if (error.message === 'While getting info from url\nPrivate video') errorMessage = 'This is a private video';
|
||||
else
|
||||
errorMessage = error.message.replace("While getting info from url\n", "").replace("While getting info from url", "");
|
||||
errorMessage = error.message
|
||||
.replace('While getting info from url\n', '')
|
||||
.replace('While getting info from url', '');
|
||||
|
||||
return makeErrorEmbed({
|
||||
title: `Error while looking up the song`,
|
||||
description: `${errorMessage}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_play.error'),
|
||||
description: errorMessage,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
export default class Play extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_Play";
|
||||
public commands = ["play", "p"];
|
||||
public commandInteractionName = "play";
|
||||
public id = 'Discord_MusicPlayer_Play';
|
||||
public commands = ['play', 'p'];
|
||||
public commandInteractionName = 'play';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -105,6 +111,8 @@ export default class Play extends DiscordModule {
|
||||
if (!guild || !member || !user) return;
|
||||
if (!this.isJSONValid(interaction.customId)) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
let payload = JSON.parse(interaction.customId);
|
||||
|
||||
if (typeof payload.m === 'undefined' || typeof payload.a === 'undefined') return;
|
||||
@@ -118,7 +126,6 @@ export default class Play extends DiscordModule {
|
||||
*/
|
||||
|
||||
if (payload.m === 'MP_P' && payload.a === 'arp') {
|
||||
|
||||
if (typeof payload.d === 'undefined') return;
|
||||
|
||||
let data = payload.d.split('$');
|
||||
@@ -128,7 +135,7 @@ export default class Play extends DiscordModule {
|
||||
c: data[0],
|
||||
v: data[1],
|
||||
l: data[2]
|
||||
}
|
||||
};
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
@@ -137,17 +144,24 @@ export default class Play extends DiscordModule {
|
||||
|
||||
if (!voiceChannel || !(voiceChannel instanceof VoiceChannel)) return;
|
||||
|
||||
|
||||
if (!member.voice.channel)
|
||||
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(hybridData.getRaw())] }, true);
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
hybridData,
|
||||
{ embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(hybridData, locale)] },
|
||||
true
|
||||
);
|
||||
|
||||
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id))
|
||||
await joinVoiceChannelProcedure(new HybridInteractionMessage(interaction) , null, voiceChannel);
|
||||
await joinVoiceChannelProcedure(new HybridInteractionMessage(interaction), null, voiceChannel);
|
||||
|
||||
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
|
||||
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
||||
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(hybridData.getRaw())] }, true);
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
hybridData,
|
||||
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(hybridData, locale)] },
|
||||
true
|
||||
);
|
||||
|
||||
if (!instance!.isConnected()) {
|
||||
await joinVoiceChannelProcedure(new HybridInteractionMessage(interaction), instance!, voiceChannel);
|
||||
@@ -156,7 +170,9 @@ export default class Play extends DiscordModule {
|
||||
|
||||
if (!instance) return;
|
||||
|
||||
let playlist = await DiscordMusicPlayer.getYouTubeSongsInPlayList(`https://www.youtube.com/watch?v=${payload.d.v}&list=${payload.d.l}`);
|
||||
let playlist = await DiscordMusicPlayer.getYouTubeSongsInPlayList(
|
||||
`https://www.youtube.com/watch?v=${payload.d.v}&list=${payload.d.l}`
|
||||
);
|
||||
const songs = (await playlist.all_videos()).filter((song) => {
|
||||
return payload.d.v !== song.id;
|
||||
});
|
||||
@@ -165,15 +181,18 @@ export default class Play extends DiscordModule {
|
||||
instance.addTrackToQueue(song);
|
||||
}
|
||||
|
||||
if(hybridData.getSelectMenu().message instanceof Message)
|
||||
if (hybridData.getSelectMenu().message instanceof Message)
|
||||
await (hybridData.getSelectMenu().message as Message).edit({ components: [] });
|
||||
|
||||
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.ADDED_SONGS_QUEUE(hybridData.getRaw(), songs)] }, true);
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
hybridData,
|
||||
{ embeds: [EMBEDS.ADDED_SONGS_QUEUE(hybridData, locale, songs)] },
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async GuildSelectMenuInteractionCreate(interaction: SelectMenuInteraction) {
|
||||
|
||||
const hybridData = new HybridInteractionMessage(interaction);
|
||||
const guild = hybridData.getGuild();
|
||||
const member = hybridData.getMember();
|
||||
@@ -182,6 +201,7 @@ export default class Play extends DiscordModule {
|
||||
if (!guild || !member || !user) return;
|
||||
if (!this.isJSONValid(interaction.customId)) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
let payload = JSON.parse(interaction.customId);
|
||||
|
||||
/*
|
||||
@@ -194,7 +214,6 @@ export default class Play extends DiscordModule {
|
||||
if (typeof payload.m === 'undefined' || typeof payload.a === 'undefined') return;
|
||||
|
||||
if (payload.m === 'MP_SM' && payload.a === 'play') {
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
const voiceChannel = DiscordProvider.client.guilds.cache.get(guild.id)?.channels.cache.get(payload.d.v);
|
||||
@@ -203,16 +222,23 @@ export default class Play extends DiscordModule {
|
||||
if (!voiceChannel || !(voiceChannel instanceof VoiceChannel)) return;
|
||||
|
||||
if (!member.voice.channel)
|
||||
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(interaction)] }, true);
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
hybridData,
|
||||
{ embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(new HybridInteractionMessage(interaction), locale)] },
|
||||
true
|
||||
);
|
||||
|
||||
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id))
|
||||
await joinVoiceChannelProcedure(new HybridInteractionMessage(interaction), null, voiceChannel);
|
||||
|
||||
|
||||
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
|
||||
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
||||
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(interaction)] }, true);
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
hybridData,
|
||||
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(new HybridInteractionMessage(interaction), locale)] },
|
||||
true
|
||||
);
|
||||
|
||||
if (!instance!.isConnected()) {
|
||||
await joinVoiceChannelProcedure(new HybridInteractionMessage(interaction), instance!, voiceChannel);
|
||||
@@ -221,39 +247,52 @@ export default class Play extends DiscordModule {
|
||||
|
||||
if (!instance) return;
|
||||
|
||||
let result = await DiscordMusicPlayer.searchYouTubeByYouTubeLink(DiscordMusicPlayer.parseYouTubeLink(interaction.values[0])).catch((err) => {
|
||||
sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.LOOKUP_ERROR(hybridData.getRaw(), err)] }, true);
|
||||
let result = await DiscordMusicPlayer.searchYouTubeByYouTubeLink(
|
||||
DiscordMusicPlayer.parseYouTubeLink(interaction.values[0])
|
||||
).catch((err) => {
|
||||
sendHybridInteractionMessageResponse(
|
||||
hybridData,
|
||||
{ embeds: [EMBEDS.LOOKUP_ERROR(hybridData, locale, err)] },
|
||||
true
|
||||
);
|
||||
return null;
|
||||
});
|
||||
if (!result) return;
|
||||
|
||||
instance.addTrackToQueue(result);
|
||||
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.ADDED_QUEUE(interaction, result)] }, true);
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
hybridData,
|
||||
{ embeds: [EMBEDS.ADDED_QUEUE(new HybridInteractionMessage(interaction), locale, result)] },
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
let query;
|
||||
const guild = data.getGuild();
|
||||
const channel = data.getChannel();
|
||||
const member = data.getMember();
|
||||
|
||||
if (!guild || !channel || !member) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PLAY_INFO(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PLAY_INFO(data, locale)] });
|
||||
|
||||
query = args.join(' ');
|
||||
}
|
||||
else if (data.isSlashCommand()) {
|
||||
} else if (data.isSlashCommand()) {
|
||||
query = args.getSubcommand();
|
||||
}
|
||||
|
||||
if (!query || !guild || !channel || !member) return;
|
||||
if (!query) return;
|
||||
|
||||
if (!member.voice.channel)
|
||||
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 voiceChannel = member.voice.channel;
|
||||
|
||||
@@ -264,7 +303,11 @@ export default class Play extends DiscordModule {
|
||||
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
|
||||
if (instance!.voiceChannel.id !== member.voice.channel.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!.isConnected()) {
|
||||
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
|
||||
@@ -276,18 +319,22 @@ export default class Play extends DiscordModule {
|
||||
if (DiscordMusicPlayer.isYouTubeLink(query)) {
|
||||
let linkData = DiscordMusicPlayer.parseYouTubeLink(query);
|
||||
|
||||
if (linkData.videoId === "" && linkData.list) {
|
||||
if (linkData.videoId === '' && linkData.list) {
|
||||
let playlist = await DiscordMusicPlayer.getYouTubeSongsInPlayList(query);
|
||||
const songs = await playlist.all_videos();
|
||||
|
||||
for (let song of songs) {
|
||||
instance.addTrackToQueue(song);
|
||||
}
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_SONGS_QUEUE(data.getRaw(), songs)] }, true);
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.ADDED_SONGS_QUEUE(data, locale, songs)] },
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
let result = await DiscordMusicPlayer.searchYouTubeByYouTubeLink(linkData).catch((err) => {
|
||||
sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOKUP_ERROR(data.getRaw(), err)] }, true);
|
||||
sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOKUP_ERROR(data, locale, err)] }, true);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -300,23 +347,28 @@ export default class Play extends DiscordModule {
|
||||
instance.addTrackToQueue(result);
|
||||
|
||||
if (linkData.list) {
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('✅')
|
||||
.setCustomId(JSON.stringify({
|
||||
const row = new MessageActionRow().addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('✅')
|
||||
.setCustomId(
|
||||
JSON.stringify({
|
||||
m: 'MP_P',
|
||||
a: 'arp', // Add remaining playlist
|
||||
d: `${voiceChannel.id}$${linkData.videoId}$${linkData.list}`
|
||||
}))
|
||||
.setLabel(' Add the remaining songs in the playlist')
|
||||
.setStyle('PRIMARY')
|
||||
)
|
||||
})
|
||||
)
|
||||
.setLabel(' Add the remaining songs in the playlist')
|
||||
.setStyle('PRIMARY')
|
||||
);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data.getRaw(), result)], components: [row] });
|
||||
}
|
||||
else
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data.getRaw(), result)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ADDED_QUEUE(data, locale, result)],
|
||||
components: [row]
|
||||
});
|
||||
} else
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ADDED_QUEUE(data, locale, result)]
|
||||
});
|
||||
} else {
|
||||
let result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
||||
|
||||
@@ -324,7 +376,6 @@ export default class Play extends DiscordModule {
|
||||
instance.addTrackToQueue(result[0]);
|
||||
|
||||
if (result.length > 1) {
|
||||
|
||||
// TODO: Find a better logic than this
|
||||
// If the first result title is exact match with the query or first title contains half the space of the query, it's probably a sentence
|
||||
// then we don't need to show the search results
|
||||
@@ -333,37 +384,41 @@ export default class Play extends DiscordModule {
|
||||
// The query length is too long to fit in json
|
||||
if (query.length > 100 - 51) return;
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('🔎')
|
||||
.setCustomId(JSON.stringify({
|
||||
const row = new MessageActionRow().addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('🔎')
|
||||
.setCustomId(
|
||||
JSON.stringify({
|
||||
m: 'MP_S',
|
||||
a: 'search',
|
||||
d: {
|
||||
q: query
|
||||
}
|
||||
}))
|
||||
.setLabel(' Not this? Search!')
|
||||
.setStyle('PRIMARY')
|
||||
)
|
||||
})
|
||||
)
|
||||
.setLabel(' Not this? Search!')
|
||||
.setStyle('PRIMARY')
|
||||
);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data.getRaw(), result[0])], components: [row] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ADDED_QUEUE(data, locale, result[0])],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ADDED_QUEUE(data.getRaw(), result[0])] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ADDED_QUEUE(data, locale, result[0])]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isJSONValid(jsonString: string) {
|
||||
try {
|
||||
let o = JSON.parse(jsonString);
|
||||
if (o && typeof o === "object") {
|
||||
if (o && typeof o === 'object') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
} catch (e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,83 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { Message, CommandInteraction, Interaction, TextChannel } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import { Message, CommandInteraction, Interaction, TextChannel } from "discord.js";
|
||||
import { makeErrorEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||
import DiscordMusicPlayer, {
|
||||
DiscordMusicPlayerInstance,
|
||||
DiscordMusicPlayerLoopMode
|
||||
} from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import DiscordMusicPlayer, { DiscordMusicPlayerInstance, DiscordMusicPlayerLoopMode } from "../../providers/DiscordMusicPlayer";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import { makeErrorEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from '../../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
QUEUE: (data: Message | Interaction, instance: DiscordMusicPlayerInstance) => {
|
||||
|
||||
QUEUE: (data: HybridInteractionMessage, locale: I18n, instance: DiscordMusicPlayerInstance) => {
|
||||
const queue = instance.queue;
|
||||
|
||||
if(!queue.track[0])
|
||||
if (!queue.track[0])
|
||||
return makeInfoEmbed({
|
||||
title: `Queue`,
|
||||
description: `The queue is empty!`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_queue.title'),
|
||||
description: locale.__('musicplayer_queue.empty'),
|
||||
user: data.getUser()
|
||||
});
|
||||
else {
|
||||
if(queue.track.length == 1) {
|
||||
let queueString = `1. [${queue.track[0].title}](${queue.track[0].url})`
|
||||
const nowPlayingText = `${
|
||||
instance.getLoopMode() === DiscordMusicPlayerLoopMode.Current
|
||||
? ` ${locale.__('musicplayer_queue.looping_current')}`
|
||||
: ''
|
||||
}: [${queue.track[0].title}](${queue.track[0].url})`;
|
||||
|
||||
if (queue.track.length == 1) {
|
||||
let queueString = `1. [${queue.track[0].title}](${queue.track[0].url})`;
|
||||
return makeInfoEmbed({
|
||||
title: `Queue`,
|
||||
description: `Now playing${instance.getLoopMode() === DiscordMusicPlayerLoopMode.Current ? " (Looping current)" : ""}: [${queue.track[0].title}](${queue.track[0].url})\n\nThere are ${queue.track.length} song in the queue!\n${queueString}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_queue.title'),
|
||||
description: `${locale.__('musicplayer_queue.now_playing')}${nowPlayingText}\n
|
||||
There are ${queue.track.length} song in the queue!\n${queueString}`,
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
else if(queue.track.length >= 10) {
|
||||
let first10 = queue.track.slice(0, 10);
|
||||
let queueString = first10.map((track, index) => `${index + 1}. [${track.title}](${track.url})`).join("\n");
|
||||
} else if (queue.track.length >= 10) {
|
||||
const upcomingText = `[${queue.track[1].title}](${queue.track[1].url})`;
|
||||
const first10 = queue.track.slice(0, 10);
|
||||
let queueString = first10
|
||||
.map((track, index) => `${index + 1}. [${track.title}](${track.url})`)
|
||||
.join('\n');
|
||||
return makeInfoEmbed({
|
||||
title: `Queue`,
|
||||
description: `Now playing${instance.getLoopMode() === DiscordMusicPlayerLoopMode.Current ? " (Looping current)" : ""}: [${queue.track[0].title}](${queue.track[0].url})\nUpcoming song: [${queue.track[1].title}](${queue.track[1].url})\n\nThere are ${queue.track.length} songs in the queue!\n${queueString}\n${queue.track.length > 10 ? `...${queue.track.length - 10} more songs` : ""}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_queue.title'),
|
||||
description: `${locale.__('musicplayer_queue.now_playing')}${nowPlayingText}
|
||||
${locale.__('musicplayer_queue.upcoming_song')} ${upcomingText}\n
|
||||
${locale.__('musicplayer_queue.song_x_in_queue', queue.track.length.toString())}
|
||||
${queueString}\n${queue.track.length > 10 ? `...${queue.track.length - 10} more songs` : ''}`,
|
||||
user: data.getUser()
|
||||
});
|
||||
} else {
|
||||
let queueString = queue.track.map((track, index) => `${index + 1}. [${track.title}](${track.url})`).join("\n");
|
||||
const upcomingText = `[${queue.track[1].title}](${queue.track[1].url})`;
|
||||
const queueString = queue.track
|
||||
.map((track, index) => `${index + 1}. [${track.title}](${track.url})`)
|
||||
.join('\n');
|
||||
return makeInfoEmbed({
|
||||
title: `Queue`,
|
||||
description: `Now playing${instance.getLoopMode() === DiscordMusicPlayerLoopMode.Current ? " (Looping current)" : ""}: [${queue.track[0].title}](${queue.track[0].url})\nUpcoming song: [${queue.track[1].title}](${queue.track[1].url})\n\nThere are ${queue.track.length} songs in the queue!\n${queueString}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_queue.title'),
|
||||
description: `${locale.__('musicplayer_queue.now_playing')}${nowPlayingText}
|
||||
${locale.__('musicplayer_queue.upcoming_song')} ${upcomingText}\n
|
||||
${locale.__('musicplayer_queue.song_x_in_queue', queue.track.length.toString())}
|
||||
${queueString}`,
|
||||
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()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class QueueCommand extends DiscordModule {
|
||||
public id = 'Discord_MusicPlayer_Queue';
|
||||
public commands = ['queue', 'q'];
|
||||
public commandInteractionName = 'queue';
|
||||
|
||||
public id = "Discord_MusicPlayer_Queue";
|
||||
public commands = ["queue", "q"];
|
||||
public commandInteractionName = "queue";
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
@@ -66,16 +87,20 @@ export default class QueueCommand extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
|
||||
if(!guild) return;
|
||||
if (!guild) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if(!instance) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data.getRaw())] });
|
||||
if (!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.QUEUE(data.getRaw(), instance)] });
|
||||
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE(data, locale, instance)] });
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,42 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
|
||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import { I18n } from "i18n";
|
||||
|
||||
import DiscordProvider from "../../providers/Discord";
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import Locale from "../../services/Locale";
|
||||
|
||||
const EMBEDS = {
|
||||
RESUMED: (data: Message | Interaction) => {
|
||||
RESUMED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeSuccessEmbed({
|
||||
title: `Resumed`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_resume.resumed'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
NOT_PAUSED: (data: Message | Interaction) => {
|
||||
NOT_PAUSED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeInfoEmbed({
|
||||
title: `The music is not paused`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_resume.not_paused'),
|
||||
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,26 +62,28 @@ export default class Resume 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)] });
|
||||
|
||||
if(!instance.isPaused())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_PAUSED(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_PAUSED(data, locale)] });
|
||||
|
||||
instance.resumePlayer();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.RESUMED(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.RESUMED(data, locale)] });
|
||||
}
|
||||
}
|
||||
@@ -1,61 +1,45 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
|
||||
import { Message, CommandInteraction, Interaction, MessageActionRow, ButtonInteraction, MessageSelectMenu, MessageSelectOptionData } from "discord.js";
|
||||
import { makeErrorEmbed, makeSuccessEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import { I18n } from "i18n";
|
||||
|
||||
import { joinVoiceChannelProcedure } from "./Join";
|
||||
|
||||
import DiscordMusicPlayer, { ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeErrorEmbed, makeSuccessEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||
|
||||
const EMBEDS = {
|
||||
SEARCH_INFO: (data: Message | Interaction) => {
|
||||
SEARCH_INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Search',
|
||||
description: `Search for a song`,
|
||||
title: locale.__('musicplayer_search.title'),
|
||||
description: locale.__('musicplayer_search.info'),
|
||||
fields: [
|
||||
{
|
||||
name: 'Arguments',
|
||||
value: '``Search query``'
|
||||
name: locale.__('common.available_args'),
|
||||
value: locale.__('musicplayer_search.valid_args'),
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
SEARCH_RESULT: (data: Message | Interaction, result: ValidTracks[]) => {
|
||||
SEARCH_RESULT: (data: HybridInteractionMessage, locale: I18n, result: ValidTracks[]) => {
|
||||
return makeInfoEmbed({
|
||||
title: `Search result`,
|
||||
description: `${result.length} results found\n\n${result.map(track => `- [${track.title}](${track.url})`).join('\n')}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer_search.title_result'),
|
||||
description: `${locale.__('musicplayer_search.x_results_found', result.length.toString())}\n\n${result.map(track => `- [${track.title}](${track.url})`).join('\n')}`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
INVALID_LINK: (data: Message | Interaction) => {
|
||||
USER_NOT_IN_VOICECHANNEL: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: `Invalid Link`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
title: locale.__('musicplayer.not_in_voice'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
ADDED_QUEUE: (data: Message | Interaction, track: ValidTracks) => {
|
||||
let embed = makeSuccessEmbed({
|
||||
title: `Song added to queue!`,
|
||||
description: `${track.title}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
});
|
||||
|
||||
const highestResolutionThumbnail = track.thumbnails.reduce((prev, current) => (prev.height * prev.width > current.height * current.width) ? prev : current)
|
||||
|
||||
if(highestResolutionThumbnail)
|
||||
embed.setImage(highestResolutionThumbnail.url);
|
||||
|
||||
return embed;
|
||||
},
|
||||
USER_NOT_IN_VOICECHANNEL: (data: Message | Interaction) => {
|
||||
USER_NOT_IN_SAME_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
|
||||
});
|
||||
},
|
||||
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
|
||||
title: locale.__('musicplayer.different_voice_channel'),
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -100,12 +84,13 @@ export default class Search extends DiscordModule {
|
||||
const channel = data.getChannel();
|
||||
|
||||
if (!guild || !user || !member || !channel) return;
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_INFO(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_INFO(data, locale)] });
|
||||
|
||||
query = args.join(' ');
|
||||
}
|
||||
@@ -119,7 +104,7 @@ export default class Search extends DiscordModule {
|
||||
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)] });
|
||||
|
||||
|
||||
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id))
|
||||
@@ -129,7 +114,7 @@ export default class Search extends DiscordModule {
|
||||
if (!instance) return;
|
||||
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] });
|
||||
|
||||
if (!instance.isConnected()) {
|
||||
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
|
||||
@@ -173,7 +158,7 @@ export default class Search extends DiscordModule {
|
||||
const row = new MessageActionRow();
|
||||
row.addComponents(messageSelectMenu);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_RESULT(data.getRaw(), result)], components: [row] });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_RESULT(data, locale, result)], components: [row] });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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)] });
|
||||
}
|
||||
}
|
||||
+33
-22
@@ -1,4 +1,5 @@
|
||||
import { Message, Permissions, Interaction, CommandInteraction } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
@@ -7,38 +8,43 @@ import {
|
||||
makeErrorEmbed,
|
||||
makeInfoEmbed
|
||||
} from '../utils/DiscordMessage';
|
||||
import Locale from '../services/Locale';
|
||||
|
||||
const EMBEDS = {
|
||||
SAY_INFO: (data: Message | Interaction) => {
|
||||
SAY_INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Say',
|
||||
description: `Make me say something!`,
|
||||
title: locale.__('say.title'),
|
||||
description: locale.__('say.info'),
|
||||
fields: [
|
||||
{
|
||||
name: 'Available arguments',
|
||||
value: '``Your message``'
|
||||
name: locale.__('common.available_args'),
|
||||
value: locale.__('say.valid_args')
|
||||
}
|
||||
],
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
NO_PERMISSION: (data: Message | Interaction) => {
|
||||
NO_PERMISSION: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'You need ``VIEW_CHANNEL, SEND_MESSAGES and MANAGE_CHANNELS`` permission on this guild!',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
title: locale.__('common.no_permissions'),
|
||||
description: locale.__(
|
||||
'common.no_permissions_description',
|
||||
'VIEW_CHANNEL, SEND_MESSAGES and MANAGE_CHANNELS'
|
||||
),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
SAY_ERROR: (data: Message | Interaction, error: any) => {
|
||||
SAY_ERROR: (data: HybridInteractionMessage, locale: I18n, error: Error) => {
|
||||
return makeErrorEmbed({
|
||||
title: `Unable to say`,
|
||||
description: error.message,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
title: locale.__('say.error'),
|
||||
description: error.message ? error.message : undefined,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
SUCCESSFULLY_SAID: (data: Message | Interaction) => {
|
||||
SUCCESSFULLY_SAID: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Successfully said',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
title: locale.__('say.success'),
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -57,6 +63,11 @@ export default class Say extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
const guild = data.getGuild();
|
||||
if (!guild) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
@@ -72,12 +83,12 @@ export default class Say extends DiscordModule {
|
||||
])
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PERMISSION(data.getRaw())]
|
||||
embeds: [EMBEDS.NO_PERMISSION(data, locale)]
|
||||
});
|
||||
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SAY_INFO(data.getRaw())]
|
||||
embeds: [EMBEDS.SAY_INFO(data, locale)]
|
||||
});
|
||||
|
||||
query = args.join(' ');
|
||||
@@ -90,7 +101,7 @@ export default class Say extends DiscordModule {
|
||||
?.permissions.has([Permissions.FLAGS.ADMINISTRATOR])
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PERMISSION(data.getRaw())]
|
||||
embeds: [EMBEDS.NO_PERMISSION(data, locale)]
|
||||
});
|
||||
|
||||
query = interaction.options.getString('message');
|
||||
@@ -101,10 +112,10 @@ export default class Say extends DiscordModule {
|
||||
await data.getChannel()!.send({ content: query });
|
||||
await data
|
||||
.getMessageComponentInteraction()
|
||||
.reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data.getRaw())] });
|
||||
.reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data, locale)] });
|
||||
} catch (err: any) {
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SAY_ERROR(data.getRaw(), err)]
|
||||
embeds: [EMBEDS.SAY_ERROR(data, locale, err)]
|
||||
});
|
||||
}
|
||||
} else if (data.isMessage()) {
|
||||
@@ -115,7 +126,7 @@ export default class Say extends DiscordModule {
|
||||
await data.getChannel()!.send({ content: query });
|
||||
} catch (err: any) {
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SAY_ERROR(data.getRaw(), err)]
|
||||
embeds: [EMBEDS.SAY_ERROR(data, locale, err)]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ import DiscordProvider from '../providers/Discord';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from '../utils/DiscordMessage';
|
||||
import Locale from '../providers/Locale';
|
||||
import Cache from '../providers/Cache';
|
||||
import Locale from '../services/Locale';
|
||||
|
||||
const EMBEDS = {
|
||||
STATS_INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -19,7 +18,7 @@ const EMBEDS = {
|
||||
return makeInfoEmbed({
|
||||
title: locale.__('stats.title'),
|
||||
icon: '📊',
|
||||
description: locale.__('stats.description'),
|
||||
description: locale.__('stats.info'),
|
||||
fields: [
|
||||
{
|
||||
name: `🌐 ${locale.__('stats.users')}`,
|
||||
@@ -60,13 +59,10 @@ export default class Stats extends DiscordModule {
|
||||
const guild = data.getGuild();
|
||||
if (!guild) return;
|
||||
|
||||
const cachedGuild = await Cache.getCachedGuild(guild.id);
|
||||
if (!cachedGuild) return;
|
||||
|
||||
const LocaleProvider = Locale.getLocaleProvider(cachedGuild.locale);
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.STATS_INFO(data, LocaleProvider)]
|
||||
embeds: [EMBEDS.STATS_INFO(data, locale)]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+152
-124
@@ -1,32 +1,144 @@
|
||||
import { Message, Interaction, CommandInteraction } from 'discord.js';
|
||||
import { getColorFromURL } from 'color-thief-node';
|
||||
import { Message, CommandInteraction, Presence, PresenceStatus } from 'discord.js';
|
||||
import { getColorFromURL, Palette } from 'color-thief-node';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
sendHybridInteractionMessageResponse,
|
||||
makeErrorEmbed,
|
||||
makeInfoEmbed
|
||||
} from '../utils/DiscordMessage';
|
||||
import { sendHybridInteractionMessageResponse, makeErrorEmbed, makeInfoEmbed } from '../utils/DiscordMessage';
|
||||
import Locale from '../services/Locale';
|
||||
|
||||
interface UserInfoData {
|
||||
displayName: string;
|
||||
tag: string;
|
||||
status: PresenceStatus | null;
|
||||
joinedAt: Date | null;
|
||||
displayAvatarURL: string;
|
||||
isGuildOwner: boolean;
|
||||
presence: Presence | null;
|
||||
colorThiefColor: Palette | null;
|
||||
}
|
||||
|
||||
const EMBEDS = {
|
||||
SAY_INFO: (data: Message | Interaction) => {
|
||||
INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'User Info',
|
||||
description: `View info on discord user`,
|
||||
title: locale.__('userinfo.title'),
|
||||
description: locale.__('userinfo.info'),
|
||||
fields: [
|
||||
{
|
||||
name: 'Available arguments',
|
||||
value: '``Discord user mention or id``'
|
||||
name: locale.__('common.available_args'),
|
||||
value: locale.__('userinfo.valid_args')
|
||||
}
|
||||
],
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
USER_NOT_FOUND: (data: Message | Interaction) => {
|
||||
USER_NOT_FOUND: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'That user cannot be found!',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
title: locale.__('userinfo.user_not_found'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
USER_INFO: (data: HybridInteractionMessage, locale: I18n, user: UserInfoData) => {
|
||||
let readableStatus: string;
|
||||
|
||||
switch (user.status) {
|
||||
case 'online':
|
||||
readableStatus = `🟢 ${locale.__('userinfo.online')}`;
|
||||
break;
|
||||
case 'idle':
|
||||
readableStatus = `🌙 ${locale.__('userinfo.idle')}`;
|
||||
break;
|
||||
case 'dnd':
|
||||
readableStatus = `⛔ ${locale.__('userinfo.dnd')}`;
|
||||
break;
|
||||
case 'offline':
|
||||
readableStatus = `⚫ ${locale.__('userinfo.offline')}`;
|
||||
break;
|
||||
default:
|
||||
readableStatus = `⚫ ${locale.__('userinfo.unknown')}`;
|
||||
break;
|
||||
}
|
||||
|
||||
let embed = makeInfoEmbed({
|
||||
icon: null,
|
||||
title: user.tag,
|
||||
fields: [
|
||||
{
|
||||
name: `${readableStatus}`,
|
||||
value: `\u200b`
|
||||
}
|
||||
],
|
||||
color: user.colorThiefColor || undefined,
|
||||
user: data.getUser()
|
||||
});
|
||||
|
||||
if (user.presence?.activities) {
|
||||
for (let activity of user.presence?.activities) {
|
||||
if (activity.type === 'CUSTOM')
|
||||
embed.addField(
|
||||
`✨ ${locale.__('userinfo.custom_status')}`,
|
||||
`${
|
||||
!activity.emoji
|
||||
? ''
|
||||
: `${
|
||||
activity.emoji?.identifier.startsWith('<') &&
|
||||
activity.emoji?.identifier.endsWith('>') &&
|
||||
activity.emoji?.identifier.split(':').length == 2
|
||||
? activity.emoji?.identifier.split(':')[0]
|
||||
: activity.emoji?.name
|
||||
}`
|
||||
} ${activity.state === null ? '' : activity.state}
|
||||
\u200b`,
|
||||
false
|
||||
);
|
||||
else {
|
||||
let title = '';
|
||||
switch (activity.type) {
|
||||
case 'PLAYING':
|
||||
title = `'🕹 ${locale.__('userinfo.playing_x', activity.name)}`;
|
||||
break;
|
||||
case 'STREAMING':
|
||||
title = `'🔴 ${locale.__('userinfo.streaming_x', activity.name)}`;
|
||||
break;
|
||||
case 'LISTENING':
|
||||
title = `🎵 ${locale.__('userinfo.listening_x', activity.name)}`;
|
||||
break;
|
||||
case 'WATCHING':
|
||||
title = `📺 ${locale.__('userinfo.watching_x', activity.name)}`;
|
||||
break;
|
||||
case 'COMPETING':
|
||||
title = `'🌠 ${locale.__('userinfo.competing_x', activity.name)}`;
|
||||
break;
|
||||
}
|
||||
embed.addField(
|
||||
`${title}`,
|
||||
`${activity.details === null ? '' : activity.details}
|
||||
${activity.state === null ? '' : activity.state}
|
||||
Since <t:${Math.round(new Date(activity.createdAt).getTime() / 1000)}:R>
|
||||
\u200b`,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
embed.addField(
|
||||
`📰 ${locale.__('userinfo.user_guild_info')}`,
|
||||
`${
|
||||
user.joinedAt === null
|
||||
? locale.__('userinfo.join_date_unknown')
|
||||
: locale.__('userinfo.join_date', `<t:${Math.round(user.joinedAt.getTime() / 1000)}:R>`)
|
||||
}
|
||||
${user.isGuildOwner ? `${locale.__('userinfo.guild_owner')}` : ''}
|
||||
`
|
||||
);
|
||||
|
||||
embed.setThumbnail(user.displayAvatarURL + '?size=4096');
|
||||
embed.setAuthor({
|
||||
name: user.displayName,
|
||||
iconURL: user.displayAvatarURL + '?size=4096'
|
||||
});
|
||||
|
||||
return embed;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,135 +156,51 @@ export default class UserInfo extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
const guild = data.getGuild();
|
||||
if (!guild) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SAY_INFO(data.getRaw())]
|
||||
embeds: [EMBEDS.INFO(data, locale)]
|
||||
});
|
||||
|
||||
if (typeof data.getMessage().mentions.users.first() !== 'undefined')
|
||||
query = data.getMessage().mentions.users.first()?.id;
|
||||
else query = args[0];
|
||||
} else if (data.isSlashCommand())
|
||||
query = data.getSlashCommand().options.getUser('user')?.id;
|
||||
} else if (data.isSlashCommand()) query = data.getSlashCommand().options.getUser('user')?.id;
|
||||
|
||||
// Find the user want to look up
|
||||
let TargetMember = (await data.getGuild()!.members.fetch()).get(query);
|
||||
let TargetMember = (await guild.members.fetch()).get(query);
|
||||
if (!TargetMember)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_FOUND(data.getRaw())]
|
||||
embeds: [EMBEDS.USER_NOT_FOUND(data, locale)]
|
||||
});
|
||||
|
||||
if (data.isSlashCommand()) await data.getMessageComponentInteraction().deferReply();
|
||||
|
||||
let readableStatus: string;
|
||||
|
||||
switch (TargetMember.presence?.status) {
|
||||
case 'online':
|
||||
readableStatus = '🟢 Online';
|
||||
break;
|
||||
case 'idle':
|
||||
readableStatus = '🌙 Idle';
|
||||
break;
|
||||
case 'dnd':
|
||||
readableStatus = '⛔ Do not disturb';
|
||||
break;
|
||||
case 'offline':
|
||||
readableStatus = '⚫ Offline';
|
||||
break;
|
||||
default:
|
||||
readableStatus = '❓ Unknown';
|
||||
break;
|
||||
}
|
||||
|
||||
const embed = makeInfoEmbed({
|
||||
icon: '',
|
||||
title: `${TargetMember.user.tag}`,
|
||||
fields: [
|
||||
{
|
||||
name: `${readableStatus}`,
|
||||
value: `\u200b`
|
||||
}
|
||||
],
|
||||
user: data.getUser()
|
||||
});
|
||||
|
||||
if (TargetMember.presence?.activities)
|
||||
for (let activity of TargetMember.presence?.activities) {
|
||||
if (activity.type === 'CUSTOM')
|
||||
embed.addField(
|
||||
`✨ ${activity.name}`,
|
||||
`${
|
||||
!activity.emoji
|
||||
? ''
|
||||
: `${
|
||||
activity.emoji?.identifier.startsWith('%')
|
||||
? activity.emoji?.name
|
||||
: '<' + activity.emoji?.identifier + '>'
|
||||
}`
|
||||
} ${activity.state === null ? '' : activity.state}
|
||||
\u200b`,
|
||||
true
|
||||
);
|
||||
else {
|
||||
let emoji = '';
|
||||
switch (activity.type) {
|
||||
case 'PLAYING':
|
||||
emoji = '🕹 ';
|
||||
break;
|
||||
case 'STREAMING':
|
||||
emoji = '🔴 ';
|
||||
break;
|
||||
case 'LISTENING':
|
||||
emoji = '🎵 ';
|
||||
break;
|
||||
case 'WATCHING':
|
||||
emoji = '📺 ';
|
||||
break;
|
||||
case 'COMPETING':
|
||||
emoji = '🌠 ';
|
||||
break;
|
||||
}
|
||||
embed.addField(
|
||||
`${emoji}${
|
||||
activity.type.toLowerCase().charAt(0).toUpperCase() +
|
||||
activity.type.toLowerCase().slice(1)
|
||||
} ${activity.name}`,
|
||||
`${activity.details === null ? '' : activity.details}
|
||||
${activity.state === null ? '' : activity.state}
|
||||
Since <t:${Math.round(new Date(activity.createdAt).getTime() / 1000)}:R>
|
||||
\u200b`,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
embed.addField(
|
||||
`📰 Information on this guild`,
|
||||
`${
|
||||
TargetMember.joinedAt === null
|
||||
? 'Cannot determine joined date'
|
||||
: `Joined <t:${Math.round(TargetMember.joinedAt.getTime() / 1000)}:R>`
|
||||
}
|
||||
${TargetMember.id === data.getGuild()!.ownerId ? 'Owner of this guild 👑' : ''}
|
||||
`
|
||||
);
|
||||
|
||||
let colorthief = null;
|
||||
try {
|
||||
const colorthief = await getColorFromURL(
|
||||
TargetMember.user.displayAvatarURL().replace('.webp', '.jpg')
|
||||
);
|
||||
embed.setColor(colorthief);
|
||||
colorthief = await getColorFromURL(TargetMember.user.displayAvatarURL().replace('.webp', '.jpg'));
|
||||
} catch (err) {}
|
||||
|
||||
embed.setThumbnail(TargetMember.user.displayAvatarURL());
|
||||
embed.setAuthor({
|
||||
name: `${TargetMember.displayName}`,
|
||||
iconURL: TargetMember.user.displayAvatarURL()
|
||||
});
|
||||
const userInfoData: UserInfoData = {
|
||||
tag: TargetMember.user.tag,
|
||||
status: TargetMember.presence?.status ? TargetMember.presence?.status : null,
|
||||
displayName: TargetMember.displayName,
|
||||
joinedAt: TargetMember.joinedAt,
|
||||
displayAvatarURL: TargetMember.displayAvatarURL(),
|
||||
presence: TargetMember.presence || null,
|
||||
isGuildOwner: TargetMember.id === guild.ownerId,
|
||||
colorThiefColor: colorthief
|
||||
};
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [embed] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_INFO(data, locale, userInfoData)]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Snowflake } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import Cache from '../providers/Cache';
|
||||
import Locale from '../providers/Locale';
|
||||
|
||||
export async function getGuildLocale(id: Snowflake): Promise<I18n> {
|
||||
const cachedGuild = await Cache.getCachedGuild(id);
|
||||
if (!cachedGuild) return Locale.getLocaleProvider("en");
|
||||
|
||||
const LocaleProvider = Locale.getLocaleProvider(cachedGuild.locale);
|
||||
return LocaleProvider;
|
||||
}
|
||||
|
||||
export default {
|
||||
getGuildLocale
|
||||
}
|
||||
@@ -23,7 +23,7 @@ const emotes = {
|
||||
};
|
||||
|
||||
interface EmbedData {
|
||||
icon?: string;
|
||||
icon?: string | null;
|
||||
title: string;
|
||||
description?: any;
|
||||
color?: ColorResolvable;
|
||||
@@ -33,7 +33,7 @@ interface EmbedData {
|
||||
}
|
||||
|
||||
interface EmbedDataPresets {
|
||||
icon?: string;
|
||||
icon?: string | null;
|
||||
title: string;
|
||||
description?: any;
|
||||
color?: ColorResolvable;
|
||||
@@ -70,7 +70,7 @@ export function makeEmbed(data: EmbedData) {
|
||||
|
||||
export function makeInfoEmbed(data: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !data.icon ? '🔮' : data.icon,
|
||||
icon: !data.icon && data.icon !== null ? '🔮' : data.icon,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
color: '#C7CEEA',
|
||||
@@ -82,7 +82,7 @@ export function makeInfoEmbed(data: EmbedDataPresets) {
|
||||
|
||||
export function makeSuccessEmbed(data: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !data.icon ? '✅' : data.icon,
|
||||
icon: !data.icon && data.icon !== null ? '✅' : data.icon,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
color: '#B5EAD7',
|
||||
@@ -94,7 +94,7 @@ export function makeSuccessEmbed(data: EmbedDataPresets) {
|
||||
|
||||
export function makeWarningEmbed(data: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !data.icon ? '⚠️' : data.icon,
|
||||
icon: !data.icon && data.icon !== null ? '⚠️' : data.icon,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
color: '#FFEEAD',
|
||||
@@ -106,7 +106,7 @@ export function makeWarningEmbed(data: EmbedDataPresets) {
|
||||
|
||||
export function makeErrorEmbed(data: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !data.icon ? '❌' : data.icon,
|
||||
icon: !data.icon && data.icon !== null ? '❌' : data.icon,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
color: '#FF9AA2',
|
||||
@@ -118,7 +118,7 @@ export function makeErrorEmbed(data: EmbedDataPresets) {
|
||||
|
||||
export function makeProcessingEmbed(data: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !data.icon ? getEmotes().yumiloading : data.icon,
|
||||
icon: !data.icon && data.icon !== null ? getEmotes().yumiloading : data.icon,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
color: '#E2F0CB',
|
||||
|
||||
Reference in New Issue
Block a user