[CodeFactor] Apply fixes

pull/33/head
codefactor-io 6 years ago
parent d3e1106d70
commit 742848f36f

@ -32,9 +32,9 @@ exports.DJ = class {
connect(voiceChannel) { connect(voiceChannel) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.voiceChannel = voiceChannel || this.voiceChannel; this.voiceChannel = voiceChannel || this.voiceChannel;
if (this.connected) { if (this.connected)
this.stop(); this.stop();
}
logger.verbose(`Connecting to voiceChannel ${this.voiceChannel.name}`); logger.verbose(`Connecting to voiceChannel ${this.voiceChannel.name}`);
this.voiceChannel.join().then(connection => { this.voiceChannel.join().then(connection => {
logger.info(`Connected to Voicechannel ${this.voiceChannel.name}`); logger.info(`Connected to Voicechannel ${this.voiceChannel.name}`);
@ -42,7 +42,7 @@ exports.DJ = class {
this.checkListeners(); this.checkListeners();
resolve(); resolve();
}).catch((error) => reject(error)); }).catch((error) => reject(error));
}) });
} }
/** /**
@ -51,9 +51,9 @@ exports.DJ = class {
*/ */
set listenOnRepeat(value) { set listenOnRepeat(value) {
this.repeat = value; this.repeat = value;
if (this.current) { if (this.current)
this.queue.push(this.current); this.queue.push(this.current);
}
} }
/** /**
@ -99,8 +99,9 @@ exports.DJ = class {
logger.verbose(`Exiting ${this.voiceChannel.name}`); logger.verbose(`Exiting ${this.voiceChannel.name}`);
this.stop(); this.stop();
}, config.music.timeout || 300000); }, config.music.timeout || 300000);
} else if (this.connected) } else if (this.connected) {
setTimeout(() => this.checkListeners(), 10000); setTimeout(() => this.checkListeners(), 10000);
}
} }
/** /**
@ -159,15 +160,15 @@ exports.DJ = class {
}); });
} else { } else {
logger.debug(`Added ${url} to the queue`); logger.debug(`Added ${url} to the queue`);
if (playnext) { if (playnext)
this.getVideoName(url).then((title) => { this.getVideoName(url).then((title) => {
this.queue.unshift({'url': url, 'title': title}); this.queue.unshift({'url': url, 'title': title});
}).catch((err) => logger.verbose(err.message)); }).catch((err) => logger.verbose(err.message));
} else { else
this.getVideoName(url).then((title) => { this.getVideoName(url).then((title) => {
this.queue.push({'url': url, 'title': title}); this.queue.push({'url': url, 'title': title});
}).catch((err) => logger.verbose(err.message)); }).catch((err) => logger.verbose(err.message));
}
} }
} }
} }
@ -200,7 +201,7 @@ exports.DJ = class {
this.volume = percentage; this.volume = percentage;
this.disp.setVolume(percentage); this.disp.setVolume(percentage);
} else { } else {
logger.warn("No dispatcher found.") logger.warn("No dispatcher found.");
} }
} }
@ -209,11 +210,11 @@ exports.DJ = class {
*/ */
pause() { pause() {
logger.verbose("Pausing music..."); logger.verbose("Pausing music...");
if (this.disp !== null) { if (this.disp !== null)
this.disp.pause(); this.disp.pause();
} else { else
logger.warn("No dispatcher found"); logger.warn("No dispatcher found");
}
} }
/** /**
@ -221,11 +222,11 @@ exports.DJ = class {
*/ */
resume() { resume() {
logger.verbose("Resuming music..."); logger.verbose("Resuming music...");
if (this.disp !== null) { if (this.disp !== null)
this.disp.resume(); this.disp.resume();
} else { else
logger.warn("No dispatcher found"); logger.warn("No dispatcher found");
}
} }
/** /**
@ -340,13 +341,13 @@ exports.playFile = function (guildId, filename) {
*/ */
exports.play = function (voiceChannel, url) { exports.play = function (voiceChannel, url) {
let guildId = voiceChannel.guild.id; let guildId = voiceChannel.guild.id;
if (!djs[guildId]) { if (!djs[guildId])
this.connect(voiceChannel).then(() => { this.connect(voiceChannel).then(() => {
djs[guildId].playYouTube(url); djs[guildId].playYouTube(url);
}); });
} else { else
djs[guildId].playYouTube(url); djs[guildId].playYouTube(url);
}
}; };
/** /**
@ -357,13 +358,13 @@ exports.play = function (voiceChannel, url) {
*/ */
exports.playnext = function (voiceChannel, url) { exports.playnext = function (voiceChannel, url) {
let guildId = voiceChannel.guild.id; let guildId = voiceChannel.guild.id;
if (!djs[guildId]) { if (!djs[guildId])
this.connect(voiceChannel).then(() => { this.connect(voiceChannel).then(() => {
djs[guildId].playYouTube(url, true); djs[guildId].playYouTube(url, true);
}); });
} else { else
djs[guildId].playYouTube(url, true); djs[guildId].playYouTube(url, true);
}
}; };
/** /**

@ -80,9 +80,9 @@ exports.MockDatabase = class {
} }
run(sql, values, callback) { run(sql, values, callback) {
if(callback) { if(callback)
callback(); callback();
}
} }
get() { get() {
@ -90,7 +90,7 @@ exports.MockDatabase = class {
} }
all() { all() {
return null return null;
} }
close() { close() {

@ -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/VIDID/maxresdefault.jpg', getTh4Id(getVid4Id('VIDID')));
assert('https://i3.ytimg.com/vi/1234/maxresdefault.jpg', getTh4Id(getVid4Id('1234'))); assert('https://i3.ytimg.com/vi/1234/maxresdefault.jpg', getTh4Id(getVid4Id('1234')));
done(); done();
}) });
}); });
describe('#ConfigVerifyer', function() { describe('#ConfigVerifyer', function() {
@ -173,7 +173,7 @@ describe('lib/utils', function() {
confVer = new utils.ConfigVerifyer(testObj, ['key1', 'key1.key2', 'key7.key8.0.key9']); confVer = new utils.ConfigVerifyer(testObj, ['key1', 'key1.key2', 'key7.key8.0.key9']);
assert(!confVer.verifyConfig(modifiedMockLogger)); assert(!confVer.verifyConfig(modifiedMockLogger));
done(); done();
}) });
}); });
}); });
@ -239,7 +239,7 @@ describe('lib/music', function() {
dj.getVideoName('http://www.youtube.com/watch?v=ABCDEFGHIJK').then((name) => { dj.getVideoName('http://www.youtube.com/watch?v=ABCDEFGHIJK').then((name) => {
assert(name === 'test'); assert(name === 'test');
done(); done();
}) });
}); });
it('sets the volume', function(done) { it('sets the volume', function(done) {
@ -249,7 +249,7 @@ describe('lib/music', function() {
dj.setVolume(100); dj.setVolume(100);
assert(dj.volume === 100); assert(dj.volume === 100);
done(); done();
}) });
}); });
it('pauses playback', function(done) { it('pauses playback', function(done) {
@ -258,7 +258,7 @@ describe('lib/music', function() {
dj.playFile(); dj.playFile();
dj.pause(); dj.pause();
done(); done();
}) });
}); });
it('resumes playback', function(done) { it('resumes playback', function(done) {
@ -267,7 +267,7 @@ describe('lib/music', function() {
dj.playFile(); dj.playFile();
dj.resume(); dj.resume();
done(); done();
}) });
}); });
it('stops playback', function(done) { it('stops playback', function(done) {
@ -319,7 +319,7 @@ describe('lib/music', function() {
assert(dj.queue.length === 0); assert(dj.queue.length === 0);
done(); done();
}).catch(() => done()); }).catch(() => done());
}) });
}); });
}); });
@ -344,7 +344,7 @@ describe('lib/cmd', function() {
servant.createCommand(mockobjects.mockCommand, mockobjects.mockCommand.textReply); servant.createCommand(mockobjects.mockCommand, mockobjects.mockCommand.textReply);
assert(servant.commands['test']); assert(servant.commands['test']);
servant.removeCommand('test'); servant.removeCommand('test');
assert(!servant.commands['test']) assert(!servant.commands['test']);
}); });
it('parses commands', function() { it('parses commands', function() {
@ -454,7 +454,7 @@ describe('lib/guilding', function() {
gh.dj = new music.DJ(mockobjects.mockVoicechannel); gh.dj = new music.DJ(mockobjects.mockVoicechannel);
gh.connectAndPlay(mockobjects.mockVoicechannel, 'test', false).then(() => { gh.connectAndPlay(mockobjects.mockVoicechannel, 'test', false).then(() => {
done(); done();
}) });
}); });
it('handles all servercommands', function() { 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])) { for (let command of Object.keys(servercommands[category])) {
msg.content = '~' + command; msg.content = '~' + command;
gh.handleMessage(msg); gh.handleMessage(msg);
} }
}
assert(msgSpy.called); assert(msgSpy.called);
}); });

Loading…
Cancel
Save