fix code format
This commit is contained in:
parent
a067c957c1
commit
9fd2c873ca
5 changed files with 136 additions and 144 deletions
|
@ -4,8 +4,7 @@ exports.conf = {
|
|||
aliases: [],
|
||||
permLevel: 'User',
|
||||
requiredPerms: [],
|
||||
cooldown: 2000,
|
||||
joinArguments: 1
|
||||
cooldown: 2000
|
||||
}
|
||||
|
||||
exports.help = {
|
||||
|
@ -16,6 +15,6 @@ exports.help = {
|
|||
parameters: '[query] - A query to find video by or a link to the video.'
|
||||
}
|
||||
|
||||
exports.run = async (client, message, args, level, data) => {
|
||||
await client.music.play(message, args[0]);
|
||||
};
|
||||
exports.run = async (client, message, [...args], level, data) => {
|
||||
await client.music.play(message, args)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
exports.conf = {
|
||||
enabled: true,
|
||||
guildOnly: true,
|
||||
aliases: [],
|
||||
aliases: ['vol'],
|
||||
permLevel: 'Moderator',
|
||||
requiredPerms: ['vol'],
|
||||
requiredPerms: [],
|
||||
cooldown: 2000
|
||||
}
|
||||
|
||||
|
@ -16,17 +16,17 @@ exports.help = {
|
|||
}
|
||||
|
||||
exports.run = async (client, message, args, level, data) => {
|
||||
let vol = args[0];
|
||||
let vol = args[0]
|
||||
|
||||
if(vol) {
|
||||
vol = Number(vol);
|
||||
if (vol) {
|
||||
vol = Number(vol)
|
||||
|
||||
vol = vol / 100 * 0.5;
|
||||
vol = vol / 100 * 0.5
|
||||
|
||||
if(vol <= 1) {
|
||||
client.music.setVolume(message.guild, vol);
|
||||
if (vol <= 1) {
|
||||
client.music.setVolume(message.guild, vol)
|
||||
|
||||
message.reply('set volume to ' + vol * 100 + '%');
|
||||
};
|
||||
};
|
||||
};
|
||||
message.reply('set volume to ' + vol * 100 + '%')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,15 +106,6 @@ module.exports = async (client, message) => {
|
|||
message.flags.push(args.shift().slice(1))
|
||||
}
|
||||
|
||||
let argsPossiblyJoined = args;
|
||||
|
||||
if(cmd.conf.joinArguments) {
|
||||
if(args.length > cmd.conf.joinArguments && args.length > 1)
|
||||
{
|
||||
argsPossiblyJoined[cmd.conf.joinArguments - 1] = args.slice(cmd.conf.joinArguments - 1).join(' ');
|
||||
}
|
||||
};
|
||||
|
||||
client.logger.log(`Command ran: ${cmd.help.name}`)
|
||||
cmd.run(client, message, argsPossiblyJoined, level, data)
|
||||
cmd.run(client, message, args, level, data)
|
||||
}
|
||||
|
|
216
helpers/music.js
216
helpers/music.js
|
@ -1,8 +1,8 @@
|
|||
const ytdl = require('ytdl-core-discord');
|
||||
const fetch = require('node-fetch');
|
||||
const ytdl = require('ytdl-core-discord')
|
||||
const fetch = require('node-fetch')
|
||||
|
||||
module.exports = client => {
|
||||
client.music = {guilds: {}};
|
||||
client.music = { guilds: {} }
|
||||
|
||||
// MUSIC - TIMESTAMP
|
||||
client.createTimestamp = function (duration) {
|
||||
|
@ -30,137 +30,137 @@ module.exports = client => {
|
|||
return time
|
||||
}
|
||||
|
||||
client.music.getGuild = function(id) {
|
||||
let guild = client.music.guilds[id];
|
||||
client.music.getGuild = function (id) {
|
||||
let guild = client.music.guilds[id]
|
||||
|
||||
if(!guild) {
|
||||
guild = {};
|
||||
if (!guild) {
|
||||
guild = {}
|
||||
|
||||
guild.dispatcher = null;
|
||||
guild.playing = false;
|
||||
guild.queue = [];
|
||||
guild.dispatcher = null
|
||||
guild.playing = false
|
||||
guild.queue = []
|
||||
|
||||
client.music.guilds[id] = guild;
|
||||
};
|
||||
|
||||
return guild;
|
||||
};
|
||||
|
||||
client.music.isYouTubeLink = function(query) {
|
||||
return query.startsWith('https://youtube.com/') || query.startsWith('http://youtube.com/') || query.startsWith('https://youtu.be/') || query.startsWith('http://youtu.be/') || query.startsWith('https://m.youtube.com/') || query.startsWith('http://m.youtube.com/') || query.startsWith('https://www.youtube.com/') || query.startsWith('http://www.youtube.com/');
|
||||
};
|
||||
|
||||
client.music.getLinkFromID = function(id) {
|
||||
return 'https://www.youtube.com/watch?v=' + id;
|
||||
};
|
||||
|
||||
client.music.getVideoByQuery = async function(query) {
|
||||
let isLink = client.music.isYouTubeLink(query);
|
||||
|
||||
let response;
|
||||
|
||||
if(isLink) {
|
||||
response = await fetch('https://www.googleapis.com/youtube/v3/search?key=' + client.config.keys.yt + '&part=id,snippet&maxResults=1&type=video&id=' + id);
|
||||
} else {
|
||||
// TODO: replace this workaround
|
||||
response = await fetch('https://www.googleapis.com/youtube/v3/search?key=' + client.config.keys.yt + '&part=id,snippet&maxResults=1&type=video&q=**' + encodeURIComponent(query) + '**');
|
||||
};
|
||||
|
||||
let parsed = await response.json();
|
||||
|
||||
if(parsed.items) {
|
||||
let video = parsed.items[0];
|
||||
|
||||
if(video) {
|
||||
return video;
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
client.music.play = async function(message, query, ignoreQueue) {
|
||||
let guild = client.music.getGuild(message.guild.id);
|
||||
|
||||
if(!message.member.voice.channel && !guild.voiceChannel) {
|
||||
return message.reply('you are not in a voice channel!');
|
||||
client.music.guilds[id] = guild
|
||||
}
|
||||
|
||||
let vc = message.member.voice.channel;
|
||||
return guild
|
||||
}
|
||||
|
||||
let video;
|
||||
|
||||
if(!ignoreQueue) {
|
||||
video = await client.music.getVideoByQuery(query);
|
||||
};
|
||||
client.music.isYouTubeLink = function (query) {
|
||||
return query.startsWith('https://youtube.com/') || query.startsWith('http://youtube.com/') || query.startsWith('https://youtu.be/') || query.startsWith('http://youtu.be/') || query.startsWith('https://m.youtube.com/') || query.startsWith('http://m.youtube.com/') || query.startsWith('https://www.youtube.com/') || query.startsWith('http://www.youtube.com/')
|
||||
}
|
||||
|
||||
if(video || ignoreQueue) {
|
||||
if(!ignoreQueue) {
|
||||
// Fix the bot if somehow broken
|
||||
client.music.getLinkFromID = function (id) {
|
||||
return 'https://www.youtube.com/watch?v=' + id
|
||||
}
|
||||
|
||||
client.music.getVideoByQuery = async function (query) {
|
||||
const isLink = client.music.isYouTubeLink(query)
|
||||
|
||||
let response
|
||||
|
||||
if (isLink) {
|
||||
response = await fetch('https://www.googleapis.com/youtube/v3/search?key=' + client.config.keys.yt + '&part=id,snippet&maxResults=1&type=video&id=' + id)
|
||||
} else {
|
||||
// TODO: replace this workaround
|
||||
response = await fetch('https://www.googleapis.com/youtube/v3/search?key=' + client.config.keys.yt + '&part=id,snippet&maxResults=1&type=video&q=**' + encodeURIComponent(query) + '**')
|
||||
}
|
||||
|
||||
const parsed = await response.json()
|
||||
|
||||
if (parsed.items) {
|
||||
const video = parsed.items[0]
|
||||
|
||||
if (video) {
|
||||
return video
|
||||
} else {
|
||||
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) {
|
||||
return message.reply('you are not in a voice channel!')
|
||||
}
|
||||
|
||||
const vc = message.member.voice.channel
|
||||
|
||||
let video
|
||||
|
||||
if (!ignoreQueue) {
|
||||
video = await client.music.getVideoByQuery(query)
|
||||
}
|
||||
|
||||
if (video || ignoreQueue) {
|
||||
if (!ignoreQueue) {
|
||||
// Fix the bot if somehow broken
|
||||
// music "playing", nothing in queue
|
||||
if((guild.playing || guild.dispatcher) && guild.queue.length == 0) {
|
||||
guild.playing = false;
|
||||
guild.dispatcher = null;
|
||||
if ((guild.playing || guild.dispatcher) && guild.queue.length === 0) {
|
||||
guild.playing = false
|
||||
guild.dispatcher = null
|
||||
// music not playing, something is in queue
|
||||
} else if(!guild.playing && !guild.dispatcher && guild.queue.length > 0) {
|
||||
guild.queue = [];
|
||||
};
|
||||
} else if (!guild.playing && !guild.dispatcher && guild.queue.length > 0) {
|
||||
guild.queue = []
|
||||
}
|
||||
|
||||
// Add video to queue
|
||||
guild.queue.push({video: video, requestedBy: message.member.id});
|
||||
};
|
||||
guild.queue.push({ video: video, requestedBy: message.member.id })
|
||||
}
|
||||
|
||||
// Figure out if the bot should add it to queue or play it right now
|
||||
if(guild.playing) {
|
||||
message.reply('added **' + video.snippet.title + '** to the queue');
|
||||
// Figure out if the bot should add it to queue or play it right now
|
||||
if (guild.playing) {
|
||||
message.reply('added **' + video.snippet.title + '** to the queue')
|
||||
} else {
|
||||
guild.playing = true;
|
||||
guild.playing = true
|
||||
|
||||
guild.voiceChannel = vc;
|
||||
guild.voiceChannel = vc
|
||||
|
||||
let connection = await vc.join();
|
||||
|
||||
let v = guild.queue[0];
|
||||
const connection = await vc.join()
|
||||
|
||||
guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId), {highWaterMark: 1024 * 1024 * 32}), {type: 'opus'});
|
||||
guild.dispatcher.setVolume(0.25);
|
||||
const v = guild.queue[0]
|
||||
|
||||
message.channel.send('Playing **' + v.video.snippet.title + '**');
|
||||
guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId), { highWaterMark: 1024 * 1024 * 32 }), { type: 'opus' })
|
||||
guild.dispatcher.setVolume(0.25)
|
||||
|
||||
message.channel.send('Playing **' + v.video.snippet.title + '**')
|
||||
|
||||
// play next in queue on end
|
||||
guild.dispatcher.once('finish', () => {
|
||||
guild.queue.shift();
|
||||
guild.playing = false;
|
||||
guild.queue.shift()
|
||||
guild.playing = false
|
||||
|
||||
if(guild.queue.length > 0) {
|
||||
client.music.play(message, null, true);
|
||||
if (guild.queue.length > 0) {
|
||||
client.music.play(message, null, true)
|
||||
} else {
|
||||
guild.dispatcher = null;
|
||||
guild.dispatcher = null
|
||||
|
||||
connection.disconnect();
|
||||
};
|
||||
});
|
||||
};
|
||||
connection.disconnect()
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
return message.reply('failed to find the video!');
|
||||
};
|
||||
};
|
||||
return message.reply('failed to find the video!')
|
||||
}
|
||||
}
|
||||
|
||||
client.music.setVolume = function(guild, target) {
|
||||
let g = client.music.getGuild(guild.id);
|
||||
client.music.setVolume = function (guild, target) {
|
||||
const g = client.music.getGuild(guild.id)
|
||||
|
||||
if(g.dispatcher) {
|
||||
g.dispatcher.setVolume(target);
|
||||
};
|
||||
};
|
||||
if (g.dispatcher) {
|
||||
g.dispatcher.setVolume(target)
|
||||
}
|
||||
}
|
||||
|
||||
client.music.skip = function(guild, reason) {
|
||||
let g = client.music.getGuild(guild.id);
|
||||
client.music.skip = function (guild, reason) {
|
||||
const g = client.music.getGuild(guild.id)
|
||||
|
||||
if(g.dispatcher) {
|
||||
g.dispatcher.end(reason);
|
||||
};
|
||||
};
|
||||
if (g.dispatcher) {
|
||||
g.dispatcher.end(reason)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
20
index.js
20
index.js
|
@ -50,6 +50,14 @@ client.logger = require('tracer').colorConsole({
|
|||
filters: [colors.white]
|
||||
})
|
||||
|
||||
// Check if Woomy is running inside a Docker container
|
||||
if (isDocker() === true) {
|
||||
client.devmode = true
|
||||
client.logger.warn('Running in development mode.')
|
||||
} else {
|
||||
client.devmode = false
|
||||
}
|
||||
|
||||
// Create caches for permissions, commands, cooldowns and aliases
|
||||
client.levelCache = {}
|
||||
client.commands = new Discord.Collection()
|
||||
|
@ -59,7 +67,9 @@ client.aliases = new Discord.Collection()
|
|||
// Main initialisation function
|
||||
const init = async () => {
|
||||
// initialise sentry
|
||||
if (client.config.keys.sentry != '') sentry.init({dsn: client.config.keys.sentry})
|
||||
if (client.config.keys.sentry !== '' && client.devmode === false) {
|
||||
sentry.init({ dsn: client.config.keys.sentry })
|
||||
}
|
||||
|
||||
// Command handler
|
||||
fs.readdir('./commands', (err, files) => {
|
||||
|
@ -101,14 +111,6 @@ const init = async () => {
|
|||
client.levelCache[thisLevel.name] = thisLevel.level
|
||||
}
|
||||
|
||||
// Check if Woomy is running inside a Docker container
|
||||
if (isDocker() === true) {
|
||||
client.devmode = true
|
||||
client.logger.warn('Running in development mode.')
|
||||
} else {
|
||||
client.devmode = false
|
||||
}
|
||||
|
||||
// Initialise DB
|
||||
await client.db.init(client)
|
||||
|
||||
|
|
Loading…
Reference in a new issue