forked from embee/woomy
		
	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: [],
 | 
					  aliases: [],
 | 
				
			||||||
  permLevel: 'User',
 | 
					  permLevel: 'User',
 | 
				
			||||||
  requiredPerms: [],
 | 
					  requiredPerms: [],
 | 
				
			||||||
  cooldown: 2000,
 | 
					  cooldown: 2000
 | 
				
			||||||
  joinArguments: 1
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.help = {
 | 
					exports.help = {
 | 
				
			||||||
| 
						 | 
					@ -16,6 +15,6 @@ 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.'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.run = async (client, message, args, level, data) => {
 | 
					exports.run = async (client, message, [...args], level, data) => {
 | 
				
			||||||
    await client.music.play(message, args[0]);
 | 
					  await client.music.play(message, args)
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,9 @@
 | 
				
			||||||
exports.conf = {
 | 
					exports.conf = {
 | 
				
			||||||
  enabled: true,
 | 
					  enabled: true,
 | 
				
			||||||
  guildOnly: true,
 | 
					  guildOnly: true,
 | 
				
			||||||
  aliases: [],
 | 
					  aliases: ['vol'],
 | 
				
			||||||
  permLevel: 'Moderator',
 | 
					  permLevel: 'Moderator',
 | 
				
			||||||
  requiredPerms: ['vol'],
 | 
					  requiredPerms: [],
 | 
				
			||||||
  cooldown: 2000
 | 
					  cooldown: 2000
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,17 +16,17 @@ exports.help = {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.run = async (client, message, args, level, data) => {
 | 
					exports.run = async (client, message, args, level, data) => {
 | 
				
			||||||
  let vol = args[0];
 | 
					  let vol = args[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if(vol) {
 | 
					  if (vol) {
 | 
				
			||||||
    vol = Number(vol);
 | 
					    vol = Number(vol)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    vol = vol / 100 * 0.5;
 | 
					    vol = vol / 100 * 0.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(vol <= 1) {
 | 
					    if (vol <= 1) {
 | 
				
			||||||
      client.music.setVolume(message.guild, vol);
 | 
					      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))
 | 
					    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}`)
 | 
					  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 ytdl = require('ytdl-core-discord')
 | 
				
			||||||
const fetch = require('node-fetch');
 | 
					const fetch = require('node-fetch')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = client => {
 | 
					module.exports = client => {
 | 
				
			||||||
  client.music = {guilds: {}};
 | 
					  client.music = { guilds: {} }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // MUSIC - TIMESTAMP
 | 
					  // MUSIC - TIMESTAMP
 | 
				
			||||||
  client.createTimestamp = function (duration) {
 | 
					  client.createTimestamp = function (duration) {
 | 
				
			||||||
| 
						 | 
					@ -30,137 +30,137 @@ module.exports = client => {
 | 
				
			||||||
    return time
 | 
					    return time
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  client.music.getGuild = function(id) {
 | 
					  client.music.getGuild = function (id) {
 | 
				
			||||||
    let guild = client.music.guilds[id];
 | 
					    let guild = client.music.guilds[id]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!guild) {
 | 
					    if (!guild) {
 | 
				
			||||||
      guild = {};
 | 
					      guild = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      guild.dispatcher = null;
 | 
					      guild.dispatcher = null
 | 
				
			||||||
      guild.playing = false;
 | 
					      guild.playing = false
 | 
				
			||||||
      guild.queue = [];
 | 
					      guild.queue = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      client.music.guilds[id] = guild;
 | 
					      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!');
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let vc = message.member.voice.channel;
 | 
					    return guild
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let video;
 | 
					  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(!ignoreQueue) {
 | 
					  }
 | 
				
			||||||
      video = await client.music.getVideoByQuery(query);
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(video || ignoreQueue) {
 | 
					  client.music.getLinkFromID = function (id) {
 | 
				
			||||||
      if(!ignoreQueue) {
 | 
					    return 'https://www.youtube.com/watch?v=' + id
 | 
				
			||||||
        // Fix the bot if somehow broken
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  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
 | 
					        // music "playing", nothing in queue
 | 
				
			||||||
        if((guild.playing || guild.dispatcher) && guild.queue.length == 0) {
 | 
					        if ((guild.playing || guild.dispatcher) && guild.queue.length === 0) {
 | 
				
			||||||
          guild.playing = false;
 | 
					          guild.playing = false
 | 
				
			||||||
          guild.dispatcher = null;
 | 
					          guild.dispatcher = null
 | 
				
			||||||
        // 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 = []
 | 
				
			||||||
        };
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Add video to 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
 | 
					      // Figure out if  the bot should add it to queue or play it right now
 | 
				
			||||||
      if(guild.playing) {
 | 
					      if (guild.playing) {
 | 
				
			||||||
        message.reply('added **' + video.snippet.title + '** to the queue');
 | 
					        message.reply('added **' + video.snippet.title + '** to the queue')
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        guild.playing = true;
 | 
					        guild.playing = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        guild.voiceChannel = vc;
 | 
					        guild.voiceChannel = vc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let connection = await vc.join();
 | 
					        const connection = await vc.join()
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        let v = guild.queue[0];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        guild.dispatcher = connection.play(await ytdl(client.music.getLinkFromID(v.video.id.videoId), {highWaterMark: 1024 * 1024 * 32}), {type: 'opus'});
 | 
					        const v = guild.queue[0]
 | 
				
			||||||
        guild.dispatcher.setVolume(0.25);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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
 | 
					        // play next in queue on end
 | 
				
			||||||
        guild.dispatcher.once('finish', () => {
 | 
					        guild.dispatcher.once('finish', () => {
 | 
				
			||||||
          guild.queue.shift();
 | 
					          guild.queue.shift()
 | 
				
			||||||
          guild.playing = false;
 | 
					          guild.playing = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if(guild.queue.length > 0) {
 | 
					          if (guild.queue.length > 0) {
 | 
				
			||||||
            client.music.play(message, null, true);
 | 
					            client.music.play(message, null, true)
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            guild.dispatcher = null;
 | 
					            guild.dispatcher = null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            connection.disconnect();
 | 
					            connection.disconnect()
 | 
				
			||||||
          };
 | 
					          }
 | 
				
			||||||
        });
 | 
					        })
 | 
				
			||||||
      };
 | 
					      }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      return message.reply('failed to find the video!');
 | 
					      return message.reply('failed to find the video!')
 | 
				
			||||||
    };
 | 
					    }
 | 
				
			||||||
  };
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  client.music.setVolume = function(guild, target) {
 | 
					  client.music.setVolume = function (guild, target) {
 | 
				
			||||||
    let g = client.music.getGuild(guild.id);
 | 
					    const g = client.music.getGuild(guild.id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(g.dispatcher) {
 | 
					    if (g.dispatcher) {
 | 
				
			||||||
      g.dispatcher.setVolume(target);
 | 
					      g.dispatcher.setVolume(target)
 | 
				
			||||||
    };
 | 
					    }
 | 
				
			||||||
  };
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  client.music.skip = function(guild, reason) {
 | 
					  client.music.skip = function (guild, reason) {
 | 
				
			||||||
    let g = client.music.getGuild(guild.id);
 | 
					    const g = client.music.getGuild(guild.id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(g.dispatcher) {
 | 
					    if (g.dispatcher) {
 | 
				
			||||||
      g.dispatcher.end(reason);
 | 
					      g.dispatcher.end(reason)
 | 
				
			||||||
    };
 | 
					    }
 | 
				
			||||||
  };
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										20
									
								
								index.js
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								index.js
									
										
									
									
									
								
							| 
						 | 
					@ -50,6 +50,14 @@ client.logger = require('tracer').colorConsole({
 | 
				
			||||||
  filters: [colors.white]
 | 
					  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
 | 
					// Create caches for permissions, commands, cooldowns and aliases
 | 
				
			||||||
client.levelCache = {}
 | 
					client.levelCache = {}
 | 
				
			||||||
client.commands = new Discord.Collection()
 | 
					client.commands = new Discord.Collection()
 | 
				
			||||||
| 
						 | 
					@ -59,7 +67,9 @@ client.aliases = new Discord.Collection()
 | 
				
			||||||
// Main initialisation function
 | 
					// Main initialisation function
 | 
				
			||||||
const init = async () => {
 | 
					const init = async () => {
 | 
				
			||||||
  // initialise sentry
 | 
					  // 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
 | 
					  // Command handler
 | 
				
			||||||
  fs.readdir('./commands', (err, files) => {
 | 
					  fs.readdir('./commands', (err, files) => {
 | 
				
			||||||
| 
						 | 
					@ -101,14 +111,6 @@ const init = async () => {
 | 
				
			||||||
    client.levelCache[thisLevel.name] = thisLevel.level
 | 
					    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
 | 
					  // Initialise DB
 | 
				
			||||||
  await client.db.init(client)
 | 
					  await client.db.init(client)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue