Skip to content

Commit 6059f30

Browse files
authored
commands: whisper now rejects errors (#410)
* fix: client.whisper() now rejects when an error occurs * Adds errorCommands to whisper test
1 parent 6c1775c commit 6059f30

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

lib/client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ client.prototype.handleMessage = function handleMessage(message) {
583583
"_promiseSubscribers",
584584
"_promiseSubscribersoff",
585585
"_promiseEmoteonly",
586-
"_promiseEmoteonlyoff"
586+
"_promiseEmoteonlyoff",
587+
"_promiseWhisper"
587588
], [noticeArr, [msgid, channel]]);
588589
break;
589590

lib/commands.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,16 @@ module.exports = {
544544

545545
// Send the command to the server and race the Promise against a delay..
546546
return this._sendCommand(this._getPromiseDelay(), "#tmijs", `/w ${username} ${message}`, (resolve, reject) => {
547+
this.once("_promiseWhisper", (err) => {
548+
if (err) { reject(err); }
549+
});
550+
}).catch((error) => {
551+
// Either an "actual" error occured or the timeout triggered
552+
// the latter means no errors have occured and we can resolve
553+
// else just elevate the error
554+
if (error !== "No response from Twitch.") {
555+
throw error;
556+
}
547557
var from = _.channel(username),
548558
userstate = _.merge({
549559
"message-type": "whisper",
@@ -557,10 +567,7 @@ module.exports = {
557567
[from, userstate, message, true],
558568
[from, userstate, message, true]
559569
]);
560-
561-
// At this time, there is no possible way to detect if a message has been sent has been eaten
562-
// by the server, so we can only resolve the Promise.
563-
resolve([username, message]);
570+
return [username, message];
564571
});
565572
}
566573
}

test/commands.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ var tests = [{
398398
inputParams: ['moddymcmodface', 'You got unmodded! D:'],
399399
returnedParams: ['moddymcmodface', 'You got unmodded! D:'],
400400
serverTest: '/w',
401-
serverCommand: ':tmi.twitch.tv WHISPER moddymcmodface :You got unmodded! D:'
401+
serverCommand: ':tmi.twitch.tv WHISPER moddymcmodface :You got unmodded! D:',
402+
errorCommands: [
403+
no_permission,
404+
]
402405
}];
403406

404407
describe('commands (justinfan)', function() {

0 commit comments

Comments
 (0)