Skip to content

Commit 2a66500

Browse files
committed
client: pass null for default delay
1 parent ee4c347 commit 2a66500

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

lib/client.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,10 @@ client.prototype._sendCommand = function _sendCommand(delay, channel, command, f
13181318
// Disconnected from server..
13191319
return reject('Not connected to server.');
13201320
}
1321-
else if(typeof delay === 'number') {
1321+
else if(delay === null || typeof delay === 'number') {
1322+
if(delay === null) {
1323+
delay = this._getPromiseDelay();
1324+
}
13221325
_.promiseDelay(delay).then(() => reject('No response from Twitch.'));
13231326
}
13241327

@@ -1328,8 +1331,6 @@ client.prototype._sendCommand = function _sendCommand(delay, channel, command, f
13281331
this.log.info(`[${chan}] Executing command: ${command}`);
13291332
this.ws.send(`PRIVMSG ${chan} :${command}`);
13301333
}
1331-
1332-
13331334
// Executing a raw command..
13341335
else {
13351336
this.log.info(`Executing command: ${command}`);

lib/commands.js

+36-36
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function followersonly(channel, minutes) {
55
channel = _.channel(channel);
66
minutes = _.get(minutes, 30);
77
// Send the command to the server and race the Promise against a delay..
8-
return this._sendCommand(this._getPromiseDelay(), channel, `/followers ${minutes}`, (resolve, reject) => {
8+
return this._sendCommand(null, channel, `/followers ${minutes}`, (resolve, reject) => {
99
// Received _promiseFollowers event, resolve or reject..
1010
this.once('_promiseFollowers', err => {
1111
if(!err) { resolve([ channel, ~~minutes ]); }
@@ -18,7 +18,7 @@ function followersonly(channel, minutes) {
1818
function followersonlyoff(channel) {
1919
channel = _.channel(channel);
2020
// Send the command to the server and race the Promise against a delay..
21-
return this._sendCommand(this._getPromiseDelay(), channel, '/followersoff', (resolve, reject) => {
21+
return this._sendCommand(null, channel, '/followersoff', (resolve, reject) => {
2222
// Received _promiseFollowersoff event, resolve or reject..
2323
this.once('_promiseFollowersoff', err => {
2424
if(!err) { resolve([ channel ]); }
@@ -31,7 +31,7 @@ function followersonlyoff(channel) {
3131
function part(channel) {
3232
channel = _.channel(channel);
3333
// Send the command to the server and race the Promise against a delay..
34-
return this._sendCommand(this._getPromiseDelay(), null, `PART ${channel}`, (resolve, reject) => {
34+
return this._sendCommand(null, null, `PART ${channel}`, (resolve, reject) => {
3535
// Received _promisePart event, resolve or reject..
3636
this.once('_promisePart', err => {
3737
if(!err) { resolve([ channel ]); }
@@ -44,7 +44,7 @@ function part(channel) {
4444
function r9kbeta(channel) {
4545
channel = _.channel(channel);
4646
// Send the command to the server and race the Promise against a delay..
47-
return this._sendCommand(this._getPromiseDelay(), channel, '/r9kbeta', (resolve, reject) => {
47+
return this._sendCommand(null, channel, '/r9kbeta', (resolve, reject) => {
4848
// Received _promiseR9kbeta event, resolve or reject..
4949
this.once('_promiseR9kbeta', err => {
5050
if(!err) { resolve([ channel ]); }
@@ -57,7 +57,7 @@ function r9kbeta(channel) {
5757
function r9kbetaoff(channel) {
5858
channel = _.channel(channel);
5959
// Send the command to the server and race the Promise against a delay..
60-
return this._sendCommand(this._getPromiseDelay(), channel, '/r9kbetaoff', (resolve, reject) => {
60+
return this._sendCommand(null, channel, '/r9kbetaoff', (resolve, reject) => {
6161
// Received _promiseR9kbetaoff event, resolve or reject..
6262
this.once('_promiseR9kbetaoff', err => {
6363
if(!err) { resolve([ channel ]); }
@@ -71,7 +71,7 @@ function slow(channel, seconds) {
7171
channel = _.channel(channel);
7272
seconds = _.get(seconds, 300);
7373
// Send the command to the server and race the Promise against a delay..
74-
return this._sendCommand(this._getPromiseDelay(), channel, `/slow ${seconds}`, (resolve, reject) => {
74+
return this._sendCommand(null, channel, `/slow ${seconds}`, (resolve, reject) => {
7575
// Received _promiseSlow event, resolve or reject..
7676
this.once('_promiseSlow', err => {
7777
if(!err) { resolve([ channel, ~~seconds ]); }
@@ -84,7 +84,7 @@ function slow(channel, seconds) {
8484
function slowoff(channel) {
8585
channel = _.channel(channel);
8686
// Send the command to the server and race the Promise against a delay..
87-
return this._sendCommand(this._getPromiseDelay(), channel, '/slowoff', (resolve, reject) => {
87+
return this._sendCommand(null, channel, '/slowoff', (resolve, reject) => {
8888
// Received _promiseSlowoff event, resolve or reject..
8989
this.once('_promiseSlowoff', err => {
9090
if(!err) { resolve([ channel ]); }
@@ -112,7 +112,7 @@ module.exports = {
112112
username = _.username(username);
113113
reason = _.get(reason, '');
114114
// Send the command to the server and race the Promise against a delay..
115-
return this._sendCommand(this._getPromiseDelay(), channel, `/ban ${username} ${reason}`, (resolve, reject) => {
115+
return this._sendCommand(null, channel, `/ban ${username} ${reason}`, (resolve, reject) => {
116116
// Received _promiseBan event, resolve or reject..
117117
this.once('_promiseBan', err => {
118118
if(!err) { resolve([ channel, username, reason ]); }
@@ -125,7 +125,7 @@ module.exports = {
125125
clear(channel) {
126126
channel = _.channel(channel);
127127
// Send the command to the server and race the Promise against a delay..
128-
return this._sendCommand(this._getPromiseDelay(), channel, '/clear', (resolve, reject) => {
128+
return this._sendCommand(null, channel, '/clear', (resolve, reject) => {
129129
// Received _promiseClear event, resolve or reject..
130130
this.once('_promiseClear', err => {
131131
if(!err) { resolve([ channel ]); }
@@ -138,7 +138,7 @@ module.exports = {
138138
color(channel, newColor) {
139139
newColor = _.get(newColor, channel);
140140
// Send the command to the server and race the Promise against a delay..
141-
return this._sendCommand(this._getPromiseDelay(), '#tmijs', `/color ${newColor}`, (resolve, reject) => {
141+
return this._sendCommand(null, '#tmijs', `/color ${newColor}`, (resolve, reject) => {
142142
// Received _promiseColor event, resolve or reject..
143143
this.once('_promiseColor', err => {
144144
if(!err) { resolve([ newColor ]); }
@@ -152,7 +152,7 @@ module.exports = {
152152
channel = _.channel(channel);
153153
seconds = _.get(seconds, 30);
154154
// Send the command to the server and race the Promise against a delay..
155-
return this._sendCommand(this._getPromiseDelay(), channel, `/commercial ${seconds}`, (resolve, reject) => {
155+
return this._sendCommand(null, channel, `/commercial ${seconds}`, (resolve, reject) => {
156156
// Received _promiseCommercial event, resolve or reject..
157157
this.once('_promiseCommercial', err => {
158158
if(!err) { resolve([ channel, ~~seconds ]); }
@@ -165,7 +165,7 @@ module.exports = {
165165
deletemessage(channel, messageUUID) {
166166
channel = _.channel(channel);
167167
// Send the command to the server and race the Promise against a delay..
168-
return this._sendCommand(this._getPromiseDelay(), channel, `/delete ${messageUUID}`, (resolve, reject) => {
168+
return this._sendCommand(null, channel, `/delete ${messageUUID}`, (resolve, reject) => {
169169
// Received _promiseDeletemessage event, resolve or reject..
170170
this.once('_promiseDeletemessage', err => {
171171
if(!err) { resolve([ channel ]); }
@@ -178,7 +178,7 @@ module.exports = {
178178
emoteonly(channel) {
179179
channel = _.channel(channel);
180180
// Send the command to the server and race the Promise against a delay..
181-
return this._sendCommand(this._getPromiseDelay(), channel, '/emoteonly', (resolve, reject) => {
181+
return this._sendCommand(null, channel, '/emoteonly', (resolve, reject) => {
182182
// Received _promiseEmoteonly event, resolve or reject..
183183
this.once('_promiseEmoteonly', err => {
184184
if(!err) { resolve([ channel ]); }
@@ -191,7 +191,7 @@ module.exports = {
191191
emoteonlyoff(channel) {
192192
channel = _.channel(channel);
193193
// Send the command to the server and race the Promise against a delay..
194-
return this._sendCommand(this._getPromiseDelay(), channel, '/emoteonlyoff', (resolve, reject) => {
194+
return this._sendCommand(null, channel, '/emoteonlyoff', (resolve, reject) => {
195195
// Received _promiseEmoteonlyoff event, resolve or reject..
196196
this.once('_promiseEmoteonlyoff', err => {
197197
if(!err) { resolve([ channel ]); }
@@ -201,13 +201,13 @@ module.exports = {
201201
},
202202

203203
// Enable followers-only mode on a channel..
204-
followersonly: followersonly,
204+
followersonly,
205205

206206
// Alias for followersonly()..
207207
followersmode: followersonly,
208208

209209
// Disable followers-only mode on a channel..
210-
followersonlyoff: followersonlyoff,
210+
followersonlyoff,
211211

212212
// Alias for followersonlyoff()..
213213
followersmodeoff: followersonlyoff,
@@ -230,7 +230,7 @@ module.exports = {
230230
join(channel) {
231231
channel = _.channel(channel);
232232
// Send the command to the server ..
233-
return this._sendCommand(null, null, `JOIN ${channel}`, (resolve, reject) => {
233+
return this._sendCommand(undefined, null, `JOIN ${channel}`, (resolve, reject) => {
234234
const eventName = '_promiseJoin';
235235
let hasFulfilled = false;
236236
const listener = (err, joinedChannel) => {
@@ -258,7 +258,7 @@ module.exports = {
258258
channel = _.channel(channel);
259259
username = _.username(username);
260260
// Send the command to the server and race the Promise against a delay..
261-
return this._sendCommand(this._getPromiseDelay(), channel, `/mod ${username}`, (resolve, reject) => {
261+
return this._sendCommand(null, channel, `/mod ${username}`, (resolve, reject) => {
262262
// Received _promiseMod event, resolve or reject..
263263
this.once('_promiseMod', err => {
264264
if(!err) { resolve([ channel, username ]); }
@@ -271,7 +271,7 @@ module.exports = {
271271
mods(channel) {
272272
channel = _.channel(channel);
273273
// Send the command to the server and race the Promise against a delay..
274-
return this._sendCommand(this._getPromiseDelay(), channel, '/mods', (resolve, reject) => {
274+
return this._sendCommand(null, channel, '/mods', (resolve, reject) => {
275275
// Received _promiseMods event, resolve or reject..
276276
this.once('_promiseMods', (err, mods) => {
277277
if(!err) {
@@ -288,15 +288,15 @@ module.exports = {
288288
},
289289

290290
// Leave a channel..
291-
part: part,
291+
part,
292292

293293
// Alias for part()..
294294
leave: part,
295295

296296
// Send a ping to the server..
297297
ping() {
298298
// Send the command to the server and race the Promise against a delay..
299-
return this._sendCommand(this._getPromiseDelay(), null, 'PING', (resolve, _reject) => {
299+
return this._sendCommand(null, null, 'PING', (resolve, _reject) => {
300300
// Update the internal ping timeout check interval..
301301
this.latency = new Date();
302302
this.pingTimeout = setTimeout(() => {
@@ -316,21 +316,21 @@ module.exports = {
316316
},
317317

318318
// Enable R9KBeta mode on a channel..
319-
r9kbeta: r9kbeta,
319+
r9kbeta,
320320

321321
// Alias for r9kbeta()..
322322
r9kmode: r9kbeta,
323323

324324
// Disable R9KBeta mode on a channel..
325-
r9kbetaoff: r9kbetaoff,
325+
r9kbetaoff,
326326

327327
// Alias for r9kbetaoff()..
328328
r9kmodeoff: r9kbetaoff,
329329

330330
// Send a raw message to the server..
331331
raw(message) {
332332
// Send the command to the server and race the Promise against a delay..
333-
return this._sendCommand(this._getPromiseDelay(), null, message, (resolve, _reject) => {
333+
return this._sendCommand(null, null, message, (resolve, _reject) => {
334334
resolve([ message ]);
335335
});
336336
},
@@ -346,7 +346,7 @@ module.exports = {
346346
}
347347
else {
348348
// Send the command to the server and race the Promise against a delay..
349-
return this._sendCommand(this._getPromiseDelay(), channel, message, (resolve, _reject) => {
349+
return this._sendCommand(null, channel, message, (resolve, _reject) => {
350350
// At this time, there is no possible way to detect if a message has been sent has been eaten
351351
// by the server, so we can only resolve the Promise.
352352
resolve([ channel, message ]);
@@ -362,13 +362,13 @@ module.exports = {
362362
},
363363

364364
// Enable slow mode on a channel..
365-
slow: slow,
365+
slow,
366366

367367
// Alias for slow()..
368368
slowmode: slow,
369369

370370
// Disable slow mode on a channel..
371-
slowoff: slowoff,
371+
slowoff,
372372

373373
// Alias for slowoff()..
374374
slowmodeoff: slowoff,
@@ -377,7 +377,7 @@ module.exports = {
377377
subscribers(channel) {
378378
channel = _.channel(channel);
379379
// Send the command to the server and race the Promise against a delay..
380-
return this._sendCommand(this._getPromiseDelay(), channel, '/subscribers', (resolve, reject) => {
380+
return this._sendCommand(null, channel, '/subscribers', (resolve, reject) => {
381381
// Received _promiseSubscribers event, resolve or reject..
382382
this.once('_promiseSubscribers', err => {
383383
if(!err) { resolve([ channel ]); }
@@ -390,7 +390,7 @@ module.exports = {
390390
subscribersoff(channel) {
391391
channel = _.channel(channel);
392392
// Send the command to the server and race the Promise against a delay..
393-
return this._sendCommand(this._getPromiseDelay(), channel, '/subscribersoff', (resolve, reject) => {
393+
return this._sendCommand(null, channel, '/subscribersoff', (resolve, reject) => {
394394
// Received _promiseSubscribersoff event, resolve or reject..
395395
this.once('_promiseSubscribersoff', err => {
396396
if(!err) { resolve([ channel ]); }
@@ -412,7 +412,7 @@ module.exports = {
412412
seconds = _.get(seconds, 300);
413413
reason = _.get(reason, '');
414414
// Send the command to the server and race the Promise against a delay..
415-
return this._sendCommand(this._getPromiseDelay(), channel, `/timeout ${username} ${seconds} ${reason}`, (resolve, reject) => {
415+
return this._sendCommand(null, channel, `/timeout ${username} ${seconds} ${reason}`, (resolve, reject) => {
416416
// Received _promiseTimeout event, resolve or reject..
417417
this.once('_promiseTimeout', err => {
418418
if(!err) { resolve([ channel, username, ~~seconds, reason ]); }
@@ -426,7 +426,7 @@ module.exports = {
426426
channel = _.channel(channel);
427427
username = _.username(username);
428428
// Send the command to the server and race the Promise against a delay..
429-
return this._sendCommand(this._getPromiseDelay(), channel, `/unban ${username}`, (resolve, reject) => {
429+
return this._sendCommand(null, channel, `/unban ${username}`, (resolve, reject) => {
430430
// Received _promiseUnban event, resolve or reject..
431431
this.once('_promiseUnban', err => {
432432
if(!err) { resolve([ channel, username ]); }
@@ -453,7 +453,7 @@ module.exports = {
453453
channel = _.channel(channel);
454454
username = _.username(username);
455455
// Send the command to the server and race the Promise against a delay..
456-
return this._sendCommand(this._getPromiseDelay(), channel, `/unmod ${username}`, (resolve, reject) => {
456+
return this._sendCommand(null, channel, `/unmod ${username}`, (resolve, reject) => {
457457
// Received _promiseUnmod event, resolve or reject..
458458
this.once('_promiseUnmod', err => {
459459
if(!err) { resolve([ channel, username ]); }
@@ -467,7 +467,7 @@ module.exports = {
467467
channel = _.channel(channel);
468468
username = _.username(username);
469469
// Send the command to the server and race the Promise against a delay..
470-
return this._sendCommand(this._getPromiseDelay(), channel, `/unvip ${username}`, (resolve, reject) => {
470+
return this._sendCommand(null, channel, `/unvip ${username}`, (resolve, reject) => {
471471
// Received _promiseUnvip event, resolve or reject..
472472
this.once('_promiseUnvip', err => {
473473
if(!err) { resolve([ channel, username ]); }
@@ -481,7 +481,7 @@ module.exports = {
481481
channel = _.channel(channel);
482482
username = _.username(username);
483483
// Send the command to the server and race the Promise against a delay..
484-
return this._sendCommand(this._getPromiseDelay(), channel, `/vip ${username}`, (resolve, reject) => {
484+
return this._sendCommand(null, channel, `/vip ${username}`, (resolve, reject) => {
485485
// Received _promiseVip event, resolve or reject..
486486
this.once('_promiseVip', err => {
487487
if(!err) { resolve([ channel, username ]); }
@@ -494,7 +494,7 @@ module.exports = {
494494
vips(channel) {
495495
channel = _.channel(channel);
496496
// Send the command to the server and race the Promise against a delay..
497-
return this._sendCommand(this._getPromiseDelay(), channel, '/vips', (resolve, reject) => {
497+
return this._sendCommand(null, channel, '/vips', (resolve, reject) => {
498498
// Received _promiseVips event, resolve or reject..
499499
this.once('_promiseVips', (err, vips) => {
500500
if(!err) { resolve(vips); }
@@ -512,7 +512,7 @@ module.exports = {
512512
return Promise.reject('Cannot send a whisper to the same account.');
513513
}
514514
// Send the command to the server and race the Promise against a delay..
515-
return this._sendCommand(this._getPromiseDelay(), '#tmijs', `/w ${username} ${message}`, (_resolve, reject) => {
515+
return this._sendCommand(null, '#tmijs', `/w ${username} ${message}`, (_resolve, reject) => {
516516
this.once('_promiseWhisper', err => {
517517
if (err) { reject(err); }
518518
});

0 commit comments

Comments
 (0)