From 742848f36f41bbf3e40abd535d96779c1ced2229 Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Fri, 8 Feb 2019 20:37:09 +0000 Subject: [PATCH] [CodeFactor] Apply fixes --- lib/music.js | 47 +++++++++++++++++++++++---------------------- test/mockobjects.js | 6 +++--- test/test.js | 22 ++++++++++----------- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/lib/music.js b/lib/music.js index d9cefcf..bf10d9b 100644 --- a/lib/music.js +++ b/lib/music.js @@ -32,9 +32,9 @@ exports.DJ = class { connect(voiceChannel) { return new Promise((resolve, reject) => { this.voiceChannel = voiceChannel || this.voiceChannel; - if (this.connected) { + if (this.connected) this.stop(); - } + logger.verbose(`Connecting to voiceChannel ${this.voiceChannel.name}`); this.voiceChannel.join().then(connection => { logger.info(`Connected to Voicechannel ${this.voiceChannel.name}`); @@ -42,7 +42,7 @@ exports.DJ = class { this.checkListeners(); resolve(); }).catch((error) => reject(error)); - }) + }); } /** @@ -51,9 +51,9 @@ exports.DJ = class { */ set listenOnRepeat(value) { this.repeat = value; - if (this.current) { + if (this.current) this.queue.push(this.current); - } + } /** @@ -99,8 +99,9 @@ exports.DJ = class { logger.verbose(`Exiting ${this.voiceChannel.name}`); this.stop(); }, config.music.timeout || 300000); - } else if (this.connected) - setTimeout(() => this.checkListeners(), 10000); + } else if (this.connected) { +setTimeout(() => this.checkListeners(), 10000); +} } /** @@ -159,15 +160,15 @@ exports.DJ = class { }); } else { logger.debug(`Added ${url} to the queue`); - if (playnext) { + if (playnext) this.getVideoName(url).then((title) => { this.queue.unshift({'url': url, 'title': title}); }).catch((err) => logger.verbose(err.message)); - } else { + else this.getVideoName(url).then((title) => { this.queue.push({'url': url, 'title': title}); }).catch((err) => logger.verbose(err.message)); - } + } } } @@ -200,7 +201,7 @@ exports.DJ = class { this.volume = percentage; this.disp.setVolume(percentage); } else { - logger.warn("No dispatcher found.") + logger.warn("No dispatcher found."); } } @@ -209,11 +210,11 @@ exports.DJ = class { */ pause() { logger.verbose("Pausing music..."); - if (this.disp !== null) { + if (this.disp !== null) this.disp.pause(); - } else { + else logger.warn("No dispatcher found"); - } + } /** @@ -221,11 +222,11 @@ exports.DJ = class { */ resume() { logger.verbose("Resuming music..."); - if (this.disp !== null) { + if (this.disp !== null) this.disp.resume(); - } else { + else logger.warn("No dispatcher found"); - } + } /** @@ -340,13 +341,13 @@ exports.playFile = function (guildId, filename) { */ exports.play = function (voiceChannel, url) { let guildId = voiceChannel.guild.id; - if (!djs[guildId]) { + if (!djs[guildId]) this.connect(voiceChannel).then(() => { djs[guildId].playYouTube(url); }); - } else { + else djs[guildId].playYouTube(url); - } + }; /** @@ -357,13 +358,13 @@ exports.play = function (voiceChannel, url) { */ exports.playnext = function (voiceChannel, url) { let guildId = voiceChannel.guild.id; - if (!djs[guildId]) { + if (!djs[guildId]) this.connect(voiceChannel).then(() => { djs[guildId].playYouTube(url, true); }); - } else { + else djs[guildId].playYouTube(url, true); - } + }; /** diff --git a/test/mockobjects.js b/test/mockobjects.js index 62da037..ece4ab5 100644 --- a/test/mockobjects.js +++ b/test/mockobjects.js @@ -80,9 +80,9 @@ exports.MockDatabase = class { } run(sql, values, callback) { - if(callback) { + if(callback) callback(); - } + } get() { @@ -90,7 +90,7 @@ exports.MockDatabase = class { } all() { - return null + return null; } close() { diff --git a/test/test.js b/test/test.js index 924568a..5d44af0 100644 --- a/test/test.js +++ b/test/test.js @@ -135,7 +135,7 @@ describe('lib/utils', function() { assert('https://i3.ytimg.com/vi/VIDID/maxresdefault.jpg', getTh4Id(getVid4Id('VIDID'))); assert('https://i3.ytimg.com/vi/1234/maxresdefault.jpg', getTh4Id(getVid4Id('1234'))); done(); - }) + }); }); describe('#ConfigVerifyer', function() { @@ -173,7 +173,7 @@ describe('lib/utils', function() { confVer = new utils.ConfigVerifyer(testObj, ['key1', 'key1.key2', 'key7.key8.0.key9']); assert(!confVer.verifyConfig(modifiedMockLogger)); done(); - }) + }); }); }); @@ -239,7 +239,7 @@ describe('lib/music', function() { dj.getVideoName('http://www.youtube.com/watch?v=ABCDEFGHIJK').then((name) => { assert(name === 'test'); done(); - }) + }); }); it('sets the volume', function(done) { @@ -249,7 +249,7 @@ describe('lib/music', function() { dj.setVolume(100); assert(dj.volume === 100); done(); - }) + }); }); it('pauses playback', function(done) { @@ -258,7 +258,7 @@ describe('lib/music', function() { dj.playFile(); dj.pause(); done(); - }) + }); }); it('resumes playback', function(done) { @@ -267,7 +267,7 @@ describe('lib/music', function() { dj.playFile(); dj.resume(); done(); - }) + }); }); it('stops playback', function(done) { @@ -319,7 +319,7 @@ describe('lib/music', function() { assert(dj.queue.length === 0); done(); }).catch(() => done()); - }) + }); }); }); @@ -344,7 +344,7 @@ describe('lib/cmd', function() { servant.createCommand(mockobjects.mockCommand, mockobjects.mockCommand.textReply); assert(servant.commands['test']); servant.removeCommand('test'); - assert(!servant.commands['test']) + assert(!servant.commands['test']); }); it('parses commands', function() { @@ -454,7 +454,7 @@ describe('lib/guilding', function() { gh.dj = new music.DJ(mockobjects.mockVoicechannel); gh.connectAndPlay(mockobjects.mockVoicechannel, 'test', false).then(() => { done(); - }) + }); }); it('handles all servercommands', function() { @@ -474,12 +474,12 @@ describe('lib/guilding', function() { } }; - for (let category of Object.keys(servercommands)) { + for (let category of Object.keys(servercommands)) for (let command of Object.keys(servercommands[category])) { msg.content = '~' + command; gh.handleMessage(msg); } - } + assert(msgSpy.called); });