1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-18 05:26:00 +00:00

Update V3.0.4

This commit is contained in:
MatteZ02
2020-03-21 19:49:25 +02:00
parent b9f0eb3a96
commit 7e20f54362
63 changed files with 124 additions and 90 deletions

60
src/struct/client.js Normal file
View File

@ -0,0 +1,60 @@
const { Client, Collection } = require('discord.js');
const admin = require('firebase-admin');
const serviceAccount = require('./config/serviceAccount.json');
const fs = require('fs');
const path = require('path');
const events = require('../events/events.js');
module.exports = class extends Client {
constructor() {
super({
disableEveryone: true,
disabledEvents: ['TYPING_START']
});
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
this.commands = new Collection();
this.commandAliases = new Collection();
this.settingCmd = new Collection();
this.queue = new Map();
this.funcs = {};
this.dispatcher = {};
this.config = require('./config/config.js');
this.messages = require('./config/messages.js');
this.db = admin.firestore();
this.db.FieldValue = require('firebase-admin').firestore.FieldValue;
this.dispatcher.finish = require('../events/dispatcherEvents/finish.js');
this.dispatcher.error = require('../events/dispatcherEvents/error.js');
this.global = {
db: {
guilds: {},
},
};
fs.readdirSync(path.join(__dirname, 'funcs')).forEach(filename => {
this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`);
});
const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
command.uses = 0;
this.commands.set(command.name, command);
this.commandAliases.set(command.alias, command);
}
const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.js'));
for (const file of settingFiles) {
const option = require(`../commands/settings/${file}`);
this.settingCmd.set(option.name, option);
}
if (this.config.devMode) {
this.config.token = this.config.devToken;
}
events(this);
this.login(this.config.token).catch(err => console.log('Failed to login: ' + err));
}
};

View File

@ -0,0 +1,32 @@
require('dotenv/config');
module.exports = {
token: process.env.TOKEN,
devToken: process.env.DEVTOKEN,
dblKey: process.env.DBLKEY,
api_key: process.env.GOOGLE_API_KEY,
testServer: "489111553321336832",
debug_channel: "634718645188034560",
primary_test_channel: "617633098296721409",
secondary_test_channel: "570531724002328577",
devId: "360363051792203779",
embedColor: "#b50002",
invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot",
supportServer: "https://discord.gg/rvHuJtB",
devMode: false,
dblApi: false,
saveDB: true,
respawn: true,
shards: 10,
shardDelay: 10000,
spawnTimeout: 60000,
respawnDelay: 1000,
prefix: ">",
devPrefix: "-",
defaultVolume: 5,
permissions: false,
dj: false,
djrole: null,
startPlaying: true,
bass: 1
}

View File

@ -0,0 +1,126 @@
module.exports = {
alreadyPaused: "<:redx:674263474704220182> The music is already paused!",
alreadyVoted: "<:redx:674263474704220182> You have already voted to skip!",
announceSongs: "📣 Current setting:",
announceSongsFalse: "<:green_check_mark:674265384777416705> announcesongs now set to `false`!",
announceSongsTrue: "<:green_check_mark:674265384777416705> announcesongs now set to `true`!",
bassApplied: "<:volumehigh:674685637626167307> The bass level **%BASS%** will be applied when the next song starts playing!",
bassFalse: "<:green_check_mark:674265384777416705> Bass is now false!",
bassLevel: "<:green_check_mark:674265384777416705> Bass level is now",
boolean: "<:redx:674263474704220182> Please define a boolean! (true/false)",
cancellingVideoSelection: "<:redx:674263474704220182> Cancelling video selection",
cantSkipToCurrent: "<:redx:674263474704220182> You can't skip to the song currently playing!",
channelFull: "<:redx:674263474704220182> Your voice channel is full!",
cmdUsesFooter: "These statistics are from the current uptime.",
cmdUsesTitle: "Musix Command Usage During Current Uptime",
correctUsage: "<:redx:674263474704220182> correct usage: ",
currentBass: ":loud_sound: The current bass is: ",
currentDefaultBass: ":speaker: Currect default bass level: ",
currentDefaultVolume: ":speaker: Current default volume is:",
currentPrefix: "Current prefix:",
currentVolume: ":loud_sound: The current volume is: ",
dbSaved: "<:green_check_mark:674265384777416705> DB Saved!",
defaultVolumeMax: "<:redx:674263474704220182> The default volume must be below `100` for quality and safety resons.",
defaultVolumeNumber: "<:redx:674263474704220182> I'm sorry, But the default volume needs to be a valid __number__.",
defaultVolumeSet: "<:green_check_mark:674265384777416705> Default volume set to:",
devMode: "<:redx:674263474704220182> Dev mode has been turned on! Commands are only available to developer(s)!",
dispatcherError: "Error with the dispatcher: ",
djFalse: "<:green_check_mark:674265384777416705> `DJ` now set to `false`",
djRoleCreated: "<:green_check_mark:674265384777416705> I did not find a role `DJ` so i have created one for you!",
djRoleFound: "<:green_check_mark:674265384777416705> I found a `DJ` role from this guild! This role is now the DJ role.",
error: "<:redx:674263474704220182> An error occured!",
errorConnecting: "Error with connecting to voice channel: ",
errorDetected: "Error detected: ",
errorDispatcher: "<:redx:674263474704220182> An error has occured while playing music! The queue has been deleted.",
errorExe: "<:redx:674263474704220182> there was an error trying to execute that command!",
errorExeOpt: "<:redx:674263474704220182> there was an error trying to execute that option!",
evalTitle: "Evaluation Command",
helpCmdFooter: "Command Alias:",
helpFooter: "\"%PREFIX%help <command>\" to see more information about a command.",
helpTitle: "help",
inviteTitle: "Invite Musix to your Discord server!",
joined: "<:green_check_mark:674265384777416705> Joined",
joinSupport: "Join the musix support server: ",
loadingSongs: "<a:loading:674284196700618783> Loading song(s)",
looping: "<:repeat1:674685561377914892> Looping the queue now!",
loopingSong: "<:repeatsong:674685573419761716> Looping **%TITLE%** now!",
maxBass: "<:redx:674263474704220182> The max bass is `100`!",
maxVolume: "<:redx:674263474704220182> The max volume is `100`!",
noDj: "<:redx:674263474704220182> You need the `DJ` role to use this command!",
noLooping: "<:repeat1:674685561377914892> No longer looping the queue!",
noLoopingSong: "<:repeatsong:674685573419761716> No longer looping the song!",
noPerms: `<:redx:674263474704220182> You need the %PERMS% permission to use this command!`,
noPermsConnect: "<:redx:674263474704220182> I cannot connect to your voice channel, make sure I have the proper permissions!",
noPermsEmbed: "<:redx:674263474704220182> I cannot send embeds (Embed links), make sure I have the proper permissions!",
noPermsManageRoles: "<:redx:674263474704220182> I cannot create roles (Manage roles), make sure I have the proper permissions! I will need this permission to create a `DJ` role since i did not find one!",
noPermsManageSettings: "<:redx:674263474704220182> You need the `MANAGE_SERVER` permission to change the settings!",
noPermsSpeak: "<:redx:674263474704220182> I cannot speak in your voice channel, make sure I have the proper permissions!",
noPermsUseExternalEmojis: "<:redx:674263474704220182> I cannot use external emojis, make sure I have the proper permissions!",
noQuery: "<:redx:674263474704220182> You need to use a link or search for a song!",
noResults: "<:redx:674263474704220182> I could not obtain any search results!",
noServerQueue: "<:redx:674263474704220182> There is nothing playing!",
noSongs: "'<:redx:674263474704220182> That song does not exist!",
nowPlayingDesc: "<a:aNotes:674602408105476106>**Now playing:**",
notAllowed: "<:redx:674263474704220182> You are not allowed to do that!",
notEnoughVotes: "<:redx:674263474704220182> Not enough votes!",
notPaused: "<:redx:674263474704220182> The music in not paused!",
noVoiceChannel: "<:redx:674263474704220182> I'm sorry but you need to be in a voice channel to play music!",
nowPlaying: "__Now playing__",
paused: "<:pause:674685548610322462> Paused the music!",
permission: "🔒 Permission requirement:",
permissionsFalse: "<:redx:674263474704220182> That value is already `false`!",
permissionsSetFalse: "<:green_check_mark:674265384777416705> Permissions requirement now set to: `false`",
permissionsSetTrue: "<:green_check_mark:674265384777416705> Permissions requirement now set to: `true`",
permissionsTrue: "<:redx:674263474704220182> That value is already `true`!",
pinging: "<a:loading:674284196700618783> Pinging...",
playlistAdded: "<:green_check_mark:674265384777416705> Playlist: **%TITLE%** has been added to the queue!",
positiveBass: "<:redx:674263474704220182> The bass needs to be a positive number!",
positiveVolume: "<:redx:674263474704220182> The volume needs to be a positive number!",
prefixHere: "My prefix here is: ",
prefixMaxLength: "The prefix must be shorter or equal to 5 letters!",
prefixSet: "<:green_check_mark:674265384777416705> New prefix set to:",
provideANumber: "Please provide a number ranging from 1-10 to select one of the search results.",
provideASong: "<:redx:674263474704220182> Please provide a song position in queue for me to remove!",
queueDeleted: "Queue deleted!",
queueDesc: "**Now playing:** %SONG%<a:aNotes:674602408105476106>\n:arrow_down: Next in queue :arrow_down:",
queueFooter: "songs in the queue!",
queueLength: "<:redx:674263474704220182> There are only %SONGS% amount of songs in the queue!",
queueTitle: "__Song queue__",
quotaReached: "<:redx:674263474704220182> Quota reached please try again after midnight Pacific Time (PT)!",
reloaded: "All files reloaded!",
removed: "🗑 removed `%SONG%` from the queue!",
reset: "<:green_check_mark:674265384777416705> Reset __all__ guild settings!",
restart: "restarting all shards...",
resumed: "<:resume:674685585478254603> Resumed the music!",
seekingPointPositive: "<:redx:674263474704220182> The seeking point needs to be a positive number!",
seekMax: "<:redx:674263474704220182> The lenght of this song is %LENGTH% seconds! You can't seek further than that!",
settingsAnnounceSongs: "announcesongs",
settingsAnnounceSongsDesc: "Whether to announce songs that start playing or not.",
settingsBass: "bass",
settingsBassDesc: "Change the default bass level.",
settingsFooter: "how to use: %PREFIX%settings <Setting name> <value>",
settingsPermissions: "permissions",
settingsPermissionsDesc: "Change whether to require permissions to use eg `skip, stop, pause, loop, etc...`",
settingsPrefix: "prefix",
settingsPrefixDesc: "Change the guild specific prefix. (string)",
settingsSetDj: "setdj",
settingsSetDjDesc: "Set a DJ role. This will allow chosen users to freely use all Musix commands. This will automatically set the `permissions` settings to true in order for the `DJ` role to have effect!",
settingsTitle: "Guild settings for Musix",
settingsVolume: "volume",
settingsVolumeDesc: "Change the default volume that the bot will start playing at. (number)",
setVolume: "<:volumehigh:674685637626167307> I set the volume to: ",
shuffled: "<:shuffle:674685595980791871> Queue suffled!",
skipped: "<:skip:674685614221688832> Skipped the song!",
songAdded: "<:green_check_mark:674265384777416705> **%TITLE%** has been added to the queue!",
songBlockedWMG: "<:redx:674263474704220182> This song had been blocked by WMG (Warner Music Groud).\n<:skip:674685614221688832> Skipped to next song.",
songSelection: "__Song Selection__",
startPlaying: "<a:aNotes:674602408105476106> Start playing: ",
statusField1: ":signal_strength: Ping",
statusField2: "Latency",
statusField3: ":stopwatch: Uptime",
statusField4: "Shard: ",
statusTitle: "Status for Musix",
stop: "<:stop:674685626108477519> Stopped the music!",
validNumber: "<:redx:674263474704220182> I'm sorry, But you need to enter a valid __number__.",
wrongVoiceChannel: "<:redx:674263474704220182> I'm sorry but you need to be in the same voice channel as Musix to use this command!",
};

View File

@ -0,0 +1,17 @@
module.exports = {
textChannel: null,
voiceChannel: null,
connection: null,
songs: [],
volume: null,
bass: null,
playing: false,
paused: false,
looping: false,
songLooping: false,
votes: 0,
voters: [],
votesNeeded: null,
time: 0,
endReason: null,
}

View File

@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "musix-248615",
"private_key_id": "2c30ab611233b72e89a992c802a8f8ad5bb2854c",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCrmJ92a7s+uKSu\nN0nfGyTpNNNbTbvowJ34mIUEsHUK39dq5aWqR7RSbpHv9RNn6zHHL4cAWpTLkj3z\n/FMOXgopgb01RcQ72pxN492fZb7ik4JRdvLe6dgeisH8tbbtk8c1lMLKJrjPJJqt\nCnihjzWbEmnVdZBMJMfYX3Q3cBVFFbV5n50ldaUXo62QLzvgkx7pOTPRDNFCla3l\nIgG0EhDopn5swl5V9Ebym1hjpsrDod7Ci6mj+stLgCuu5TllR9hI52g4oUqpoyfy\nqMXo5qUaKBVpBxE4zNKW+mlQDpAJVIrDktt0vWwzLY0aXJwjMJMhDLLu3yJWnpsn\n5rcUzohDAgMBAAECggEAAL7XI6a1BWW8PfzxgH/qHiL15mOAfjLLc8CZTaAODYtT\nsK57lMOn1wj7FHfvYcpV7XRQZ2a0Mn7Hb40zygbnavgsUmZ/VZqpYlE+G2GZD/vI\n7ZQ+2rlZEExVKo5RQUWKp0w5JiEa75Nw/boHxrPnkdtTDPOjFY9QfTtwW2JxIKRp\nzwl6cS3ESBVj1snF4I/QwCo+mIlBvJcPHvFmWJW8zf2thr+JU4iDFAz1GWh7KXLD\nPyYfg0w6baMuWeKAy9SkFynpKxiba7DCqp4NsSsNmkbKs2vaPRrZGGXIw9KItxFb\nHPkzXtUur/BXpCvfYN+KsyuYlorqklIRxXF/38N56QKBgQDt6qx/4bC/k7EmgdtA\nKZhR2X0KFaL0w+fCCFg/eqCs7xIK6msTbWNCgBwHk7N9L7Q6aW4NDhLeujDHl5Zn\nG8IL3O2XVQxKFKhyORe8Jr7BBtg+OTEsS+f618r6N0p7zJVNocaXPhRHvpD1J1w+\nyNHNOeVGFgtRhxKw8xQA+00ABQKBgQC4o4AbQs+HfxrNST/9Nkrt9k5s2f0TewJx\ntIAndNcHen6p2HlkqgdIiI7676tfXgwaFl/wV3SQ2NKMXXGpRMMj0Iz6PldEZIT8\navNH226+h1UgmMuJ5JhdHQ/RVDnl1vN7xrOuJ4U5BuOeS44QYiYgE5afdbmCXzgV\nSii+eB2BpwKBgQC5igrOjA5PyPkdI6X9irKsGiVGSQtVQLYrfmB72MEXPDXg52Fr\nvCHtiYTSb+BJH3u5FeFqMvCKW7+Q1+nGLUKOB9QN8Zhs6WFX+qhE5h5a4GChXe64\nMdYOrF0x9w6SL0C8Uw5RgmtEbBwV44UvvWLIXn8rwiM/iEwOTPLrtQ8elQKBgQCE\nErhNR8IpOxtR4ua52r9Ibpp0tI2aBLCf4yyUjLhPqii2l5lmD1W8ZapZB11/j0d6\n1ax0wCoqfl5Fd4YZPY2UrdZaHoPP8VNLN7mkGeuisC2Nbp6RmYn/eQ1agDQWG2b5\nkA3xMmXSgAILtiH9yCdbZIemstAq2K/GUtDIRiVdGwKBgQC3ahm4dP/Tf5y1YT3P\n0GD2vfppAGWW6m3anbV97IWzHdOb0lVNoPLi8RaCH60hqV7CewolOT2d/IwAPpJH\nlSAj5NM8wOU5LsBZQ9NO6FH6KtWErsC4wES8U6KI9enMViwG7E39EaCZ65A5VT7W\n0VL7SEPN9iYy882fYuTYqV2ogg==\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-zq2bj@musix-248615.iam.gserviceaccount.com",
"client_id": "112286897035848826432",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-zq2bj%40musix-248615.iam.gserviceaccount.com"
}

View File

@ -0,0 +1,4 @@
module.exports = {
ytdlOptions: { filter: "audio", highWaterMark: 1 << 25, volume: false, begin: null },
options: { seek: 0, bitrate: 1024, passes: 10, volume: 1, type: "converted" }
};

27
src/struct/funcs/check.js Normal file
View File

@ -0,0 +1,27 @@
module.exports = function (client, msg, command) {
const queue = client.queue.get(msg.guild.id);
const permissions = msg.channel.permissionsFor(msg.author);
if (!queue || !queue.playing) {
msg.channel.send(client.messages.noServerQueue);
return false;
}
if (msg.author.id !== client.config.devId) {
if (msg.member.voice.channel !== queue.voiceChannel) {
msg.channel.send(client.messages.wrongVoiceChannel);
return false;
}
if (client.global.db.guilds[msg.guild.id].permissions === true) {
if (client.global.db.guilds[msg.guild.id].dj) {
if (!msg.member.roles.cache.has(client.global.db.guilds[msg.guild.id].djrole)) {
msg.channel.send(client.messages.noDj);
return false;
} else return true;
} else if (!permissions.has(command.permission)) {
let message
message = client.messages.noPerms.replace("%PERMS%", commands.permissions);
msg.channel.send(message);
return false;
} else return true;
} else return true;
} else return true;
};

View File

@ -0,0 +1,11 @@
module.exports = async function (client) {
client.guilds.cache.forEach(guild => {
if (client.global.db.guilds[guild.id].prefix === undefined) client.global.db.guilds[guild.id].prefix = client.config.prefix;
if (client.global.db.guilds[guild.id].defaultVolume === undefined) client.global.db.guilds[guild.id].defaultVolume = client.config.defaultVolume;
if (client.global.db.guilds[guild.id].permissions === undefined) client.global.db.guilds[guild.id].permissions = client.config.permissions;
if (client.global.db.guilds[guild.id].dj === undefined) client.global.db.guilds[guild.id].dj = client.config.dj;
if (client.global.db.guilds[guild.id].djrole === undefined) client.global.db.guilds[guild.id].djrole = client.config.djrole;
if (client.global.db.guilds[guild.id].startPlaying === undefined) client.global.db.guilds[guild.id].startPlaying = client.config.startPlaying;
if (client.global.db.guilds[guild.id].bass === undefined) client.global.db.guilds[guild.id].bass = client.config.bass;
});
};

22
src/struct/funcs/dbget.js Normal file
View File

@ -0,0 +1,22 @@
module.exports = async function (collection, doc, client) {
if (doc) {
let d = await client.db.collection(collection).doc(doc).get().catch(err => {
console.log('Error getting document', err);
return 'error';
});
return d.data();
} else {
let d = await client.db.collection(collection).get().catch(err => {
console.log('Error getting document', err);
return 'error';
});
let finalD = [];
d.forEach(doc => {
finalD.push({
id: doc.id,
d: doc.data(),
});
});
return finalD;
}
};

19
src/struct/funcs/exe.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = function (msg, args, client, Discord, command) {
const permissions = msg.channel.permissionsFor(msg.client.user);
if (!permissions.has('EMBED_LINKS')) return msg.channel.send(client.messages.noPermsEmbed);
if (!permissions.has('USE_EXTERNAL_EMOJIS')) return msg.channel.send(client.noPermsUseExternalEmojis);
try {
command.uses++;
command.execute(msg, args, client, Discord, command);
} catch (error) {
const date = new Date();
msg.reply(client.messages.errorExe);
const embed = new Discord.MessageEmbed()
.setTitle(`Musix ${error.toString()}`)
.setDescription(error.stack.replace(/at /g, '**at **'))
.setFooter(`guild: ${msg.guild.id} (${msg.guild.name}), user: ${msg.member.id} (${msg.member.displayName}), channel: ${msg.channel.id} (${msg.channel.name}), date: ${date}, Shard: ${client.shard.ids}`)
.setColor('#b50002');
client.debug_channel.send(embed);
console.error(error);
}
};

View File

@ -0,0 +1,9 @@
module.exports = async function (client) {
if (!client.guilds.cache.has(client.config.testServer)) return;
try {
await client.channels.fetch(client.config.secondary_test_channel)
.then(x => x.join());
} catch (error) {
client.debug_channel.send(client.messages.errorDetected + error);
}
};

View File

@ -0,0 +1,41 @@
module.exports = async function (video, msg, voiceChannel, client, playlist = false) {
const Discord = require('discord.js');
const song = {
id: video.id,
title: Discord.Util.escapeMarkdown(video.title),
url: `https://www.youtube.com/watch?v=${video.id}`,
author: msg.author
}
const queue = client.queue.get(msg.guild.id);
if (queue) {
queue.songs.push(song);
if (playlist) return;
let message;
message = client.messages.songAdded.replace("%TITLE%", song.title);
return msg.channel.send(message);
}
const construct = require("../config/queueConfig.js");
construct.textChannel = msg.channel;
construct.voiceChannel = voiceChannel;
construct.volume = client.global.db.guilds[msg.guild.id].defaultVolume;
construct.bass = client.global.db.guilds[msg.guild.id].bass;
construct.songs.push(song);
client.queue.set(msg.guild.id, construct);
try {
const connection = await voiceChannel.join();
construct.connection = connection;
client.funcs.play(msg.guild, construct.songs[0], client, 0, true);
} catch (error) {
client.queue.delete(msg.guild.id);
client.debug_channel.send(client.messages.errorConnecting + error);
return msg.channel.send(client.messages.error);
}
return;
}

View File

@ -0,0 +1,17 @@
module.exports = function msToTime(duration, format) {
var seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
days = Math.floor((duration / (1000 * 60 * 60 * 24)) % 24);
days = (days < 10) ? "0" + days : days;
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
if (format === "hh:mm:ss") {
return `${hours}:${minutes}:${seconds}`;
} else if (format === "dd:hh:mm:ss") {
return `${days}:${hours}:${minutes}:${seconds}`;
}
}

48
src/struct/funcs/play.js Normal file
View File

@ -0,0 +1,48 @@
module.exports = async function (guild, song, client, seek, play) {
const Discord = require('discord.js');
const ytdl = require('ytdl-core');
const streamConfig = require("../config/streamConfig.js");
const getThumb = require('video-thumbnail-url');
const prism = require('prism-media');
const queue = client.queue.get(guild.id);
if (!song) {
queue.voiceChannel.leave();
client.queue.delete(guild.id);
return;
}
streamConfig.ytdlOptions.begin = seek;
const ffmpegArgs = [
"-analyzeduration", "0",
"-loglevel", "0",
"-f", "s16le",
"-ar", "48000",
"-ac", "2",
"-af", `bass=g=${queue.bass}`
];
const transcoder = new prism.FFmpeg({ args: ffmpegArgs });
const dispatcher = queue.connection
.play(await ytdl(song.url, streamConfig.ytdlOptions).pipe(transcoder), streamConfig.options).on("finish", () => {
client.dispatcher.finish(client, queue.endReason, guild);
}).on('start', () => {
dispatcher.player.streamingData.pausedTime = 0;
}).on('error', error => {
client.dispatcher.error(client, error, guild);
});
dispatcher.setVolume(queue.volume / 10);
if (client.global.db.guilds[guild.id].startPlaying || play) {
const data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
const songtime = (data.length_seconds * 1000).toFixed(0);
const thumbnail = getThumb(queue.songs[0].url);
const embed = new Discord.MessageEmbed()
.setTitle(`${client.messages.startPlaying}**${song.title}**`)
.setDescription(`Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\``)
.setThumbnail(thumbnail._rejectionHandler0)
.setColor(client.config.embedColor)
queue.textChannel.send(embed);
}
queue.playing = true;
}

View File

@ -0,0 +1,16 @@
module.exports = async function (client) {
if (client.config.saveDB && !client.config.devMode) {
console.log('DB saved');
client.guilds.cache.forEach(guild => {
client.db.collection('guilds').doc(guild.id).set({
prefix: client.global.db.guilds[guild.id].prefix,
defaultVolume: client.global.db.guilds[guild.id].defaultVolume,
permissions: client.global.db.guilds[guild.id].permissions,
dj: client.global.db.guilds[guild.id].dj,
djrole: client.global.db.guilds[guild.id].djrole,
startPlaying: client.global.db.guilds[guild.id].startPlaying,
bass: client.global.db.guilds[guild.id].bass,
});
});
}
}

View File

@ -0,0 +1,11 @@
module.exports = function (a) {
for (let i = a.length - 1; i > 1; i--) {
const j = Math.floor(Math.random() * (i + 1));
if (i === 0 || j === 0) {
console.log(`J or I is 0. I: ${i} J: ${j}`);
} else {
[a[i], a[j]] = [a[j], a[i]];
}
}
return a;
};

View File

@ -0,0 +1,17 @@
module.exports = async function (client, msg, youtube, voiceChannel, url) {
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
const lmsg = await msg.channel.send(client.messages.loadingSongs);
const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos();
for (const video of Object.values(videos)) {
const video2 = await youtube.getVideoByID(video.id);
await client.funcs.handleVideo(video2, msg, voiceChannel, client, true);
}
let message;
message = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
lmsg.edit(message);
return true;
} else {
return false;
}
};