|
| 1 | +const imports = require('../../imports'); |
| 2 | +var glofunc = require('../../globalfunctions'); |
| 3 | +const globalVars = require('../../globalvars'); |
| 4 | + |
| 5 | +const Discord = require('discord.js'); |
| 6 | +const axios = require("axios"); |
| 7 | + |
| 8 | +module.exports = { |
| 9 | + |
| 10 | + run: function(interaction) { |
| 11 | + function spliceSlice(str, index, count, add) { |
| 12 | + // We cannot pass negative indexes directly to the 2nd slicing operation. |
| 13 | + if (index < 0) { |
| 14 | + index = str.length + index; |
| 15 | + if (index < 0) { |
| 16 | + index = 0; |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + return str.slice(0, index) + (add || "") + str.slice(index + count); |
| 21 | + } |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + if (interaction.customId === 'music_pause') { |
| 26 | + |
| 27 | + |
| 28 | + const serverQueue = globalVars.MusicQueue.get(interaction.guild.id); |
| 29 | + if (!serverQueue || serverQueue.songs.length == 0){ |
| 30 | + interaction.reply({ content: "There is nothing playing now.", ephemeral: true }); |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + if(globalVars.music_djonly && interaction.user.id !== "481895822624161795"){ |
| 35 | + interaction.reply({ content: ":lock: Sorry, DJ only is `enabled`, you can't do any music related commands.", ephemeral: true }); |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + interaction.reply({ content: ":pause_button: Song ``" + serverQueue["songs"][0]["title"] + "`` has been paused.", ephemeral: false }); |
| 40 | + globalVars.audioPlayer.pause(); |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + var percentage = Math.round((serverQueue.songs[0].timeleft/serverQueue.songs[0].length) * 15); |
| 45 | + |
| 46 | + var timebutton = "\\🔘"; |
| 47 | + var timebar = spliceSlice("▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬", percentage, 0, timebutton); |
| 48 | + |
| 49 | + var listening_platform_name = "REPORT TO MVDW"; |
| 50 | + var listening_platform_icon = ""; |
| 51 | + switch(serverQueue.songs[0].type){ |
| 52 | + case 0: |
| 53 | + listening_platform_name = "YouTube"; |
| 54 | + listening_platform_icon = "https://cdn.discordapp.com/attachments/834518897549508649/834713284627529748/youtube_play1600.png"; |
| 55 | + break; |
| 56 | + case 1: |
| 57 | + listening_platform_name = "Creo"; |
| 58 | + listening_platform_icon = "https://www.watchcreo.com/assets/images/favicon_new.png"; |
| 59 | + break; |
| 60 | + case 2: |
| 61 | + listening_platform_name = "SoundCloud"; |
| 62 | + listening_platform_icon = "https://cdn.discordapp.com/attachments/885543263111639061/942008394896781392/iu.png"; |
| 63 | + break; |
| 64 | + case 3: |
| 65 | + listening_platform_name = "uploaded file"; |
| 66 | + listening_platform_icon = "https://cdn.discordapp.com/attachments/885543263111639061/942014209816936448/folder.png"; |
| 67 | + break; |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + const now_playing = new Discord.MessageEmbed() |
| 73 | + .setColor('#19d3c8') |
| 74 | + .setTitle(':arrow_forward: Now Playing:') |
| 75 | + .setDescription("__**" + serverQueue.songs[0].title + "**__\n" + |
| 76 | + "*By " + serverQueue.songs[0].author + "*\n\n" + |
| 77 | + timebar + "\n" + |
| 78 | + glofunc.toHHMMSS(serverQueue.songs[0].timeleft) + " / " + glofunc.toHHMMSS(serverQueue.songs[0].length) + "\n\n") |
| 79 | + .setThumbnail(serverQueue.songs[0].thumbnail) //youtube bugged |
| 80 | + .setFooter("Listen on " + listening_platform_name, listening_platform_icon); |
| 81 | + |
| 82 | + |
| 83 | + const button_row = new Discord.MessageActionRow(); |
| 84 | + const button_row2 = new Discord.MessageActionRow(); |
| 85 | + button_row.addComponents( |
| 86 | + new Discord.MessageButton() |
| 87 | + .setCustomId("music_play") |
| 88 | + .setLabel('') |
| 89 | + .setStyle('PRIMARY') |
| 90 | + .setEmoji('▶️') |
| 91 | + ); |
| 92 | + button_row.addComponents( |
| 93 | + new Discord.MessageButton() |
| 94 | + .setCustomId("music_skip") |
| 95 | + .setLabel('Skip') |
| 96 | + .setStyle('PRIMARY') |
| 97 | + .setEmoji('⏩') |
| 98 | + ); |
| 99 | + button_row.addComponents( |
| 100 | + new Discord.MessageButton() |
| 101 | + .setCustomId("music_loop") |
| 102 | + .setLabel('Loop') |
| 103 | + .setStyle('PRIMARY') |
| 104 | + .setEmoji('🔂') |
| 105 | + ); |
| 106 | + button_row2.addComponents( |
| 107 | + new Discord.MessageButton() |
| 108 | + .setLabel('Open Connect2Music') |
| 109 | + .setStyle('LINK') |
| 110 | + .setURL("https://www.enthix.net/connect2music") |
| 111 | + .setEmoji('🎵') |
| 112 | + .setDisabled(true) |
| 113 | + ); |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + interaction.message.edit({ embeds: [now_playing], components: [button_row, button_row2] }) |
| 119 | + |
| 120 | + |
| 121 | + } else if (interaction.customId === 'music_play') { |
| 122 | + |
| 123 | + |
| 124 | + const serverQueue = globalVars.MusicQueue.get(interaction.guild.id); |
| 125 | + |
| 126 | + if (!serverQueue || serverQueue.songs.length == 0){ |
| 127 | + interaction.reply({ content: "There is nothing playing now.", ephemeral: true }); |
| 128 | + return; |
| 129 | + } |
| 130 | + |
| 131 | + if(globalVars.music_djonly && interaction.user.id !== "481895822624161795"){ |
| 132 | + interaction.reply({ content: ":lock: Sorry, DJ only is `enabled`, you can't do any music related commands.", ephemeral: true }); |
| 133 | + return; |
| 134 | + } |
| 135 | + |
| 136 | + interaction.reply({ content: ":arrow_forward: Song ``" + serverQueue["songs"][0]["title"] + "`` has been resumed.", ephemeral: false }); |
| 137 | + globalVars.audioPlayer.unpause(); |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + var percentage = Math.round((serverQueue.songs[0].timeleft/serverQueue.songs[0].length) * 15); |
| 142 | + |
| 143 | + var timebutton = "\\🔘"; |
| 144 | + var timebar = spliceSlice("▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬", percentage, 0, timebutton); |
| 145 | + |
| 146 | + var listening_platform_name = "REPORT TO MVDW"; |
| 147 | + var listening_platform_icon = ""; |
| 148 | + switch(serverQueue.songs[0].type){ |
| 149 | + case 0: |
| 150 | + listening_platform_name = "YouTube"; |
| 151 | + listening_platform_icon = "https://cdn.discordapp.com/attachments/834518897549508649/834713284627529748/youtube_play1600.png"; |
| 152 | + break; |
| 153 | + case 1: |
| 154 | + listening_platform_name = "Creo"; |
| 155 | + listening_platform_icon = "https://www.watchcreo.com/assets/images/favicon_new.png"; |
| 156 | + break; |
| 157 | + case 2: |
| 158 | + listening_platform_name = "SoundCloud"; |
| 159 | + listening_platform_icon = "https://cdn.discordapp.com/attachments/885543263111639061/942008394896781392/iu.png"; |
| 160 | + break; |
| 161 | + case 3: |
| 162 | + listening_platform_name = "uploaded file"; |
| 163 | + listening_platform_icon = "https://cdn.discordapp.com/attachments/885543263111639061/942014209816936448/folder.png"; |
| 164 | + break; |
| 165 | + } |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + const now_playing = new Discord.MessageEmbed() |
| 170 | + .setColor('#19d3c8') |
| 171 | + .setTitle(':arrow_forward: Now Playing:') |
| 172 | + .setDescription("__**" + serverQueue.songs[0].title + "**__\n" + |
| 173 | + "*By " + serverQueue.songs[0].author + "*\n\n" + |
| 174 | + timebar + "\n" + |
| 175 | + glofunc.toHHMMSS(serverQueue.songs[0].timeleft) + " / " + glofunc.toHHMMSS(serverQueue.songs[0].length) + "\n\n") |
| 176 | + .setThumbnail(serverQueue.songs[0].thumbnail) //youtube bugged |
| 177 | + .setFooter("Listen on " + listening_platform_name, listening_platform_icon); |
| 178 | + |
| 179 | + |
| 180 | + const button_row = new Discord.MessageActionRow(); |
| 181 | + const button_row2 = new Discord.MessageActionRow(); |
| 182 | + button_row.addComponents( |
| 183 | + new Discord.MessageButton() |
| 184 | + .setCustomId("music_pause") |
| 185 | + .setLabel('') |
| 186 | + .setStyle('PRIMARY') |
| 187 | + .setEmoji('⏸️') |
| 188 | + ); |
| 189 | + button_row.addComponents( |
| 190 | + new Discord.MessageButton() |
| 191 | + .setCustomId("music_skip") |
| 192 | + .setLabel('Skip') |
| 193 | + .setStyle('PRIMARY') |
| 194 | + .setEmoji('⏩') |
| 195 | + ); |
| 196 | + button_row.addComponents( |
| 197 | + new Discord.MessageButton() |
| 198 | + .setCustomId("music_loop") |
| 199 | + .setLabel('Loop') |
| 200 | + .setStyle('PRIMARY') |
| 201 | + .setEmoji('🔂') |
| 202 | + ); |
| 203 | + button_row2.addComponents( |
| 204 | + new Discord.MessageButton() |
| 205 | + .setLabel('Open Connect2Music') |
| 206 | + .setStyle('LINK') |
| 207 | + .setURL("https://www.enthix.net/connect2music") |
| 208 | + .setEmoji('🎵') |
| 209 | + .setDisabled(true) |
| 210 | + ); |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + interaction.message.edit({ embeds: [now_playing], components: [button_row, button_row2] }) |
| 216 | + |
| 217 | + |
| 218 | + } else if (interaction.customId === 'music_skip') { |
| 219 | + const serverQueue = globalVars.MusicQueue.get(interaction.guild.id); |
| 220 | + |
| 221 | + if (!serverQueue || serverQueue.songs.length == 0){ |
| 222 | + interaction.reply({ content: "There is nothing playing now.", ephemeral: true }); |
| 223 | + return; |
| 224 | + } |
| 225 | + |
| 226 | + if(globalVars.music_djonly && interaction.user.id !== "481895822624161795"){ |
| 227 | + interaction.reply({ content: ":lock: Sorry, DJ only is `enabled`, you can't do any music related commands.", ephemeral: true }); |
| 228 | + return; |
| 229 | + } |
| 230 | + |
| 231 | + |
| 232 | + var member_size_required = Math.round((serverQueue.voiceChannel.members.size - 1) / 2); |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | + if(globalVars.vote_skip_song.includes(interaction.user.id)){ |
| 237 | + interaction.reply({ content: ":no_entry_sign: You already voted. `" + globalVars.vote_skip_song.length + "/" + member_size_required + "`", ephemeral: true }); |
| 238 | + return; |
| 239 | + } |
| 240 | + globalVars.vote_skip_song.push(interaction.user.id); |
| 241 | + |
| 242 | + |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | + if(globalVars.vote_skip_song.length < member_size_required){ |
| 247 | + interaction.reply({ content: ":fast_forward: " + globalVars.vote_skip_song.length + "/" + member_size_required + " votes to skip."}); |
| 248 | + } else { |
| 249 | + if(globalVars.MusicLoop){ |
| 250 | + globalVars.MusicLoop = false; |
| 251 | + interaction.message.channel.send({ content: ":repeat_one: Loop removed."}); |
| 252 | + } |
| 253 | + |
| 254 | + interaction.reply({ content: ":track_next: Skipping song..."}); |
| 255 | + globalVars.audioPlayer.stop(); |
| 256 | + } |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | + |
| 261 | + } else if (interaction.customId === 'music_loop') { |
| 262 | + const serverQueue = globalVars.MusicQueue.get(interaction.guild.id); |
| 263 | + |
| 264 | + if (!serverQueue || serverQueue.songs.length == 0){ |
| 265 | + interaction.reply({ content: "There is nothing playing now.", ephemeral: true }); |
| 266 | + return; |
| 267 | + } |
| 268 | + |
| 269 | + if(globalVars.music_djonly && interaction.user.id !== "481895822624161795"){ |
| 270 | + interaction.reply({ content: ":lock: Sorry, DJ only is `enabled`, you can't do any music related commands.", ephemeral: true }); |
| 271 | + return; |
| 272 | + } |
| 273 | + |
| 274 | + |
| 275 | + |
| 276 | + if(globalVars.MusicLoop){ |
| 277 | + globalVars.MusicLoop = false; |
| 278 | + interaction.reply({ content: "Loop removed." }); |
| 279 | + } else { |
| 280 | + globalVars.MusicLoop = true; |
| 281 | + interaction.reply({ content: ":repeat_one: Song `" + serverQueue.songs[0].title + "` looped." }); |
| 282 | + } |
| 283 | + |
| 284 | + } |
| 285 | + |
| 286 | + }, |
| 287 | + ModuleType: "clickbutton" |
| 288 | + |
| 289 | +} |
0 commit comments