1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-22 18:03:17 +00:00

Saved queues

This commit is contained in:
MatteZ02 2019-10-12 17:40:00 +03:00
parent e8f30cd706
commit a8cde6abca
6 changed files with 73 additions and 7 deletions

View File

@ -5,7 +5,9 @@ module.exports = {
async execute(message, args, client, Discord, prefix) {
const ytdl = require('ytdl-core');
const serverQueue = client.queue.get(message.guild.id);
let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
if (serverQueue) {
let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
}
if (message.author.id !== '360363051792203779') return message.channel.send(':x: You are not allowed to do that!');
const input = message.content.slice(prefix.length + 4);
let output;

56
commands/playlist.js Normal file
View File

@ -0,0 +1,56 @@
module.exports = {
name: 'playlist',
usage: '[option]',
description: 'Save and load queues',
cooldown: 10,
async execute(message, args, client, Discord, prefix) {
const serverQueue = client.queue.get(message.guild.id);
if (client.global.db.guilds[message.guild.id].premium) {
if (args[1] === 'play') {
if (client.global.db.playlists[message.guild.id].saved) {
if (!serverQueue) {
const construct = {
textChannel: message.channel,
voiceChannel: message.member.voiceChannel,
connection: null,
songs: [...client.global.db.playlists[message.guild.id].songs],
volume: client.global.db.guilds[message.guild.id].defaultVolume,
playing: true,
looping: false
};
client.queue.set(message.guild.id, construct);
message.channel.send(":white_check_mark: Queue set!");
try {
var connection = await message.member.voiceChannel.join();
construct.connection = connection;
client.funcs.play(message.guild, construct.songs[0], client, message, 0);
} catch (error) {
client.queue.delete(message.guild.id);
return message.channel.send(`:x: An error occured: ${error}`);
}
} else {
serverQueue.connection.dispatcher.end("queue set");
serverQueue.songs = [...client.global.db.playlists[message.guild.id].songs];
message.channel.send(":white_check_mark: Queue set!");
}
} else return message.channel.send(':x: There is no queue set for this server!')
} else if (args[1] === 'save') {
client.global.db.playlists[message.guild.id] = {
songs: serverQueue.songs,
firstSong: serverQueue.songs[0],
saved: true,
};
message.channel.send(":white_check_mark: Queue saved!");
} else {
const embed = new Discord.RichEmbed()
.setTitle('Options for playlist!')
.addField('play', 'Play the guild specific queue.', true)
.addField('save', 'Save the currently playing queue.')
.setFooter(`how to use: ${prefix}playlist <Option>`)
.setAuthor(client.user.username, client.user.displayAvatarURL)
.setColor('#b50002')
return message.channel.send(embed);
}
} else return message.channel.send(":x: This is not a premium guild!");
},
};

View File

@ -8,6 +8,7 @@ module.exports = {
prefix: ">",
defaultVolume: 5,
permissions: false,
premium: false,
};
});
return message.channel.send(':white_check_mark: Reset all guild settings!')
@ -16,9 +17,10 @@ module.exports = {
prefix: ">",
defaultVolume: 5,
permissions: false,
premium: false,
};
}
let prefix = client.global.db.guilds[message.guild.id].prefix;
let prefix = "-"//client.global.db.guilds[message.guild.id].prefix;
const args = message.content.slice(prefix.length).split(' ');
if (message.mentions.users.first()) {
if (message.mentions.users.first().id === '607266889537945605' && args[1] === 'help') return client.commands.get('help').execute(message, args, client, Discord, prefix, client);

View File

@ -16,8 +16,13 @@ module.exports = {
defaultVolume: client.global.db.guilds[guild.id].defaultVolume,
permissions: client.global.db.guilds[guild.id].permissions,
});
if (client.global.db.guilds[guild.id].premium) {
client.db.collection('playlists').doc(guild.id).set({
songs: client.global.db.playlists[message.guild.id].songs,
});
}
});
dbl.postStats(client.guilds.size);
}, 1200000);
}, 1800000);
}
}

View File

@ -25,11 +25,11 @@ module.exports = async function (guild, song, client, message, seek) {
});
dispatcher.setVolume(serverQueue.volume / 10);
dispatcher.on("error", error => console.error(error));
//let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
//let songtime = (data.length_seconds * 1000).toFixed(0);
let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url));
let songtime = (data.length_seconds * 1000).toFixed(0);
const embed = new Discord.RichEmbed()
.setTitle(`:musical_note: Start playing: **${song.title}**`)
//.setDescription(`Song duration: \`${client.funcs.msToTime(songtime)}\``)
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime)}\``)
.setColor("#b50002")
serverQueue.textChannel.send(embed);
}

View File

@ -18,6 +18,7 @@ client.db.FieldValue = require('firebase-admin').firestore.FieldValue;
client.global = {
db: {
guilds: {},
playlists: {},
},
};
@ -34,7 +35,7 @@ client.funcs.dbget = require('./funcs/dbget.js');
client.config = {
token: process.env.TOKEN,
apikey: process.env.API_KEY,
apikey: process.env.API_KEY2,
prefix: '>',
test: 'success',
};