changed music up
This commit is contained in:
parent
93926545ae
commit
4ff85905ff
5 changed files with 197 additions and 197 deletions
|
@ -15,8 +15,9 @@ exports.help = {
|
||||||
params: ''
|
params: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { skip } = require('../utils/music')
|
||||||
exports.run = async (client, message, args, level, data) => {
|
exports.run = async (client, message, args, level, data) => {
|
||||||
client.music.skip(message.guild, 'forceskip');
|
skip(message.guild, 'forceskip')
|
||||||
|
|
||||||
message.reply('skipped currently playing music');
|
message.reply('skipped currently playing music')
|
||||||
};
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ exports.help = {
|
||||||
parameters: '[query] - A query to find video by or a link to the video.'
|
parameters: '[query] - A query to find video by or a link to the video.'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { play } = require('../utils/music')
|
||||||
exports.run = async (client, message, args, level, data) => {
|
exports.run = async (client, message, args, level, data) => {
|
||||||
await client.music.play(message, args.join(' '))
|
await play(client, message, args.join(' '))
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ exports.help = {
|
||||||
parameters: '[volume] - Target volume from 0-100%'
|
parameters: '[volume] - Target volume from 0-100%'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { setVolume } = require('../utils/music')
|
||||||
exports.run = async (client, message, args, level, data) => {
|
exports.run = async (client, message, args, level, data) => {
|
||||||
let vol = args[0]
|
let vol = args[0]
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ exports.run = async (client, message, args, level, data) => {
|
||||||
vol = vol / 100 * 0.5
|
vol = vol / 100 * 0.5
|
||||||
|
|
||||||
if (vol <= 1) {
|
if (vol <= 1) {
|
||||||
client.music.setVolume(message.guild, vol)
|
setVolume(message.guild, vol)
|
||||||
|
|
||||||
message.reply('set volume to ' + vol * 100 + '%')
|
message.reply('set volume to ' + vol * 100 + '%')
|
||||||
}
|
}
|
||||||
|
|
1
index.js
1
index.js
|
@ -27,7 +27,6 @@ client.version = require('./version.json')
|
||||||
client.db = require('./utils/mongoose')
|
client.db = require('./utils/mongoose')
|
||||||
client.logger = require('./utils/logger')
|
client.logger = require('./utils/logger')
|
||||||
require('./utils/_functions')(client)
|
require('./utils/_functions')(client)
|
||||||
require('./utils/music')(client)
|
|
||||||
|
|
||||||
// Check if Woomy is running inside a Docker container
|
// Check if Woomy is running inside a Docker container
|
||||||
if (isDocker() === true) {
|
if (isDocker() === true) {
|
||||||
|
|
380
utils/music.js
380
utils/music.js
|
@ -3,209 +3,207 @@ const fetch = require('node-fetch')
|
||||||
const { MessageEmbed } = require('discord.js')
|
const { MessageEmbed } = require('discord.js')
|
||||||
const { utc } = require('moment')
|
const { utc } = require('moment')
|
||||||
|
|
||||||
module.exports = client => {
|
exports.queue = {}
|
||||||
client.music = { guilds: {} }
|
|
||||||
|
|
||||||
client.createTimestamp = function (s) {
|
exports.createTimestamp = function (s) {
|
||||||
if (s >= 3600) {
|
if (s >= 3600) {
|
||||||
return utc(s * 1000).format('HH:mm:ss')
|
return utc(s * 1000).format('HH:mm:ss')
|
||||||
} else {
|
} else {
|
||||||
return utc(s * 1000).format('mm:ss')
|
return utc(s * 1000).format('mm:ss')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getGuild = function (id) {
|
||||||
|
let guild = exports.queue[id]
|
||||||
|
|
||||||
|
if (!guild) {
|
||||||
|
guild = {}
|
||||||
|
|
||||||
|
guild.dispatcher = null
|
||||||
|
guild.playing = false
|
||||||
|
guild.queue = []
|
||||||
|
|
||||||
|
exports.queue[id] = guild
|
||||||
}
|
}
|
||||||
|
|
||||||
client.music.getGuild = function (id) {
|
return guild
|
||||||
let guild = client.music.guilds[id]
|
}
|
||||||
|
|
||||||
if (!guild) {
|
exports.getLinkFromID = function (id) {
|
||||||
guild = {}
|
return 'https://www.youtube.com/watch?v=' + id
|
||||||
|
}
|
||||||
|
|
||||||
guild.dispatcher = null
|
exports.getVideoByQuery = async query => {
|
||||||
guild.playing = false
|
let res
|
||||||
guild.queue = []
|
|
||||||
|
|
||||||
client.music.guilds[id] = guild
|
try {
|
||||||
}
|
const id = await ytdl.getURLVideoID(query)
|
||||||
|
res = await fetch('https://invidious.snopyta.org/api/v1/videos/' + id)
|
||||||
return guild
|
} catch (err) {
|
||||||
|
res = await fetch('https://invidious.snopyta.org/api/v1/search?q=' + encodeURIComponent(query))
|
||||||
}
|
}
|
||||||
|
|
||||||
client.music.getLinkFromID = function (id) {
|
const parsed = await res.json()
|
||||||
return 'https://www.youtube.com/watch?v=' + id
|
|
||||||
}
|
|
||||||
|
|
||||||
client.music.getVideoByQuery = async query => {
|
if (parsed) {
|
||||||
let resp
|
const videos = parsed
|
||||||
|
|
||||||
try {
|
if (videos) {
|
||||||
const id = await ytdl.getURLVideoID(query)
|
return videos
|
||||||
resp = await fetch('https://invidious.snopyta.org/api/v1/videos/' + id)
|
|
||||||
} catch (err) {
|
|
||||||
resp = await fetch('https://invidious.snopyta.org/api/v1/search?q=' + encodeURIComponent(query))
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsed = await resp.json()
|
|
||||||
|
|
||||||
if (parsed) {
|
|
||||||
const videos = parsed
|
|
||||||
|
|
||||||
if (videos) {
|
|
||||||
return videos
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
return false
|
||||||
client.music.play = async function (message, query, ignoreQueue) {
|
}
|
||||||
const guild = client.music.getGuild(message.guild.id)
|
}
|
||||||
|
|
||||||
if (!message.member.voice.channel && !guild.voiceChannel) {
|
exports.play = async function (client, message, query, ignoreQueue) {
|
||||||
return message.reply('You have to be connected to a voice channel to use this command!')
|
const guild = exports.getGuild(message.guild.id)
|
||||||
}
|
|
||||||
|
if (!message.member.voice.channel && !guild.voiceChannel) {
|
||||||
const vc = message.member.voice.channel
|
return message.reply('You have to be connected to a voice channel to use this command!')
|
||||||
|
}
|
||||||
let video
|
|
||||||
let videos
|
const vc = message.member.voice.channel
|
||||||
|
|
||||||
if (!ignoreQueue) {
|
let video
|
||||||
videos = await client.music.getVideoByQuery(query)
|
let videos
|
||||||
if (!videos[1]) {
|
|
||||||
if (!videos[0]) {
|
if (!ignoreQueue) {
|
||||||
video = videos
|
videos = await exports.getVideoByQuery(query)
|
||||||
} else {
|
if (!videos[1]) {
|
||||||
video = videos[0]
|
if (!videos[0]) {
|
||||||
}
|
video = videos
|
||||||
}
|
} else {
|
||||||
}
|
video = videos[0]
|
||||||
|
}
|
||||||
if (videos || ignoreQueue) {
|
}
|
||||||
if (!ignoreQueue) {
|
}
|
||||||
// Fix the bot if somehow broken
|
|
||||||
// music "playing", nothing in queue
|
if (videos || ignoreQueue) {
|
||||||
if ((guild.playing || guild.dispatcher) && guild.queue.length === 0) {
|
if (!ignoreQueue) {
|
||||||
guild.playing = false
|
// Fix the bot if somehow broken
|
||||||
guild.dispatcher = null
|
// music "playing", nothing in queue
|
||||||
// music not playing, something is in queue
|
if ((guild.playing || guild.dispatcher) && guild.queue.length === 0) {
|
||||||
} else if (!guild.playing && !guild.dispatcher && guild.queue.length > 0) {
|
guild.playing = false
|
||||||
guild.queue = []
|
guild.dispatcher = null
|
||||||
}
|
// music not playing, something is in queue
|
||||||
|
} else if (!guild.playing && !guild.dispatcher && guild.queue.length > 0) {
|
||||||
if (!video) {
|
guild.queue = []
|
||||||
let output = ''
|
}
|
||||||
let i = 0
|
|
||||||
for (i = 0; i < 5; i++) {
|
if (!video) {
|
||||||
if (!videos[i]) break
|
let output = ''
|
||||||
output += `\`${i + 1}:\` **[${videos[i].title}](https://www.youtube.com/watch?v=${videos[i].videoId})** \`[${client.createTimestamp(videos[i].lengthSeconds)}]\`\n`
|
let i = 0
|
||||||
}
|
for (i = 0; i < 5; i++) {
|
||||||
|
if (!videos[i]) break
|
||||||
const embed = new MessageEmbed()
|
output += `\`${i + 1}:\` **[${videos[i].title}](https://www.youtube.com/watch?v=${videos[i].videoId})** \`[${exports.createTimestamp(videos[i].lengthSeconds)}]\`\n`
|
||||||
embed.setTitle('Please reply with a number `1-' + i + '` to select which song you want to add to the queue.')
|
}
|
||||||
embed.setColor(client.embedColour(message.guild))
|
|
||||||
embed.setDescription(output)
|
const embed = new MessageEmbed()
|
||||||
|
embed.setTitle('Please reply with a number `1-' + i + '` to select which song you want to add to the queue.')
|
||||||
let selection = await client.awaitReply(message, embed)
|
embed.setColor(client.embedColour(message.guild))
|
||||||
selection = Number(selection)
|
embed.setDescription(output)
|
||||||
|
|
||||||
switch (selection) {
|
let selection = await client.awaitReply(message, embed)
|
||||||
case 1:
|
selection = Number(selection)
|
||||||
video = videos[0]
|
|
||||||
break
|
switch (selection) {
|
||||||
case 2:
|
case 1:
|
||||||
if (videos[1]) {
|
video = videos[0]
|
||||||
video = videos[1]
|
break
|
||||||
} else {
|
case 2:
|
||||||
return message.channel.send('Invalid choice.')
|
if (videos[1]) {
|
||||||
}
|
video = videos[1]
|
||||||
break
|
} else {
|
||||||
case 3:
|
return message.channel.send('Invalid choice.')
|
||||||
if (videos[2]) {
|
}
|
||||||
video = videos[2]
|
break
|
||||||
} else {
|
case 3:
|
||||||
return message.channel.send('Invalid choice.')
|
if (videos[2]) {
|
||||||
}
|
video = videos[2]
|
||||||
break
|
} else {
|
||||||
case 4:
|
return message.channel.send('Invalid choice.')
|
||||||
if (videos[3]) {
|
}
|
||||||
video = videos[3]
|
break
|
||||||
} else {
|
case 4:
|
||||||
return message.channel.send('Invalid choice.')
|
if (videos[3]) {
|
||||||
}
|
video = videos[3]
|
||||||
break
|
} else {
|
||||||
case 5:
|
return message.channel.send('Invalid choice.')
|
||||||
if (videos[4]) {
|
}
|
||||||
video = videos[4]
|
break
|
||||||
} else {
|
case 5:
|
||||||
return message.channel.send('Invalid choice.')
|
if (videos[4]) {
|
||||||
}
|
video = videos[4]
|
||||||
break
|
} else {
|
||||||
default:
|
return message.channel.send('Invalid choice.')
|
||||||
return message.channel.send('Invalid choice.')
|
}
|
||||||
}
|
break
|
||||||
}
|
default:
|
||||||
|
return message.channel.send('Invalid choice.')
|
||||||
if (!video && videos[0]) {
|
}
|
||||||
video = videos[0]
|
}
|
||||||
} else if (!video) {
|
|
||||||
video = videos
|
if (!video && videos[0]) {
|
||||||
}
|
video = videos[0]
|
||||||
|
} else if (!video) {
|
||||||
// Add video to queue
|
video = videos
|
||||||
guild.queue.push({ video: video, requestedBy: message.member.id })
|
}
|
||||||
}
|
|
||||||
|
// Add video to queue
|
||||||
// Figure out if the bot should add it to queue or play it right now
|
guild.queue.push({ video: video, requestedBy: message.member.id })
|
||||||
if (guild.playing) {
|
}
|
||||||
message.reply('added **' + video.title + '** to the queue')
|
|
||||||
} else {
|
// Figure out if the bot should add it to queue or play it right now
|
||||||
guild.playing = true
|
if (guild.playing) {
|
||||||
|
message.reply('added **' + video.title + '** to the queue')
|
||||||
guild.voiceChannel = vc
|
} else {
|
||||||
|
guild.playing = true
|
||||||
const connection = await vc.join()
|
|
||||||
|
guild.voiceChannel = vc
|
||||||
const v = guild.queue[0]
|
|
||||||
|
const connection = await vc.join()
|
||||||
guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.videoId), { highWaterMark: 1024 * 1024 * 32 }), { type: 'opus' })
|
|
||||||
guild.dispatcher.setVolume(0.25)
|
const v = guild.queue[0]
|
||||||
|
|
||||||
message.channel.send('Playing **' + v.video.title + '**')
|
guild.dispatcher = connection.play(await ytdl(exports.getLinkFromID(v.video.videoId), { highWaterMark: 1024 * 1024 * 32 }), { type: 'opus' })
|
||||||
|
guild.dispatcher.setVolume(0.25)
|
||||||
// play next in queue on end
|
|
||||||
guild.dispatcher.once('finish', () => {
|
message.channel.send('Playing **' + v.video.title + '**')
|
||||||
guild.queue.shift()
|
|
||||||
guild.playing = false
|
// play next in queue on end
|
||||||
|
guild.dispatcher.once('finish', () => {
|
||||||
if (guild.queue.length > 0) {
|
guild.queue.shift()
|
||||||
client.music.play(message, null, true)
|
guild.playing = false
|
||||||
} else {
|
|
||||||
guild.dispatcher = null
|
if (guild.queue.length > 0) {
|
||||||
|
exports.play(message, null, true)
|
||||||
connection.disconnect()
|
} else {
|
||||||
}
|
guild.dispatcher = null
|
||||||
})
|
|
||||||
}
|
connection.disconnect()
|
||||||
} else {
|
}
|
||||||
return message.reply('failed to find the video!')
|
})
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
return message.reply('failed to find the video!')
|
||||||
client.music.setVolume = function (guild, target) {
|
}
|
||||||
const g = client.music.getGuild(guild.id)
|
}
|
||||||
|
|
||||||
if (g.dispatcher) {
|
exports.setVolume = function (guild, target) {
|
||||||
g.dispatcher.setVolume(target)
|
const g = exports.getGuild(guild.id)
|
||||||
}
|
|
||||||
}
|
if (g.dispatcher) {
|
||||||
|
g.dispatcher.setVolume(target)
|
||||||
client.music.skip = function (guild, reason) {
|
}
|
||||||
const g = client.music.getGuild(guild.id)
|
}
|
||||||
|
|
||||||
if (g.dispatcher) {
|
exports.skip = function (guild, reason) {
|
||||||
g.dispatcher.end(reason)
|
const g = exports.getGuild(guild.id)
|
||||||
}
|
|
||||||
|
if (g.dispatcher) {
|
||||||
|
g.dispatcher.end(reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue