forked from embee/woomy
Merge branch 'next' of https://www.github.com/mudkipscience/woomy into next
This commit is contained in:
commit
7a3035e00b
6 changed files with 125 additions and 27 deletions
|
@ -20,33 +20,48 @@ exports.help = {
|
||||||
const { getGuild } = require('../utils/music')
|
const { getGuild } = require('../utils/music')
|
||||||
module.exports.run = (client, message, args, level) => {
|
module.exports.run = (client, message, args, level) => {
|
||||||
const queue = getGuild(message.guild.id).queue
|
const queue = getGuild(message.guild.id).queue
|
||||||
const oldPosition = +args[0]
|
|
||||||
const newPosition = +args[1]
|
|
||||||
const songName = queue[oldPosition].video.title
|
|
||||||
|
|
||||||
if (queue.length < 3) {
|
if (queue.length < 3) {
|
||||||
return message.channel.send('<:error:466995152976871434> Not enough songs are in the queue for this command to work!')
|
return message.channel.send('<:error:466995152976871434> Not enough songs are in the queue for this command to work!')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args[0]) {
|
if (!args[0]) {
|
||||||
return message.channel.send(`<:error:466995152976871434> You didn't tell me what song to move! Usage: \`${client.commands.get('removesong').help.usage}\``)
|
return client.userError(message, exports, 'Missing argument, the `current position` argument is required!')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args[1]) {
|
if (!args[1]) {
|
||||||
return message.channel.send(`<:error:466995152976871434> You didn't tell me what position in the queue you want to move this song to! Usage: \`${client.commands.get('removesong').help.usage}\``)
|
return client.userError(message, exports, 'Missing argument, the `new position` argument is required!')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNaN(oldPosition) === true || isNaN(newPosition) === true) {
|
const oldPosition = +args[0]
|
||||||
|
const newPosition = +args[1]
|
||||||
|
|
||||||
|
if (isNaN(oldPosition) === true) {
|
||||||
return message.channel.send('That isn\'t a number! You need to tell me the songs position in the queue (1, 2, etc.)')
|
return message.channel.send('That isn\'t a number! You need to tell me the songs position in the queue (1, 2, etc.)')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNaN(newPosition) === true) {
|
||||||
|
return message.channel.send('That isn\'t a number! You need to tell me the songs position in the queue (1, 2, etc.)')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldPosition < 1) {
|
||||||
|
return message.channel.send('This number is too low!')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPosition < 1) {
|
||||||
|
return message.channel.send('This number is too low!')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldPosition >= queue.length) {
|
||||||
|
return message.channel.send('This number is too high!')
|
||||||
|
}
|
||||||
|
|
||||||
if (newPosition >= queue.length) {
|
if (newPosition >= queue.length) {
|
||||||
var k = newPosition - queue.length + 1
|
return message.channel.send('This number is too high!')
|
||||||
while (k--) {
|
|
||||||
queue.push(undefined)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const songName = queue[oldPosition].video.title
|
||||||
|
|
||||||
queue.splice(newPosition, 0, queue.splice(oldPosition, 1)[0])
|
queue.splice(newPosition, 0, queue.splice(oldPosition, 1)[0])
|
||||||
|
|
||||||
message.channel.send(`Moved **${songName}** from position \`${oldPosition}\` to \`${newPosition}\``)
|
message.channel.send(`Moved **${songName}** from position \`${oldPosition}\` to \`${newPosition}\``)
|
||||||
|
|
32
commands/reload.js
Normal file
32
commands/reload.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
exports.conf = {
|
||||||
|
enabled: true,
|
||||||
|
guildOnly: false,
|
||||||
|
aliases: [],
|
||||||
|
permLevel: 'Developer',
|
||||||
|
requiredPerms: [],
|
||||||
|
cooldown: 2000
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.help = {
|
||||||
|
name: 'reload',
|
||||||
|
category: 'Developer',
|
||||||
|
description: 'Reloads a command without having to restart the whole bot.',
|
||||||
|
usage: 'reload [command]',
|
||||||
|
parameters: '[command] - command you want to reload'
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.run = async (client, message, args) => { // eslint-disable-line no-unused-vars
|
||||||
|
if (!args || args.length < 1) {
|
||||||
|
return message.channel.send(
|
||||||
|
`<:error:466995152976871434> You must provide a command to reload! Usage: \`${client.commands.get('reload').help.usage}\``
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = await client.unloadCommand(args[0])
|
||||||
|
if (response) return message.channel.send(`<:error:466995152976871434> Error unloading: ${response}`)
|
||||||
|
|
||||||
|
response = client.loadCommand(args[0])
|
||||||
|
if (response) return message.channel.send(`<:error:466995152976871434> Error loading: ${response}`)
|
||||||
|
|
||||||
|
message.channel.send(`<:success:466995111885144095> \`${args[0]}\` has been reloaded!`)
|
||||||
|
}
|
|
@ -25,16 +25,13 @@ module.exports.run = (client, message, args, level) => {
|
||||||
return message.channel.send('Not enough songs are in the queue for this command to work!')
|
return message.channel.send('Not enough songs are in the queue for this command to work!')
|
||||||
}
|
}
|
||||||
|
|
||||||
let j, x, i
|
const max = queue.length - 1
|
||||||
|
const min = 1
|
||||||
for (i = queue.length - 1; i > 0; i--) {
|
for (let i = max; i >= min; i--) {
|
||||||
if (i > 1) {
|
const randomIndex = Math.floor(Math.random() * (max - min + 1)) + min
|
||||||
console.log(i)
|
const itemAtIndex = queue[randomIndex]
|
||||||
j = Math.floor(Math.random() * (i + 1))
|
queue[randomIndex] = queue[i]
|
||||||
x = queue[i]
|
queue[i] = itemAtIndex
|
||||||
queue[i] = queue[j]
|
|
||||||
queue[j] = x
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message.channel.send('Queue shuffled!')
|
message.channel.send('Queue shuffled!')
|
||||||
|
|
|
@ -24,11 +24,12 @@ exports.run = async (client, message) => {
|
||||||
if (guild.queue.length < 1 || !guild.playing || !guild.dispatcher) return message.channel.send('Nothing is playing.')
|
if (guild.queue.length < 1 || !guild.playing || !guild.dispatcher) return message.channel.send('Nothing is playing.')
|
||||||
if (!message.member.voice.channel) return message.channel.send('You need to be in voice channel to use this command!')
|
if (!message.member.voice.channel) return message.channel.send('You need to be in voice channel to use this command!')
|
||||||
|
|
||||||
|
guild.dispatcher.end('silent')
|
||||||
|
|
||||||
|
guild.queue = []
|
||||||
guild.playing = false
|
guild.playing = false
|
||||||
guild.paused = false
|
guild.paused = false
|
||||||
guild.queue = []
|
guild.skippers = []
|
||||||
|
|
||||||
guild.dispatcher.end('silent')
|
|
||||||
|
|
||||||
message.channel.send('Playback stopped!')
|
message.channel.send('Playback stopped!')
|
||||||
}
|
}
|
||||||
|
|
48
events/voiceStateUpdate.js
Normal file
48
events/voiceStateUpdate.js
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
// Copyright 2020 Emily J. / mudkipscience and contributors. Subject to the AGPLv3 license.
|
||||||
|
|
||||||
|
const music = require('../utils/music')
|
||||||
|
|
||||||
|
module.exports = (client, oldState, newState) => {
|
||||||
|
if (newState.channelID !== oldState.channelID) {
|
||||||
|
const guild = music.getGuild(newState.guild.id)
|
||||||
|
|
||||||
|
// Reset queue, dispatcher, etc if Woomy is forcibly disconnected from the queue
|
||||||
|
if (!guild.voiceChannel.members.get(client.user.id) && guild.queue.length > 0) {
|
||||||
|
guild.queue = []
|
||||||
|
guild.playing = false
|
||||||
|
guild.paused = false
|
||||||
|
guild.skippers = []
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-disconnect feature
|
||||||
|
if (guild.playing && guild.voiceChannel.id === oldState.channelID) {
|
||||||
|
if (guild.voiceChannel.members.filter(member => !member.user.bot).size < 1) {
|
||||||
|
guild.autoDisconnect = true
|
||||||
|
|
||||||
|
guild.message.channel.send(`The music will end in 2 minutes if nobody rejoins **${guild.voiceChannel.name}**`)
|
||||||
|
.then(msg => {
|
||||||
|
msg.delete({ timeout: 120000 })
|
||||||
|
})
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (guild.dispatcher !== null && guild.voiceChannel.members.filter(member => !member.user.bot).size < 1 && guild.autoDisconnect) {
|
||||||
|
// Probably should be async? But no need here I think
|
||||||
|
guild.dispatcher.end('silent')
|
||||||
|
|
||||||
|
guild.queue = []
|
||||||
|
guild.playing = false
|
||||||
|
guild.paused = false
|
||||||
|
guild.dispatcher = null
|
||||||
|
guild.skippers = []
|
||||||
|
|
||||||
|
guild.message.channel.send('The music has ended because no one was listening to me ;~;')
|
||||||
|
} else {
|
||||||
|
guild.autoDisconnect = false
|
||||||
|
}
|
||||||
|
}, 120000)
|
||||||
|
} else {
|
||||||
|
guild.autoDisconnect = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -66,6 +66,7 @@ exports.getVideoByQuery = async function (client, query) {
|
||||||
|
|
||||||
exports.play = async function (client, message, query, ignoreQueue) {
|
exports.play = async function (client, message, query, ignoreQueue) {
|
||||||
const guild = exports.getGuild(message.guild.id)
|
const guild = exports.getGuild(message.guild.id)
|
||||||
|
guild.message = message
|
||||||
|
|
||||||
if (!message.member.voice.channel && !guild.voiceChannel) {
|
if (!message.member.voice.channel && !guild.voiceChannel) {
|
||||||
return message.reply('You have to be connected to a voice channel to use this command!')
|
return message.reply('You have to be connected to a voice channel to use this command!')
|
||||||
|
@ -92,8 +93,10 @@ exports.play = async function (client, message, query, ignoreQueue) {
|
||||||
// Fix the bot if somehow broken
|
// Fix the bot if somehow broken
|
||||||
// music "playing", nothing in queue
|
// music "playing", nothing in queue
|
||||||
if ((guild.playing || guild.dispatcher) && guild.queue.length === 0) {
|
if ((guild.playing || guild.dispatcher) && guild.queue.length === 0) {
|
||||||
|
guild.queue = []
|
||||||
guild.playing = false
|
guild.playing = false
|
||||||
guild.dispatcher = null
|
guild.paused = false
|
||||||
|
guild.skippers = []
|
||||||
// music not playing, something is in queue
|
// music not playing, something is in queue
|
||||||
} else if (!guild.playing && !guild.dispatcher && guild.queue.length > 0) {
|
} else if (!guild.playing && !guild.dispatcher && guild.queue.length > 0) {
|
||||||
guild.queue = []
|
guild.queue = []
|
||||||
|
@ -169,7 +172,6 @@ exports.play = async function (client, message, query, ignoreQueue) {
|
||||||
guild.playing = true
|
guild.playing = true
|
||||||
|
|
||||||
guild.voiceChannel = vc
|
guild.voiceChannel = vc
|
||||||
console.log(vc)
|
|
||||||
|
|
||||||
const connection = await vc.join()
|
const connection = await vc.join()
|
||||||
|
|
||||||
|
@ -188,7 +190,10 @@ exports.play = async function (client, message, query, ignoreQueue) {
|
||||||
if (guild.queue.length > 0) {
|
if (guild.queue.length > 0) {
|
||||||
exports.play(client, message, null, true)
|
exports.play(client, message, null, true)
|
||||||
} else {
|
} else {
|
||||||
guild.dispatcher = null
|
guild.queue = []
|
||||||
|
guild.playing = false
|
||||||
|
guild.paused = false
|
||||||
|
guild.skippers = []
|
||||||
|
|
||||||
connection.disconnect()
|
connection.disconnect()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue