From 379ae221c00f0027d30d3a975ccefe3109204ad5 Mon Sep 17 00:00:00 2001 From: Nanotect <61177761+Adivise@users.noreply.github.com> Date: Thu, 10 Mar 2022 09:37:56 +0700 Subject: [PATCH] `Add` `ContextMenus` Limit 5 Context! --- slashcommands/Context/Leave.js | 28 +++++++++++ slashcommands/Context/Loop.js | 37 ++++++++++++++ slashcommands/Context/Play.js | 84 ++++++++++++++++++++++++++++++++ slashcommands/Context/Shuffle.js | 26 ++++++++++ slashcommands/Context/Skip.js | 26 ++++++++++ 5 files changed, 201 insertions(+) create mode 100644 slashcommands/Context/Leave.js create mode 100644 slashcommands/Context/Loop.js create mode 100644 slashcommands/Context/Play.js create mode 100644 slashcommands/Context/Shuffle.js create mode 100644 slashcommands/Context/Skip.js diff --git a/slashcommands/Context/Leave.js b/slashcommands/Context/Leave.js new file mode 100644 index 0000000..a5261c6 --- /dev/null +++ b/slashcommands/Context/Leave.js @@ -0,0 +1,28 @@ +const { ContextMenuInteraction, MessageEmbed } = require('discord.js'); + +module.exports = { + name: "Context | Stop", + type: 3, + /** + * @param {ContextMenuInteraction} interaction + */ + run: async (interaction, client, user, language) => { + await interaction.deferReply({ ephemeral: false }); + const msg = await interaction.editReply(`${client.i18n.get(language, "music", "leave_loading")}`); + + const player = client.manager.get(interaction.guild.id); + if (!player) return msg.edit(`${client.i18n.get(language, "noplayer", "no_player")}`); + const { channel } = interaction.member.voice; + if (!channel || interaction.member.voice.channel !== interaction.guild.me.voice.channel) return msg.edit(`${client.i18n.get(language, "noplayer", "no_voice")}`); + + await player.destroy(); + + const embed = new MessageEmbed() + .setDescription(`${client.i18n.get(language, "music", "leave_msg", { + channel: channel.name + })}`) + .setColor(client.color); + + msg.edit({ content: " ", embeds: [embed] }) + } +} diff --git a/slashcommands/Context/Loop.js b/slashcommands/Context/Loop.js new file mode 100644 index 0000000..315898f --- /dev/null +++ b/slashcommands/Context/Loop.js @@ -0,0 +1,37 @@ +const { ContextMenuInteraction, MessageEmbed } = require('discord.js'); + +module.exports = { + name: "Context | Loop", + type: 3, + /** + * @param {ContextMenuInteraction} interaction + */ + run: async (interaction, client, user, language) => { + await interaction.deferReply({ ephemeral: false }); + const msg = await interaction.editReply(`${client.i18n.get(language, "music", "loopall_loading")}`); + + const player = client.manager.get(interaction.guild.id); + if (!player) return msg.edit(`${client.i18n.get(language, "noplayer", "no_player")}`); + const { channel } = interaction.member.voice; + if (!channel || interaction.member.voice.channel !== interaction.guild.me.voice.channel) return msg.edit(`${client.i18n.get(language, "noplayer", "no_voice")}`); + + if (player.queueRepeat === true) { + player.setQueueRepeat(false) + + const unloopall = new MessageEmbed() + .setDescription(`${client.i18n.get(language, "music", "unloopall")}`) + .setColor(client.color); + + return msg.edit({ content: ' ', embeds: [unloopall] }); + } + else { + player.setQueueRepeat(true); + + const loopall = new MessageEmbed() + .setDescription(`${client.i18n.get(language, "music", "loopall")}`) + .setColor(client.color); + + return msg.edit({ content: ' ', embeds: [loopall] }); + } + } +}; \ No newline at end of file diff --git a/slashcommands/Context/Play.js b/slashcommands/Context/Play.js new file mode 100644 index 0000000..9822625 --- /dev/null +++ b/slashcommands/Context/Play.js @@ -0,0 +1,84 @@ +const { ContextMenuInteraction, MessageEmbed, Permissions } = require('discord.js'); +const { convertTime } = require("../../structures/convert.js"); + +module.exports = { + name: "Context | Play", + type: 3, + /** + * @param {ContextMenuInteraction} interaction + */ + run: async (interaction, client, user, language) => { + await interaction.deferReply({ ephemeral: false }); + + const value = (interaction.channel.messages.cache.get(interaction.targetId).content ?? await interaction.channel.messages.fetch(interaction.targetId)); + if (!value.startsWith('https')) return interaction.editReply(`${client.i18n.get(language, "music", "play_startwith")}`); + + const msg = await interaction.editReply(`${client.i18n.get(language, "music", "play_loading")}`); + + const { channel } = interaction.member.voice; + if (!channel) return msg.edit(`${client.i18n.get(language, "music", "play_invoice")}`); + if (!channel.permissionsFor(interaction.guild.me).has(Permissions.FLAGS.CONNECT)) return msg.edit(`${client.i18n.get(language, "music", "play_join")}`); + if (!channel.permissionsFor(interaction.guild.me).has(Permissions.FLAGS.SPEAK)) return msg.edit(`${client.i18n.get(language, "music", "play_speak")}`); + + const player = await client.manager.create({ + guild: interaction.guild.id, + voiceChannel: interaction.member.voice.channel.id, + textChannel: interaction.channel.id, + selfDeafen: true, + }); + + const state = player.state; + if (state != "CONNECTED") await player.connect(); + const res = await client.manager.search(value, interaction.user); + if(res.loadType != "NO_MATCHES") { + if(res.loadType == "TRACK_LOADED") { + player.queue.add(res.tracks[0]); + const embed = new MessageEmbed() + .setDescription(`${client.i18n.get(language, "music", "play_track", { + title: res.tracks[0].title, + url: res.tracks[0].uri, + duration: convertTime(res.tracks[0].duration, true), + request: res.tracks[0].requester + })}`) + .setColor(client.color) + msg.edit({ content: " ", embeds: [embed] }); + if(!player.playing) player.play(); + } + else if(res.loadType == "PLAYLIST_LOADED") { + player.queue.add(res.tracks) + const embed = new MessageEmbed() + .setDescription(`${client.i18n.get(language, "music", "play_playlist", { + title: res.playlist.name, + url: value, + duration: convertTime(res.playlist.duration), + songs: res.tracks.length, + request: res.tracks[0].requester + })}`) + .setColor(client.color) + msg.edit({ content: " ", embeds: [embed] }); + if(!player.playing) player.play(); + } + else if(res.loadType == "SEARCH_RESULT") { + player.queue.add(res.tracks[0]); + const embed = new MessageEmbed() + .setDescription(`${client.i18n.get(language, "music", "play_result", { + title: res.tracks[0].title, + url: res.tracks[0].uri, + duration: convertTime(res.tracks[0].duration, true), + request: res.tracks[0].requester + })}`) + .setColor(client.color) + msg.edit({ content: " ", embeds: [embed] }); + if(!player.playing) player.play(); + } + else if(res.loadType == "LOAD_FAILED") { + msg.edit(`${client.i18n.get(language, "music", "play_fail")}`); + player.destroy(); + } + } + else { + msg.edit(`${client.i18n.get(language, "music", "play_match")}`); + player.destroy(); + } + } +} \ No newline at end of file diff --git a/slashcommands/Context/Shuffle.js b/slashcommands/Context/Shuffle.js new file mode 100644 index 0000000..f5f9527 --- /dev/null +++ b/slashcommands/Context/Shuffle.js @@ -0,0 +1,26 @@ +const { ContextMenuInteraction, MessageEmbed } = require('discord.js'); + +module.exports = { + name: "Context | Shuffle", + type: 3, + /** + * @param {ContextMenuInteraction} interaction + */ + run: async (interaction, client, user, language) => { + await interaction.deferReply({ ephemeral: false }); + const msg = await interaction.editReply(`${client.i18n.get(language, "music", "shuffle_loading")}`); + + const player = client.manager.get(interaction.guild.id); + if (!player) return msg.edit(`${client.i18n.get(language, "noplayer", "no_player")}`); + const { channel } = interaction.member.voice; + if (!channel || interaction.member.voice.channel !== interaction.guild.me.voice.channel) return msg.edit(`${client.i18n.get(language, "noplayer", "no_voice")}`); + + await player.queue.shuffle(); + + const shuffle = new MessageEmbed() + .setDescription(`${client.i18n.get(language, "music", "shuffle_msg")}`) + .setColor(client.color); + + msg.edit({ content: " ", embeds: [shuffle] }); + } +} \ No newline at end of file diff --git a/slashcommands/Context/Skip.js b/slashcommands/Context/Skip.js new file mode 100644 index 0000000..45578cc --- /dev/null +++ b/slashcommands/Context/Skip.js @@ -0,0 +1,26 @@ +const { ContextMenuInteraction, MessageEmbed } = require('discord.js'); + +module.exports = { + name: "Context | Skip", + type: 3, + /** + * @param {ContextMenuInteraction} interaction + */ + run: async (interaction, client, user, language) => { + await interaction.deferReply({ ephemeral: false }); + const msg = await interaction.editReply(`${client.i18n.get(language, "music", "skip_loading")}`); + + const player = client.manager.get(interaction.guild.id); + if (!player) return msg.edit(`${client.i18n.get(language, "noplayer", "no_player")}`); + const { channel } = interaction.member.voice; + if (!channel || interaction.member.voice.channel !== interaction.guild.me.voice.channel) return msg.edit(`${client.i18n.get(language, "noplayer", "no_voice")}`); + + await player.stop(); + + const skipped = new MessageEmbed() + .setDescription(`${client.i18n.get(language, "music", "skip_msg")}`) + .setColor(client.color); + + msg.edit({ content: " ", embeds: [skipped] }); + } +} \ No newline at end of file