mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-14 19:29:22 +00:00
Formatted code
This commit is contained in:
@@ -80,7 +80,6 @@ const EMBEDS = {
|
||||
});
|
||||
},
|
||||
NOW_PLAYING: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -97,7 +96,6 @@ const EMBEDS = {
|
||||
return embed;
|
||||
},
|
||||
NOW_REPEATING: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -141,8 +139,17 @@ export async function joinVoiceChannelProcedure(
|
||||
if (!bot) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
if(!await checkBotPermissionsInChannel({ guild, data, locale, channel: memberVoiceChannel, permissions: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.Connect]})) return;
|
||||
|
||||
if (
|
||||
!(await checkBotPermissionsInChannel({
|
||||
guild,
|
||||
data,
|
||||
locale,
|
||||
channel: memberVoiceChannel,
|
||||
permissions: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.Connect]
|
||||
}))
|
||||
)
|
||||
return;
|
||||
|
||||
// If already in VoiceChannel
|
||||
if (bot.voice.channelId) {
|
||||
@@ -231,7 +238,7 @@ export async function joinVoiceChannelProcedure(
|
||||
else if (event.instance.queue.track[0] === previousTrack && isLoopMessageSent) return;
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
||||
if(event.instance.queue.track[0] instanceof SpotifyTrack)
|
||||
if (event.instance.queue.track[0] instanceof SpotifyTrack)
|
||||
row.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🟢')
|
||||
@@ -239,14 +246,21 @@ export async function joinVoiceChannelProcedure(
|
||||
.setURL(encodeURI(`https://open.spotify.com/track/${event.instance.queue.track[0].id}`))
|
||||
.setStyle(ButtonStyle.Link)
|
||||
]);
|
||||
if(event.instance.queue.track[0] instanceof YouTubeVideo || event.instance.queue.track[0] instanceof SpotifyTrack) {
|
||||
if (
|
||||
event.instance.queue.track[0] instanceof YouTubeVideo ||
|
||||
event.instance.queue.track[0] instanceof SpotifyTrack
|
||||
) {
|
||||
const actualPlaybackURL = event.instance.getActualPlaybackURL();
|
||||
if(event.instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
|
||||
if (event.instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
|
||||
row.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🔴')
|
||||
.setLabel(' Open in YouTube')
|
||||
.setURL(event.instance.queue.track[0] instanceof YouTubeVideo ? encodeURI(`https://www.youtube.com/watch?v=${event.instance.queue.track[0].id}`) : encodeURI(event.instance.getActualPlaybackURL()!))
|
||||
.setURL(
|
||||
event.instance.queue.track[0] instanceof YouTubeVideo
|
||||
? encodeURI(`https://www.youtube.com/watch?v=${event.instance.queue.track[0].id}`)
|
||||
: encodeURI(event.instance.getActualPlaybackURL()!)
|
||||
)
|
||||
.setStyle(ButtonStyle.Link)
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction } from "discord.js";
|
||||
import { I18n } from 'i18n';
|
||||
import { Message, CommandInteraction } from 'discord.js';
|
||||
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
|
||||
const EMBEDS = {
|
||||
VOICECHANNEL_LEFT: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -32,46 +32,49 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Leave extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_Leave";
|
||||
public commands = ["leave", "disconnect", "dc"];
|
||||
public commandInteractionName = "leave";
|
||||
public id = 'Discord_MusicPlayer_Leave';
|
||||
public commands = ['leave', 'disconnect', 'dc'];
|
||||
public commandInteractionName = 'leave';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
if(!guild || !member) return;
|
||||
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, locale)] });
|
||||
|
||||
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if(!instance)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
if(instance.voiceChannel.id !== voiceChannel.id)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)] });
|
||||
|
||||
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if (!instance)
|
||||
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, locale)]
|
||||
});
|
||||
|
||||
DiscordMusicPlayer.destoryGuildInstance(guild.id);
|
||||
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.VOICECHANNEL_LEFT(data, locale)] });
|
||||
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.VOICECHANNEL_LEFT(data, locale)] });
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction } from "discord.js";
|
||||
import { I18n } from 'i18n';
|
||||
import { Message, CommandInteraction } from 'discord.js';
|
||||
|
||||
import DiscordMusicPlayer, { DiscordMusicPlayerLoopMode } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
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";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeErrorEmbed,
|
||||
makeSuccessEmbed,
|
||||
sendHybridInteractionMessageResponse,
|
||||
makeInfoEmbed
|
||||
} from '../../utils/DiscordMessage';
|
||||
const EMBEDS = {
|
||||
INVALID_LOOP_MODE: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
@@ -50,12 +55,11 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
export default class Loop extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_Loop";
|
||||
public commands = ["loop", "repeat"];
|
||||
public commandInteractionName = "loop";
|
||||
public id = 'Discord_MusicPlayer_Loop';
|
||||
public commands = ['loop', 'repeat'];
|
||||
public commandInteractionName = 'loop';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -66,7 +70,6 @@ export default class Loop extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const user = data.getUser();
|
||||
const member = data.getMember();
|
||||
@@ -78,39 +81,52 @@ export default class Loop extends DiscordModule {
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length !== 0)
|
||||
query = args.join(' ');
|
||||
}
|
||||
else if (data.isApplicationCommand())
|
||||
query = args.getSubcommand();
|
||||
if (args.length !== 0) query = args.join(' ');
|
||||
} else if (data.isApplicationCommand()) query = args.getSubcommand();
|
||||
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
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, locale)] });
|
||||
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, locale)] }, 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, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if (!query)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_STATUS(data, locale, 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())];
|
||||
let enumKey =
|
||||
Object.keys(DiscordMusicPlayerLoopMode)[
|
||||
Object.values(DiscordMusicPlayerLoopMode).indexOf(query.toLowerCase())
|
||||
];
|
||||
|
||||
if(enumKey) {
|
||||
if (enumKey) {
|
||||
instance.setLoopMode(DiscordMusicPlayerLoopMode[enumKey as keyof typeof DiscordMusicPlayerLoopMode]);
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOP_SET(data, locale, instance.getLoopMode())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.LOOP_SET(data, locale, instance.getLoopMode())]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_LOOP_MODE(data, locale)] });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { Message, CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
|
||||
import { I18n } from "i18n";
|
||||
import { SpotifyTrack, YouTubeVideo } from "play-dl";
|
||||
import { Message, CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
import { SpotifyTrack, YouTubeVideo } from 'play-dl';
|
||||
|
||||
import DiscordProvider from "../../providers/Discord";
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordProvider from '../../providers/Discord';
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeErrorEmbed, makeInfoEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
|
||||
const EMBEDS = {
|
||||
NOW_PLAYING: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -24,7 +23,7 @@ const EMBEDS = {
|
||||
|
||||
if (TrackUtils.getHighestResolutionThumbnail(thumbnails))
|
||||
embed.setImage(TrackUtils.getHighestResolutionThumbnail(thumbnails).url);
|
||||
|
||||
|
||||
return embed;
|
||||
},
|
||||
NO_MUSIC_PLAYING: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -33,14 +32,13 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class NowPlaying extends DiscordModule {
|
||||
public id = 'Discord_MusicPlayer_NowPlaying';
|
||||
public commands = ['nowplaying', 'np'];
|
||||
public commandInteractionName = 'nowplaying';
|
||||
|
||||
public id = "Discord_MusicPlayer_NowPlaying";
|
||||
public commands = ["nowplaying", "np"];
|
||||
public commandInteractionName = "nowplaying";
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
@@ -50,35 +48,44 @@ export default class NowPlaying 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 || !instance.queue.track[0]) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] });
|
||||
if (!instance || !instance.queue.track[0])
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
||||
|
||||
if(instance.queue.track[0] instanceof SpotifyTrack)
|
||||
if (instance.queue.track[0] instanceof SpotifyTrack)
|
||||
row.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🟢')
|
||||
.setLabel(' Open in Spotify')
|
||||
.setURL(encodeURI(`https://open.spotify.com/track/${instance.queue.track[0].id}`))
|
||||
.setStyle(ButtonStyle.Link),
|
||||
.setStyle(ButtonStyle.Link)
|
||||
]);
|
||||
if(instance.queue.track[0] instanceof YouTubeVideo || instance.queue.track[0] instanceof SpotifyTrack) {
|
||||
const actualPlaybackURL = instance.getActualPlaybackURL();
|
||||
if(instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
|
||||
row.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🔴')
|
||||
.setLabel(' Open in YouTube')
|
||||
.setURL(instance.queue.track[0] instanceof YouTubeVideo ? encodeURI(`https://www.youtube.com/watch?v=${instance.queue.track[0].id}`) : encodeURI(instance.getActualPlaybackURL()!))
|
||||
.setStyle(ButtonStyle.Link),
|
||||
]);
|
||||
}
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [await EMBEDS.NOW_PLAYING(data, locale, instance.queue.track[0])], components: [row] });
|
||||
if (instance.queue.track[0] instanceof YouTubeVideo || instance.queue.track[0] instanceof SpotifyTrack) {
|
||||
const actualPlaybackURL = instance.getActualPlaybackURL();
|
||||
if (instance.queue.track[0] instanceof SpotifyTrack && !actualPlaybackURL) return;
|
||||
row.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🔴')
|
||||
.setLabel(' Open in YouTube')
|
||||
.setURL(
|
||||
instance.queue.track[0] instanceof YouTubeVideo
|
||||
? encodeURI(`https://www.youtube.com/watch?v=${instance.queue.track[0].id}`)
|
||||
: encodeURI(instance.getActualPlaybackURL()!)
|
||||
)
|
||||
.setStyle(ButtonStyle.Link)
|
||||
]);
|
||||
}
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.NOW_PLAYING(data, locale, instance.queue.track[0])],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction, Interaction } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
|
||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import {
|
||||
makeSuccessEmbed,
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
PAUSED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -39,24 +44,22 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Pause extends DiscordModule{
|
||||
|
||||
public id = "Discord_MusicPlayer_Pause";
|
||||
public commands = ["pause"];
|
||||
public commandInteractionName = "pause";
|
||||
export default class Pause extends DiscordModule {
|
||||
public id = 'Discord_MusicPlayer_Pause';
|
||||
public commands = ['pause'];
|
||||
public commandInteractionName = 'pause';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
@@ -66,23 +69,33 @@ export default class Pause extends DiscordModule{
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
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, locale)] });
|
||||
if (!instance)
|
||||
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, locale)] }, true);
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
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, locale)] });
|
||||
if (instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if(instance.isPaused())
|
||||
if (instance.isPaused())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ALREADY_PAUSED(data, locale)] });
|
||||
|
||||
|
||||
instance.pausePlayer();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PAUSED(data, locale)] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ const EMBEDS = {
|
||||
});
|
||||
},
|
||||
ADDED_QUEUE: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -354,7 +353,15 @@ export default class Play extends DiscordModule {
|
||||
|
||||
if (!result) return;
|
||||
|
||||
if (data.isMessage() && data.getMessage().embeds.length > 0 && await checkBotPermissionsInChannel({ guild, channel, permissions: [PermissionsBitField.Flags.ManageMessages]})) {
|
||||
if (
|
||||
data.isMessage() &&
|
||||
data.getMessage().embeds.length > 0 &&
|
||||
(await checkBotPermissionsInChannel({
|
||||
guild,
|
||||
channel,
|
||||
permissions: [PermissionsBitField.Flags.ManageMessages]
|
||||
}))
|
||||
) {
|
||||
data.getMessage().suppressEmbeds(true);
|
||||
}
|
||||
|
||||
@@ -373,8 +380,7 @@ export default class Play extends DiscordModule {
|
||||
)
|
||||
.setLabel(' Add the remaining songs in the playlist')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
]
|
||||
);
|
||||
]);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result)],
|
||||
@@ -389,11 +395,15 @@ export default class Play extends DiscordModule {
|
||||
|
||||
if (linkData.type === 'playlist' || linkData.type === 'album') {
|
||||
let playlist = await DiscordMusicPlayer.getSpotifySongsInPlayList(query).catch((err) => {
|
||||
sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOKUP_ERROR(data, locale, err)] }, true);
|
||||
sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.LOOKUP_ERROR(data, locale, err)] },
|
||||
true
|
||||
);
|
||||
return null;
|
||||
});
|
||||
|
||||
if(!playlist) return;
|
||||
|
||||
if (!playlist) return;
|
||||
const songs = await playlist.all_tracks();
|
||||
|
||||
for (const song of songs) {
|
||||
@@ -414,7 +424,15 @@ export default class Play extends DiscordModule {
|
||||
|
||||
if (!result) return;
|
||||
|
||||
if (data.isMessage() && data.getMessage().embeds.length > 0 && await checkBotPermissionsInChannel({ guild, channel, permissions: [PermissionsBitField.Flags.ManageMessages]})) {
|
||||
if (
|
||||
data.isMessage() &&
|
||||
data.getMessage().embeds.length > 0 &&
|
||||
(await checkBotPermissionsInChannel({
|
||||
guild,
|
||||
channel,
|
||||
permissions: [PermissionsBitField.Flags.ManageMessages]
|
||||
}))
|
||||
) {
|
||||
data.getMessage().suppressEmbeds(true);
|
||||
}
|
||||
|
||||
@@ -423,7 +441,6 @@ export default class Play extends DiscordModule {
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result)]
|
||||
});
|
||||
|
||||
} else {
|
||||
let result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
||||
|
||||
@@ -461,7 +478,7 @@ export default class Play extends DiscordModule {
|
||||
)
|
||||
.setLabel(' Not this? Search!')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
]);
|
||||
]);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result[0])],
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
|
||||
import { I18n } from 'i18n';
|
||||
import { Message, CommandInteraction, ActivityType, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
||||
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { joinVoiceChannelProcedure } from "./Join";
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import { joinVoiceChannelProcedure } from './Join';
|
||||
|
||||
const EMBEDS = {
|
||||
NOT_DETECTED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -28,7 +28,6 @@ const EMBEDS = {
|
||||
});
|
||||
},
|
||||
ADDED_QUEUE: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
@@ -43,28 +42,26 @@ const EMBEDS = {
|
||||
|
||||
return embed;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class PlayMy extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_PlayMy";
|
||||
public commands = ["playmy"];
|
||||
public commandInteractionName = "playmy";
|
||||
public id = 'Discord_MusicPlayer_PlayMy';
|
||||
public commands = ['playmy'];
|
||||
public commandInteractionName = 'playmy';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
if(!guild || !member) return;
|
||||
if (!guild || !member) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
@@ -94,22 +91,20 @@ export default class PlayMy extends DiscordModule {
|
||||
instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
}
|
||||
|
||||
if(!instance) return;
|
||||
if(!member.presence) return;
|
||||
if(!member.presence.activities) return;
|
||||
if (!instance) return;
|
||||
if (!member.presence) return;
|
||||
if (!member.presence.activities) return;
|
||||
|
||||
let query;
|
||||
let found = false;
|
||||
for (const activity of member.presence.activities) {
|
||||
if(activity.type === ActivityType.Listening) {
|
||||
if(!activity.details) continue;
|
||||
if (activity.type === ActivityType.Listening) {
|
||||
if (!activity.details) continue;
|
||||
found = true;
|
||||
|
||||
if(activity.name == "Spotify")
|
||||
query = `${activity.state} - ${activity.details}`
|
||||
else
|
||||
query = `${activity.state} - ${activity.details}` // TODO: Find better query formula
|
||||
|
||||
if (activity.name == 'Spotify') query = `${activity.state} - ${activity.details}`;
|
||||
else query = `${activity.state} - ${activity.details}`; // TODO: Find better query formula
|
||||
|
||||
const result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
||||
if (!result) continue;
|
||||
instance.addTrackToQueue(result[0]);
|
||||
@@ -120,10 +115,10 @@ export default class PlayMy extends DiscordModule {
|
||||
// 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
|
||||
// if(result[0].title === query || result[0].title && (Math.ceil((result[0].title.split(" ").length - 1) / 2) === Math.ceil((query.split(" ").length - 1) / 2))) return;
|
||||
|
||||
|
||||
// The query length is too long to fit in json
|
||||
if (query.length > 100 - 51) return;
|
||||
|
||||
|
||||
row = new ActionRowBuilder<ButtonBuilder>().addComponents([
|
||||
new ButtonBuilder()
|
||||
.setEmoji('🔎')
|
||||
@@ -138,10 +133,10 @@ export default class PlayMy extends DiscordModule {
|
||||
)
|
||||
.setLabel(' Not this? Search!')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
]);
|
||||
]);
|
||||
}
|
||||
|
||||
if(!row)
|
||||
if (!row)
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result[0])]
|
||||
});
|
||||
@@ -153,9 +148,8 @@ export default class PlayMy extends DiscordModule {
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.NOT_DETECTED(data, locale)] });
|
||||
if (!found) await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_DETECTED(data, locale)] });
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,10 +133,14 @@ export default class QueueCommand extends DiscordModule {
|
||||
switch (query.toLowerCase()) {
|
||||
case 'clear':
|
||||
instance.clearQueue();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE_CLEARED(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.QUEUE_CLEARED(data, locale)]
|
||||
});
|
||||
case 'shuffle':
|
||||
instance.shuffleQueue();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE_SHUFFLED(data, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.QUEUE_SHUFFLED(data, locale)]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||
import { I18n } from "i18n";
|
||||
import { Message, CommandInteraction, Interaction } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeSuccessEmbed,
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../../utils/DiscordMessage';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
const EMBEDS = {
|
||||
RESUMED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -38,24 +43,22 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Resume extends DiscordModule{
|
||||
|
||||
public id = "Discord_MusicPlayer_Resume";
|
||||
public commands = ["resume"];
|
||||
public commandInteractionName = "resume";
|
||||
export default class Resume extends DiscordModule {
|
||||
public id = 'Discord_MusicPlayer_Resume';
|
||||
public commands = ['resume'];
|
||||
public commandInteractionName = 'resume';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
@@ -66,23 +69,33 @@ export default class Resume extends DiscordModule{
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
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, locale)] });
|
||||
if (!instance)
|
||||
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, locale)] }, true);
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
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, locale)] });
|
||||
if (instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)]
|
||||
});
|
||||
|
||||
if(!instance.isPaused())
|
||||
if (!instance.isPaused())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_PAUSED(data, locale)] });
|
||||
|
||||
instance.resumePlayer();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.RESUMED(data, locale)] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
import { Message, CommandInteraction, ActionRowBuilder, ButtonInteraction, SelectMenuBuilder, SelectMenuComponentOptionData } from "discord.js";
|
||||
import { I18n } from "i18n";
|
||||
import {
|
||||
Message,
|
||||
CommandInteraction,
|
||||
ActionRowBuilder,
|
||||
ButtonInteraction,
|
||||
SelectMenuBuilder,
|
||||
SelectMenuComponentOptionData
|
||||
} from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import { joinVoiceChannelProcedure } from "./Join";
|
||||
import { joinVoiceChannelProcedure } from './Join';
|
||||
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from "../../providers/DiscordMusicPlayer";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { makeErrorEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import { makeErrorEmbed, sendHybridInteractionMessageResponse, makeInfoEmbed } from '../../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
SEARCH_INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -17,7 +24,7 @@ const EMBEDS = {
|
||||
fields: [
|
||||
{
|
||||
name: locale.__('common.available_args'),
|
||||
value: locale.__('musicplayer_search.valid_args'),
|
||||
value: locale.__('musicplayer_search.valid_args')
|
||||
}
|
||||
],
|
||||
user: data.getUser()
|
||||
@@ -28,7 +35,7 @@ const EMBEDS = {
|
||||
title: locale.__('musicplayer_search.title_result'),
|
||||
description: `${locale.__('musicplayer_search.x_results_found', {
|
||||
COUNT: result.length.toString()
|
||||
})}\n\n${result.map(track => `- [${TrackUtils.getTitle(track)}](${track.url})`).join('\n')}`,
|
||||
})}\n\n${result.map((track) => `- [${TrackUtils.getTitle(track)}](${track.url})`).join('\n')}`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
@@ -44,12 +51,11 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
export default class Search extends DiscordModule {
|
||||
|
||||
public id = "Discord_MusicPlayer_Search";
|
||||
public commands = ["search"];
|
||||
public commandInteractionName = "search";
|
||||
public id = 'Discord_MusicPlayer_Search';
|
||||
public commands = ['search'];
|
||||
public commandInteractionName = 'search';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -70,16 +76,18 @@ export default class Search extends DiscordModule {
|
||||
data.q stands for data.query
|
||||
*/
|
||||
|
||||
if (typeof payload.m === 'undefined' ||
|
||||
if (
|
||||
typeof payload.m === 'undefined' ||
|
||||
typeof payload.a === 'undefined' ||
|
||||
payload.m !== 'MP_S' ||
|
||||
payload.a !== 'search') return;
|
||||
payload.a !== 'search'
|
||||
)
|
||||
return;
|
||||
|
||||
await this.run(new HybridInteractionMessage(interaction), payload.d.q);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
const guild = data.getGuild();
|
||||
const user = data.getUser();
|
||||
const member = data.getMember();
|
||||
@@ -95,19 +103,18 @@ export default class Search extends DiscordModule {
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_INFO(data, locale)] });
|
||||
|
||||
query = args.join(' ');
|
||||
}
|
||||
else if (data.isApplicationCommand())
|
||||
} else if (data.isApplicationCommand())
|
||||
query = data.getSlashCommand().options.get('query', true).value?.toString();
|
||||
else if (data.isButton())
|
||||
query = args;
|
||||
else if (data.isButton()) query = args;
|
||||
|
||||
if (!query) return;
|
||||
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
if (!DiscordMusicPlayer.isGuildInstanceExists(guild.id))
|
||||
await joinVoiceChannelProcedure(data, null, voiceChannel);
|
||||
@@ -116,7 +123,9 @@ 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, locale)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data, locale)]
|
||||
});
|
||||
|
||||
if (!instance.isConnected()) {
|
||||
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
|
||||
@@ -136,14 +145,16 @@ export default class Search extends DiscordModule {
|
||||
data.r stands for data.requester
|
||||
data.v stands for data.voiceChannel
|
||||
*/
|
||||
messageSelectMenu.setCustomId(JSON.stringify({
|
||||
m: 'MP_SM',
|
||||
a: 'play',
|
||||
d: {
|
||||
r: user.id,
|
||||
v: voiceChannel.id
|
||||
}
|
||||
}))
|
||||
messageSelectMenu.setCustomId(
|
||||
JSON.stringify({
|
||||
m: 'MP_SM',
|
||||
a: 'play',
|
||||
d: {
|
||||
r: user.id,
|
||||
v: voiceChannel.id
|
||||
}
|
||||
})
|
||||
);
|
||||
messageSelectMenu.setPlaceholder('Nothing selected');
|
||||
|
||||
for (let song of result) {
|
||||
@@ -160,21 +171,21 @@ export default class Search extends DiscordModule {
|
||||
const row = new ActionRowBuilder<SelectMenuBuilder>();
|
||||
row.addComponents([messageSelectMenu]);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SEARCH_RESULT(data, locale, result)], components: [row] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SEARCH_RESULT(data, locale, result)],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
isJsonValid(jsonString: string) {
|
||||
try {
|
||||
let o = JSON.parse(jsonString);
|
||||
if (o && typeof o === "object") {
|
||||
if (o && typeof o === 'object') {
|
||||
return true;
|
||||
//return o;
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
} catch (e) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
|
||||
import { Message, CommandInteraction } from "discord.js";
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../../utils/DiscordMessage";
|
||||
import { Message, CommandInteraction } from 'discord.js';
|
||||
import { makeSuccessEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from '../../utils/DiscordMessage';
|
||||
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import { I18n } from "i18n";
|
||||
import Locale from "../../services/Locale";
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
import { I18n } from 'i18n';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
const EMBEDS = {
|
||||
SKIPPED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -38,24 +38,22 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Skip extends DiscordModule{
|
||||
|
||||
public id = "Discord_MusicPlayer_Skip";
|
||||
public commands = ["skip"];
|
||||
public commandInteractionName = "skip";
|
||||
export default class Skip extends DiscordModule {
|
||||
public id = 'Discord_MusicPlayer_Skip';
|
||||
public commands = ['skip'];
|
||||
public commandInteractionName = 'skip';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const member = data.getMember();
|
||||
|
||||
@@ -65,24 +63,35 @@ export default class Skip extends DiscordModule{
|
||||
const voiceChannel = member.voice.channel;
|
||||
|
||||
if (!voiceChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data, locale)] });
|
||||
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, locale)] });
|
||||
if (!instance)
|
||||
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, locale)] }, true);
|
||||
if (instance.voiceChannel.id !== voiceChannel.id)
|
||||
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, locale)] });
|
||||
if (instance.queue.track.length === 0)
|
||||
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, locale)] });
|
||||
else
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data, locale)] });
|
||||
if (instance.queue.track.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SKIPPED_LASTSONG(data, locale)]
|
||||
});
|
||||
else return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SKIPPED(data, locale)] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user