1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-19 22:11:55 +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,
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 {
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 (!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)) {
@ -45,7 +39,6 @@ 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()
@ -54,28 +47,23 @@ 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,6 +1,5 @@
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),
@ -8,7 +7,6 @@ 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,
@ -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.');
}
if (!serverQueue) {
console.log("no serverQueue")
const construct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
@ -26,23 +23,17 @@ 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,15 +1,12 @@
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 => {
@ -21,27 +18,18 @@ 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("setting 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")
console.log("sending embed")
return serverQueue.textChannel.send(embed);
serverQueue.textChannel.send(embed);
}