changed music up

This commit is contained in:
Emily 2020-04-19 20:10:52 +10:00
parent 93926545ae
commit 4ff85905ff
5 changed files with 197 additions and 197 deletions

View File

@ -15,8 +15,9 @@ exports.help = {
params: ''
}
const { skip } = require('../utils/music')
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')
}

View File

@ -15,6 +15,7 @@ exports.help = {
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) => {
await client.music.play(message, args.join(' '))
await play(client, message, args.join(' '))
}

View File

@ -15,6 +15,7 @@ exports.help = {
parameters: '[volume] - Target volume from 0-100%'
}
const { setVolume } = require('../utils/music')
exports.run = async (client, message, args, level, data) => {
let vol = args[0]
@ -24,7 +25,7 @@ exports.run = async (client, message, args, level, data) => {
vol = vol / 100 * 0.5
if (vol <= 1) {
client.music.setVolume(message.guild, vol)
setVolume(message.guild, vol)
message.reply('set volume to ' + vol * 100 + '%')
}

View File

@ -27,7 +27,6 @@ client.version = require('./version.json')
client.db = require('./utils/mongoose')
client.logger = require('./utils/logger')
require('./utils/_functions')(client)
require('./utils/music')(client)
// Check if Woomy is running inside a Docker container
if (isDocker() === true) {

View File

@ -3,10 +3,9 @@ const fetch = require('node-fetch')
const { MessageEmbed } = require('discord.js')
const { utc } = require('moment')
module.exports = client => {
client.music = { guilds: {} }
exports.queue = {}
client.createTimestamp = function (s) {
exports.createTimestamp = function (s) {
if (s >= 3600) {
return utc(s * 1000).format('HH:mm:ss')
} else {
@ -14,8 +13,8 @@ module.exports = client => {
}
}
client.music.getGuild = function (id) {
let guild = client.music.guilds[id]
exports.getGuild = function (id) {
let guild = exports.queue[id]
if (!guild) {
guild = {}
@ -24,27 +23,27 @@ module.exports = client => {
guild.playing = false
guild.queue = []
client.music.guilds[id] = guild
exports.queue[id] = guild
}
return guild
}
client.music.getLinkFromID = function (id) {
exports.getLinkFromID = function (id) {
return 'https://www.youtube.com/watch?v=' + id
}
client.music.getVideoByQuery = async query => {
let resp
exports.getVideoByQuery = async query => {
let res
try {
const id = await ytdl.getURLVideoID(query)
resp = await fetch('https://invidious.snopyta.org/api/v1/videos/' + id)
res = 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))
res = await fetch('https://invidious.snopyta.org/api/v1/search?q=' + encodeURIComponent(query))
}
const parsed = await resp.json()
const parsed = await res.json()
if (parsed) {
const videos = parsed
@ -59,8 +58,8 @@ module.exports = client => {
}
}
client.music.play = async function (message, query, ignoreQueue) {
const guild = client.music.getGuild(message.guild.id)
exports.play = async function (client, message, query, ignoreQueue) {
const guild = exports.getGuild(message.guild.id)
if (!message.member.voice.channel && !guild.voiceChannel) {
return message.reply('You have to be connected to a voice channel to use this command!')
@ -72,7 +71,7 @@ module.exports = client => {
let videos
if (!ignoreQueue) {
videos = await client.music.getVideoByQuery(query)
videos = await exports.getVideoByQuery(query)
if (!videos[1]) {
if (!videos[0]) {
video = videos
@ -99,7 +98,7 @@ module.exports = client => {
let i = 0
for (i = 0; i < 5; i++) {
if (!videos[i]) break
output += `\`${i + 1}:\` **[${videos[i].title}](https://www.youtube.com/watch?v=${videos[i].videoId})** \`[${client.createTimestamp(videos[i].lengthSeconds)}]\`\n`
output += `\`${i + 1}:\` **[${videos[i].title}](https://www.youtube.com/watch?v=${videos[i].videoId})** \`[${exports.createTimestamp(videos[i].lengthSeconds)}]\`\n`
}
const embed = new MessageEmbed()
@ -169,7 +168,7 @@ module.exports = client => {
const v = guild.queue[0]
guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.videoId), { highWaterMark: 1024 * 1024 * 32 }), { type: 'opus' })
guild.dispatcher = connection.play(await ytdl(exports.getLinkFromID(v.video.videoId), { highWaterMark: 1024 * 1024 * 32 }), { type: 'opus' })
guild.dispatcher.setVolume(0.25)
message.channel.send('Playing **' + v.video.title + '**')
@ -180,7 +179,7 @@ module.exports = client => {
guild.playing = false
if (guild.queue.length > 0) {
client.music.play(message, null, true)
exports.play(message, null, true)
} else {
guild.dispatcher = null
@ -193,19 +192,18 @@ module.exports = client => {
}
}
client.music.setVolume = function (guild, target) {
const g = client.music.getGuild(guild.id)
exports.setVolume = function (guild, 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)
exports.skip = function (guild, reason) {
const g = exports.getGuild(guild.id)
if (g.dispatcher) {
g.dispatcher.end(reason)
}
}
}