1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-10 02:00:20 +00:00

Added consolelogs

This commit is contained in:
MatteZ02 2019-10-12 13:31:07 +03:00
parent 970ec44de8
commit 81f317105b
3 changed files with 33 additions and 1 deletions

View File

@ -8,12 +8,14 @@ module.exports = {
args: true,
cooldown: 3,
async execute(message, args, client, Discord, prefix) {
console.log("play command")
const youtube = new YouTube(client.config.apikey);
const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const serverQueue = client.queue.get(message.guild.id);
const voiceChannel = message.member.voiceChannel;
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!');
} else {
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!');
@ -21,12 +23,15 @@ module.exports = {
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);
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!');
}
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!');
}
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
console.log("playlist")
const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos();
for (const video of Object.values(videos)) {
@ -39,6 +44,7 @@ module.exports = {
var video = await youtube.getVideo(url);
} catch (error) {
try {
console.log("song selection")
var videos = await youtube.searchVideos(searchString, 10);
let index = 0;
const embed = new Discord.RichEmbed()
@ -47,23 +53,28 @@ module.exports = {
.setFooter("Please provide a number ranging from 1-10 to select one of the search results.")
.setColor("#b50002")
message.channel.send(embed);
console.log("song select embed sent")
try {
console.log("response")
var response = await message.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11, {
maxMatches: 1,
time: 10000,
errors: ['time']
});
} catch (err) {
console.log("cancelling video selection")
console.error(err);
return message.channel.send(':x: Cancelling video selection');
}
const videoIndex = parseInt(response.first().content);
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
} catch (err) {
console.log("no results")
console.error(err);
return message.channel.send(':x: I could not obtain any search results!');
}
}
console.log("Handlevideo")
return client.funcs.handleVideo(video, message, voiceChannel, client, false);
}
}

View File

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

View File

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