1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-20 01:21:56 +00:00

removed console.lgos

This commit is contained in:
MatteZ02 2019-10-12 13:38:12 +03:00
parent 59b578c5a5
commit 271c16a4c0
3 changed files with 1 additions and 34 deletions

View File

@ -8,31 +8,25 @@ module.exports = {
args: true, args: true,
cooldown: 3, cooldown: 3,
async execute(message, args, client, Discord, prefix) { async execute(message, args, client, Discord, prefix) {
console.log("play command")
const youtube = new YouTube(client.config.apikey); const youtube = new YouTube(client.config.apikey);
const searchString = args.slice(1).join(" "); const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const serverQueue = client.queue.get(message.guild.id); const serverQueue = client.queue.get(message.guild.id);
const voiceChannel = message.member.voiceChannel; const voiceChannel = message.member.voiceChannel;
if (!serverQueue) { if (!serverQueue) {
console.log("no serverQueue")
if (!voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in a voice channel to play music!'); if (!voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in a voice channel to play music!');
} else { } else {
console.log("serverQueue")
if (voiceChannel !== serverQueue.voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in the same voiceChannel as Musix to play music!'); if (voiceChannel !== serverQueue.voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in the same voiceChannel as Musix to play music!');
} }
if (!args[1]) return message.channel.send(':x: You need to use a link or search for a song!'); if (!args[1]) return message.channel.send(':x: You need to use a link or search for a song!');
const permissions = voiceChannel.permissionsFor(message.client.user); const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT')) { if (!permissions.has('CONNECT')) {
console.log("no connect perms")
return message.channel.send(':x: I cannot connect to your voice channel, make sure I have the proper permissions!'); return message.channel.send(':x: I cannot connect to your voice channel, make sure I have the proper permissions!');
} }
if (!permissions.has('SPEAK')) { if (!permissions.has('SPEAK')) {
console.log("no speaking perms")
return message.channel.send(':x: I cannot speak in your voice channel, make sure I have the proper permissions!'); return message.channel.send(':x: I cannot speak in your voice channel, make sure I have the proper permissions!');
} }
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) { if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
console.log("playlist")
const playlist = await youtube.getPlaylist(url); const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos(); const videos = await playlist.getVideos();
for (const video of Object.values(videos)) { for (const video of Object.values(videos)) {
@ -45,7 +39,6 @@ module.exports = {
var video = await youtube.getVideo(url); var video = await youtube.getVideo(url);
} catch (error) { } catch (error) {
try { try {
console.log("song selection")
var videos = await youtube.searchVideos(searchString, 10); var videos = await youtube.searchVideos(searchString, 10);
let index = 0; let index = 0;
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
@ -54,28 +47,23 @@ module.exports = {
.setFooter("Please provide a number ranging from 1-10 to select one of the search results.") .setFooter("Please provide a number ranging from 1-10 to select one of the search results.")
.setColor("#b50002") .setColor("#b50002")
message.channel.send(embed); message.channel.send(embed);
console.log("song select embed sent")
try { try {
console.log("response")
var response = await message.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11, { var response = await message.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11, {
maxMatches: 1, maxMatches: 1,
time: 10000, time: 10000,
errors: ['time'] errors: ['time']
}); });
} catch (err) { } catch (err) {
console.log("cancelling video selection")
console.error(err); console.error(err);
return message.channel.send(':x: Cancelling video selection'); return message.channel.send(':x: Cancelling video selection');
} }
const videoIndex = parseInt(response.first().content); const videoIndex = parseInt(response.first().content);
var video = await youtube.getVideoByID(videos[videoIndex - 1].id); var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
} catch (err) { } catch (err) {
console.log("no results")
console.error(err); console.error(err);
return message.channel.send(':x: I could not obtain any search results!'); return message.channel.send(':x: I could not obtain any search results!');
} }
} }
console.log("Handlevideo")
return client.funcs.handleVideo(video, message, voiceChannel, client, false); return client.funcs.handleVideo(video, message, voiceChannel, client, false);
} }
} }

View File

@ -1,6 +1,5 @@
module.exports = async function (video, message, voiceChannel, client, playlist = false) { module.exports = async function (video, message, voiceChannel, client, playlist = false) {
const Discord = require('discord.js'); const Discord = require('discord.js');
console.log("handlevideo function")
let song = { let song = {
id: video.id, id: video.id,
title: Discord.Util.escapeMarkdown(video.title), title: Discord.Util.escapeMarkdown(video.title),
@ -8,7 +7,6 @@ module.exports = async function (video, message, voiceChannel, client, playlist
} }
const serverQueue = client.queue.get(message.guild.id); const serverQueue = client.queue.get(message.guild.id);
if (client.global.db.guilds[message.guild.id].defaultVolume === undefined) { if (client.global.db.guilds[message.guild.id].defaultVolume === undefined) {
console.log("defaultvolume undefined")
client.global.db.guilds[message.guild.id] = { client.global.db.guilds[message.guild.id] = {
prefix: client.global.db.guilds[message.guild.id].prefix, prefix: client.global.db.guilds[message.guild.id].prefix,
defaultVolume: 5, defaultVolume: 5,
@ -16,7 +14,6 @@ module.exports = async function (video, message, voiceChannel, client, playlist
return message.channel.send(':x: `Error:` the default volume is undefined for this server. Please try again after a while.'); return message.channel.send(':x: `Error:` the default volume is undefined for this server. Please try again after a while.');
} }
if (!serverQueue) { if (!serverQueue) {
console.log("no serverQueue")
const construct = { const construct = {
textChannel: message.channel, textChannel: message.channel,
voiceChannel: voiceChannel, voiceChannel: voiceChannel,
@ -26,23 +23,17 @@ module.exports = async function (video, message, voiceChannel, client, playlist
playing: true, playing: true,
looping: false looping: false
}; };
console.log("Pushing song")
construct.songs.push(song); construct.songs.push(song);
console.log("settings queue")
client.queue.set(message.guild.id, construct); client.queue.set(message.guild.id, construct);
try { try {
console.log("connecting...")
var connection = await voiceChannel.join(); var connection = await voiceChannel.join();
construct.connection = connection; construct.connection = connection;
console.log("connected")
client.funcs.play(message.guild, construct.songs[0], client, message, 0); client.funcs.play(message.guild, construct.songs[0], client, message, 0);
} catch (error) { } catch (error) {
console.log("error with connection")
client.queue.delete(message.guild.id); client.queue.delete(message.guild.id);
return message.channel.send(`:x: An error occured: ${error}`); return message.channel.send(`:x: An error occured: ${error}`);
} }
} else { } else {
console.log("adding to queue")
serverQueue.songs.push(song); serverQueue.songs.push(song);
if (playlist) return undefined; if (playlist) return undefined;
return message.channel.send(`:white_check_mark: **${song.title}** has been added to the queue!`); return message.channel.send(`:white_check_mark: **${song.title}** has been added to the queue!`);

View File

@ -1,15 +1,12 @@
module.exports = async function (guild, song, client, message, seek) { module.exports = async function (guild, song, client, message, seek) {
console.log("Play function")
const Discord = require('discord.js'); const Discord = require('discord.js');
const ytdl = require('ytdl-core'); const ytdl = require('ytdl-core');
const serverQueue = client.queue.get(guild.id); const serverQueue = client.queue.get(guild.id);
if (!song) { if (!song) {
console.log("no song")
serverQueue.voiceChannel.leave(); serverQueue.voiceChannel.leave();
client.queue.delete(guild.id); client.queue.delete(guild.id);
return; return;
} }
console.log("playing stream")
const dispatcher = serverQueue.connection const dispatcher = serverQueue.connection
.playStream(ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25 }), { seek: seek, bitrate: 1024, passes: 10, volume: 1 }) .playStream(ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25 }), { seek: seek, bitrate: 1024, passes: 10, volume: 1 })
.on("end", reason => { .on("end", reason => {
@ -21,27 +18,18 @@ module.exports = async function (guild, song, client, message, seek) {
console.log(reason); console.log(reason);
} }
if (serverQueue.looping) { if (serverQueue.looping) {
console.log("looping")
serverQueue.songs.push(serverQueue.songs[0]); serverQueue.songs.push(serverQueue.songs[0]);
} }
console.log("shifting songs")
serverQueue.songs.shift(); serverQueue.songs.shift();
console.log("playing next song")
client.funcs.play(guild, serverQueue.songs[0], client, message); client.funcs.play(guild, serverQueue.songs[0], client, message);
}); });
console.log("setting volume")
dispatcher.setVolume(serverQueue.volume / 10); dispatcher.setVolume(serverQueue.volume / 10);
console.log("checking for errors")
dispatcher.on("error", error => console.error(error)); dispatcher.on("error", error => console.error(error));
console.log("defining data |")
//let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url)); //let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
console.log("defining songtime |")
//let songtime = (data.length_seconds * 1000).toFixed(0); //let songtime = (data.length_seconds * 1000).toFixed(0);
console.log("creating embed")
const embed = new Discord.RichEmbed() const embed = new Discord.RichEmbed()
.setTitle(`:musical_note: Start playing: **${song.title}**`) .setTitle(`:musical_note: Start playing: **${song.title}**`)
//.setDescription(`Song duration: \`${client.funcs.msToTime(songtime)}\``) //.setDescription(`Song duration: \`${client.funcs.msToTime(songtime)}\``)
.setColor("#b50002") .setColor("#b50002")
console.log("sending embed") serverQueue.textChannel.send(embed);
return serverQueue.textChannel.send(embed);
} }