Add user voice channel checks

This commit is contained in:
2022-01-30 22:42:00 +07:00
parent da56d51ba0
commit 16c03c3f4f
6 changed files with 125 additions and 27 deletions
+10 -3
View File
@@ -23,7 +23,7 @@ const EMBEDS = {
description: `I can't join mutiple voice channel on the same guild.
I wish I had a superpower, maybe... one day I will.
Want to move me to your voice channel? You can use the button below (soon)${!haveForceMove ? ` or use move command (soon)` : ", use move command (soon) or just (ab)use me with your admin permissions hehe"}`,
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!**"}`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
@@ -34,6 +34,12 @@ const EMBEDS = {
user: (data instanceof Interaction) ? data.user : data.author
});
},
USER_NOT_IN_VOICECHANNEL: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `You need to be in the voice channel first!`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
NOW_PLAYING: (data: Message | Interaction, track: ValidTracks) => {
const embed = makeInfoEmbed({
title: 'Now playing',
@@ -198,8 +204,9 @@ export default class Join {
const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
if (!channel) return;
// TODO: User must be in vc error msg
if (!data.member.voice.channel) return;
if (!data.member.voice.channel)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
let voiceChannel = data.member.voice.channel;
+27 -2
View File
@@ -1,5 +1,5 @@
import { Message, CommandInteraction, Interaction, VoiceChannel } from "discord.js";
import { getEmotes, makeSuccessEmbed, makeProcessingEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import { getEmotes, makeSuccessEmbed, makeErrorEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import DiscordProvider from "../../providers/Discord";
import Users from "../../services/Users"
import Environment from "../../providers/Environment";
@@ -12,6 +12,24 @@ const EMBEDS = {
description: `Left the voice channel`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
USER_NOT_IN_VOICECHANNEL: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `You need to be in the voice channel first!`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
NO_MUSIC_PLAYING: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `There are no music playing`,
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
});
}
}
@@ -40,11 +58,18 @@ export default class Leave {
if(!data.guildId) return;
const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
if (!data.member.voice.channel)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
if(!channel) return;
let instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
if(!instance) return;
if(!instance)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
if(instance.voiceChannel.id !== data.member.voice.channel.id)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] });
DiscordMusicPlayer.destoryGuildInstance(data.guild?.id!);
+30 -7
View File
@@ -27,7 +27,19 @@ const EMBEDS = {
});
embed.setImage(track.thumbnails[0].url);
return embed;
}
},
USER_NOT_IN_VOICECHANNEL: (data: Message | Interaction) => {
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
});
},
}
@@ -49,6 +61,7 @@ export default class Play {
if (!this.tryParseJSONObject(interaction.customId)) return;
let payload = JSON.parse(interaction.customId);
if(!interaction.member?.user?.id) return;
/*
Discord have 100 char custom id char limit
@@ -62,14 +75,17 @@ export default class Play {
payload.module !== 'MP_SM' ||
payload.action !== 'play') return;
interaction.deferReply();
await interaction.deferReply();
let voiceChannel = interaction.guild.channels.cache.get(payload.data.v);
let member = interaction.guild.members.cache.get(payload.data.r);
let voiceChannel = DiscordProvider.client.guilds.cache.get(interaction.guildId)?.channels.cache.get(payload.data.v);
let member = DiscordProvider.client.guilds.cache.get(interaction.guildId)?.members.cache.get(interaction.member?.user?.id);
if(!member) return;
if (!voiceChannel || !(voiceChannel instanceof VoiceChannel)) return;
if (!member.voice.channel) return;
if (!member.voice.channel)
return await sendMessageOrInteractionResponse(interaction, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(interaction)] }, true);
if (!DiscordMusicPlayer.isGuildInstanceExists(interaction.guildId)) {
await joinVoiceChannelProcedure(interaction, null, voiceChannel);
@@ -77,6 +93,9 @@ export default class Play {
let instance = DiscordMusicPlayer.getGuildInstance(interaction.guildId);
if(instance!.voiceChannel.id !== member.voice.channel.id)
return await sendMessageOrInteractionResponse(interaction, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(interaction)] }, true);
if (!instance!.isConnected()) {
await joinVoiceChannelProcedure(interaction, instance!, voiceChannel);
instance = DiscordMusicPlayer.getGuildInstance(interaction.guildId);
@@ -123,8 +142,9 @@ export default class Play {
if (!query) return;
if (!(data.channel instanceof TextChannel)) return;
// TODO: User must be in vc error msg
if (!data.member.voice.channel) return;
if (!data.member.voice.channel)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
let voiceChannel = data.member.voice.channel;
if (!DiscordMusicPlayer.isGuildInstanceExists(data.guildId)) {
@@ -133,6 +153,9 @@ export default class Play {
let instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
if(instance!.voiceChannel.id !== data.member.voice.channel.id)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] }, true);
if (!instance!.isConnected()) {
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
+10 -5
View File
@@ -1,5 +1,5 @@
import { Message, CommandInteraction, Interaction, VoiceChannel, TextChannel } from "discord.js";
import { getEmotes, makeSuccessEmbed, makeProcessingEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import { getEmotes, makeSuccessEmbed, makeErrorEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import DiscordProvider from "../../providers/Discord";
import Users from "../../services/Users"
import Environment from "../../providers/Environment";
@@ -25,6 +25,12 @@ const EMBEDS = {
description: `Now playing: ${queue.track[0].title}\n\nUpcoming song: ${queue.track[1].title}\n\nThere are ${Object.keys(queue).length} songs in the queue!`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
NO_MUSIC_PLAYING: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `There are no music playing`,
user: (data instanceof Interaction) ? data.user : data.author
});
}
}
@@ -53,12 +59,11 @@ export default class QueueCommand {
if(!data.guildId) return;
if(!(data.channel instanceof TextChannel)) return;
const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
if(!channel) return;
//const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
//if(!channel) return;
const instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
if(!instance) return;
if(!instance) return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
await sendMessageOrInteractionResponse(data, { embeds:[EMBEDS.QUEUE(data, instance.queue)] });
+19 -2
View File
@@ -28,6 +28,18 @@ const EMBEDS = {
});
embed.setImage(track.thumbnails[0].url);
return embed;
},
USER_NOT_IN_VOICECHANNEL: (data: Message | Interaction) => {
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
});
}
}
@@ -77,8 +89,10 @@ export default class Search {
if (!query) return;
if (!(data.channel instanceof TextChannel)) return;
// TODO: User must be in vc error msg
if (!data.member.voice.channel) return;
if (!data.member.voice.channel)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
let voiceChannel = data.member.voice.channel;
if (!DiscordMusicPlayer.isGuildInstanceExists(data.guildId)) {
@@ -87,6 +101,9 @@ export default class Search {
let instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
if (instance!.voiceChannel.id !== voiceChannel.id)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] });
if (!instance!.isConnected()) {
await joinVoiceChannelProcedure(data, instance!, voiceChannel);
instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
+29 -8
View File
@@ -1,5 +1,5 @@
import { Message, CommandInteraction, Interaction, VoiceChannel } from "discord.js";
import { getEmotes, makeSuccessEmbed, makeProcessingEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import { getEmotes, makeSuccessEmbed, makeErrorEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import DiscordProvider from "../../providers/Discord";
import Users from "../../services/Users"
import Environment from "../../providers/Environment";
@@ -11,6 +11,24 @@ const EMBEDS = {
title: `Skipped`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
NO_MUSIC_PLAYING: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `There are no music playing`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
USER_NOT_IN_VOICECHANNEL: (data: Message | Interaction) => {
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
});
}
}
@@ -39,19 +57,22 @@ export default class Skip {
if (!data.guildId) return;
const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
if (!data.member.voice.channel)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
if (!channel) return;
// TODO: User must be in vc error msg
if (!data.member.voice.channel) return;
let voiceChannel = data.member.voice.channel;
// TODO: No queue error
if(!DiscordMusicPlayer.isGuildInstanceExists(data.guildId)) {
return;
}
if(!DiscordMusicPlayer.isGuildInstanceExists(data.guildId))
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
const instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
if(instance!.voiceChannel.id !== data.member.voice.channel.id)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] }, true);
instance!.skipTrack();
//await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.SKIPPED(data)] });