From 4ebe625ce00aaf87c292f72d8880d801c8e1a3e3 Mon Sep 17 00:00:00 2001 From: MatteZ02 <47610069+MatteZ02@users.noreply.github.com> Date: Sun, 15 Mar 2020 21:52:36 +0200 Subject: [PATCH] compact --- struct/client.js | 12 ++++-------- struct/config/config.js | 2 +- struct/config/streamConfig.js | 4 ++++ struct/funcs/play.js | 14 ++++++-------- 4 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 struct/config/streamConfig.js diff --git a/struct/client.js b/struct/client.js index d93c3bc1..de2a4a96 100644 --- a/struct/client.js +++ b/struct/client.js @@ -59,17 +59,13 @@ module.exports = class extends Client { this.on('ready', () => { require(`${events}ready`).execute(this, Discord); - }); - this.on('message', (msg) => { + }).on('message', (msg) => { require(`${events}msg`).execute(this, msg, Discord); - }); - this.on('guildCreate', (guild) => { + }).on('guildCreate', (guild) => { require(`${events}guildCreate`).execute(this, guild); - }); - this.on('voiceStateUpdate', (oldState, newState) => { + }).on('voiceStateUpdate', (oldState, newState) => { require(`${events}voiceStateUpdate`).execute(this, oldState, newState); - }); - this.on('error', (error) => { + }).on('error', (error) => { client.channels.fetch(client.config.debug_channel).send(`Error: ${error} on shard: ${this.shard}`); }); diff --git a/struct/config/config.js b/struct/config/config.js index cc4a3883..9890c7ab 100644 --- a/struct/config/config.js +++ b/struct/config/config.js @@ -11,7 +11,7 @@ module.exports = { devId: "360363051792203779", embedColor: "#b50002", invite: "https://discordapp.com/api/oauth2/authorize?client_id=607266889537945605&permissions=3427328&redirect_uri=https%3A%2F%2Fdiscordapp.com%2Foauth2%2Fauthorize%3Fclient_id%3D607266889537945605%26%3Bscope%3Dbot%26%3Bpermissions%3D0&scope=bot", - devMode: false, + devMode: true, dblApi: false, saveDB: true, shards: 10, diff --git a/struct/config/streamConfig.js b/struct/config/streamConfig.js new file mode 100644 index 00000000..2a0c24ad --- /dev/null +++ b/struct/config/streamConfig.js @@ -0,0 +1,4 @@ +module.exports = { + ytdlOptions: { filter: "audio", highWaterMark: 1 << 25, volume: false/*, begin: seek*/ }, + options: { seek: 0, bitrate: 1024, passes: 10, volume: 1/*, bassboost: queue.bass*/ } +}; \ No newline at end of file diff --git a/struct/funcs/play.js b/struct/funcs/play.js index da967ad7..1730497b 100644 --- a/struct/funcs/play.js +++ b/struct/funcs/play.js @@ -1,6 +1,7 @@ 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 queue = client.queue.get(guild.id); @@ -10,16 +11,13 @@ module.exports = async function (guild, song, client, seek, play) { return; } const dispatcher = queue.connection - .play(await ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25, volume: false, begin: seek }), { seek: 0, bitrate: 1024, passes: 10, volume: 1, bassboost: queue.bass }) - .on("finish", () => { + .play(await ytdl(song.url, streamConfig.ytdlOptions), 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.on('start', () => { - dispatcher.player.streamingData.pausedTime = 0; - }); - dispatcher.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));