forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irc.d.ts
885 lines (789 loc) · 27.9 KB
/
irc.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
// Type definitions for irc v0.3.12
// Project: https://github.com/martynsmith/node-irc
// Definitions by: phillips1012 <https://github.com/phillips1012>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node-0.10.d.ts" />
/** This library provides IRC client functionality. */
declare module 'irc' {
import events = require('events');
import crypto = require('crypto');
import net = require('net');
/** This library provides IRC client functionality. */
namespace NodeIRC {
/** A nick connect to an IRC server. */
export class Client extends events.EventEmitter {
/**
* Socket to the server. Rarely, if ever needed. Use Client#send
* instead.
*/
public conn: net.Socket
/**
* Channels joined. Includes channel modes, user list, and topic
* information. Only updated after the server recognizes the join.
*/
public chans: {
[index: string]: {
key: string;
serverName: string;
users: {
[index: string]: string;
};
mode: string;
created: string;
}
}
/** Features supported by the server */
public supported: {
channel: {
idlength: string[];
length: number;
limit: string[];
modes: {
[index: string]: string;
}
types: string;
};
kicklength: number;
maxlist: number[];
maxtargets: string[];
modes: number;
nicklength: number
topiclength: number;
usermodes: string;
}
/**
* The current nick of the client. Updated if the nick changes
*/
public nick: string;
/** Channel listing data. */
public channellist: IChannel[];
/** IRC server MOTD */
public motd: string;
/** Maximum line length */
public maxLineLength: number;
/** Bot options */
public opt: IClientOpts;
/** Host mask */
public hostMask: string;
/**
* Connect to an IRC server
* @param server - server hostname
* @param nick - nickname
* @param opts
*/
constructor(
server: string,
nick: string,
opts?: IClientOpts
);
/**
* Send a raw message to the server; generally speaking, it’s best
* not to use this method unless you know what you’re doing.
* @param command - irc command
* @param args - command arguments (splat)
*/
public send(
command: string,
...args: string[]
): void;
/**
* Join the specified channel
* @param channel - channel to join
* @param callback
*/
public join(
channel: string,
callback?: handlers.IJoinChannel
): void;
/**
* Part the specified channel
* @param channel - channel to part
* @param message - optional message to send
* @param callback
*/
public part(
channel: string,
message: string,
callback: handlers.IPartChannel
): void;
/**
* Send a message to the specified target
* @param target - nick or channel
* @param message - message to send
*/
public say(
target: string,
message: string
): void;
/**
* Send a CTCP message to the specified target
* @param target - nick or channel
* @param type - "privmsg" for PRIVMSG, anything else for NOTICE
* @param text - CTCP message
*/
public ctcp(
target: string,
type: string,
text: string
): void;
/**
* Send an action to the specified target
* @param target - target
* @param message - message
*/
public action(
target: string,
message: string
): void;
/**
* Send a notice to the specified target.
* @param target - nick or channel
* @param message - message to send
*/
public notice(
target: string,
message: string
): void;
/**
* Request a whois for the specified nick
* @param nick - nickname
* @param callback
*/
public whois(
nick: string,
callback: handlers.IWhois
): void;
/**
* Request a channel listing from the server. The arguments for this
* are farily server specific, this method passes them as specified.
*
* Responses from the server are available via `channellist_start`,
* `channellist_item`, and `channellist` events.
*
* @param args - arguments
*/
public list(
...args: string[]
): void;
/**
* Connect to the server. Use when `autoConnect` is false.
* @param retryCount - times to retry
* @param callback
*/
public connect(
retryCount?: number | handlers.IRaw,
callback?: handlers.IRaw
): void;
/**
* Disconnect from the IRC server
* @param message - message to send
* @param callback
*/
public disconnect(
message: string,
callback: () => void
): void;
/**
* Activate flood protection “after the fact”. You can also use
* floodProtection while instantiating the Client to enable flood
* protection, and floodProtectionDelay to set the default message
* interval.
* @param interval - ms to wait between messages
*/
public activateFloodProtection(
interval: number
): void;
}
/** Client options object */
export interface IClientOpts {
/**
* IRC username
* @default 'nodebot'
*/
userName?: string;
/**
* IRC username
* @default ''
*/
password?: string;
/**
* IRC "real name"
* @default 'nodeJS IRC client'
*/
realName?: string;
/**
* IRC connection port. See
* https://nodejs.org/api/net.html#net_socket_remoteport
* @default 6667
*/
port?: number;
/**
* Local interface to bind to for network connections. See
* https://nodejs.org/api/net.html#net_socket_localaddress
*/
localAddress?: string;
/**
* Should we output debug messages to STDOUT?
* @default false
*/
debug?: boolean;
/**
* Should we output IRC errors?
* @default false
*/
showErrors?: boolean;
/**
* Should we auto-rejoin channels?
* @default false
*/
autoRejoin?: boolean;
/**
* Should we auto-reconnect to networks?
* @default true
*/
autoConnect?: boolean;
/**
* Channels to join
* @default []
*/
channels?: string[];
/**
* Should SSL be used? Can either be true or crypto credentials.
* @default false
*/
secure?: boolean | crypto.Credentials;
/**
* Should we accept self-signed certificates?
* @default false
*/
selfSigned?: boolean;
/**
* Should we accept expired certificates?
* @default false
*/
certExpired?: boolean;
/**
* Should we queue our messages to ensure we don't get kicked?
* @default false
*/
floodProtection?: boolean;
/**
* Delay between messages when flood protection is active
* @default 1000
*/
floodProtectionDelay?: number;
/**
* Should we use SASL authentication?
* @default false
*/
sasl?: boolean;
/**
* Should we strip mIRC colors from the output messages?
* @default false
*/
stripColors?: boolean;
/**
* Channel prefix
* @default '&#'
*/
channelPrefixes?: string;
/**
* Characters to split a message at.
* @default 512
*/
messageSplit?: number;
/**
* Encoding to use. See
* https://nodejs.org/api/stream.html#stream_readable_setencoding_encoding
* @default 'utf-8'
*/
encoding?: string;
}
/** Command types */
export enum CommandType {
normal, reply, error
}
/** Parsed IRC message. */
export interface IMessage {
/** Prefix */
prefix?: string;
/** Mapped IRC command */
command: string;
/** Raw IRC command */
rawCommand: string;
/** Command type */
commandType: CommandType;
/** Command arguments */
args: string[];
}
/** Whois data */
export interface IWhoisData {
/** Nickname */
nick: string;
/** Username */
user: string;
/** Hostnamej */
host: string;
/** Real name" */
realname: string;
/** Channels */
channels: string[];
/** Server */
server: string;
/** Server description string */
serverinfo: string;
/** Is this user an operator? */
operator: string;
}
/** A channel returned by a channel listing. */
export interface IChannel {
/** Channel name */
name: string;
/** User count */
users: string;
/** Topic string */
topic: string;
}
/**
* Handler functions for Client.
*/
namespace handlers {
/**
* 'registered': Emitted when the server sends the initial 001 line,
* indicating you’ve connected to the server. See the raw event for
* details on the message object.
*/
export interface IRegistered {
/**
* @param message - raw message
*/
(message: IMessage): void;
}
/**
* 'motd': Emitted when the server sends the message of the day to
* clients.
*/
export interface IMotd {
/**
* @param motd - motd string
*/
(motd: string): void;
}
/**
* 'names': Emitted when the server sends a list of nicks for a channel
* (which happens immediately after joining and on request. The nicks
* object passed to the callback is keyed by nick names, and has
* values ‘’, ‘+’, or ‘@’ depending on the level of that nick in the
* channel.
*/
export interface INames {
/**
* @param channel - channel name
* @param nicks - nicks list
*/
(channel: string, nicks: string[]): void;
}
/**
* 'names#*' As per ‘names’ event but only emits for the subscribed
* channel.
*/
export interface INamesChannel {
/**
* @param channel - channel name
* @param nicks - nicks list
*/
(nicks: string[]): void;
}
/**
* 'topic': Emitted when the server sends the channel topic on joining
* a channel, or when a user changes the topic on a channel. See the
* raw event for details on the message object.
*/
export interface ITopic {
/**
* @param channel - channel name
* @param topic - topic
* @param nick - nick
* @param message - raw message
*/
(
channel: string,
topic: string,
nick: string,
message: IMessage
): void;
}
/**
* 'join': Emitted when a user joins a channel (including when the
* client itself joins a channel). See the raw event for details on the
* message object.
*/
export interface IJoin {
/**
* @param channel - channel name
* @param nick - who joined
* @param message - raw message
*/
(channel: string, nick: string, message: IMessage): void;
}
/**
* 'join#*': As per ‘join’ event but only emits for the subscribed
* channel. See the raw event for details on the message object.
*/
export interface IJoinChannel {
/**
* @param nick - who joined
* @param message - raw message
*/
(nick: string, message: IMessage): void;
}
/**
* 'part': Emitted when a user parts a channel (including when the
* client itself parts a channel). See the raw event for details on the
* message object.
*/
export interface IPart {
/**
* @param channel - channel name
* @param nick - who parted
* @param reason - part reason
* @param message - raw message
*/
(
channel: string,
nick: string,
reason: string,
message: IMessage
): void
}
/**
* 'part': As per ‘part’ event but only emits for the subscribed
* channel. See the raw event for details on the message object.
*/
export interface IPartChannel {
/**
* @param nick - who parted
* @param reason - part reason
* @param message - raw message
*/
(
nick: string,
reason: string,
message: IMessage
): void
}
/**
* 'kick': Emitted when a user is kicked from a channel. See the raw
* event for details on the message object.
*/
export interface IKick {
/**
* @param channel - channel name
* @param nick - who was kicked
* @param by - kicker
* @param reason - kick reason
* @param message - raw message
*/
(
channel: string,
nick: string,
by: string,
reason: string,
message: IMessage
): void;
}
/**
* 'kick#*': Emitted when a user is kicked from a channel. See the raw
* event for details on the message object.
*/
export interface IKickChannel {
/**
* @param nick - who was kicked
* @param by - kicker
* @param reason - kick reason
* @param message - raw message
*/
(
nick: string,
by: string,
reason: string,
message: IMessage
): void;
}
/**
* 'message': Emitted when a message is sent. to can be either a nick
* (which is most likely this clients nick and means a private message),
* or a channel (which means a message to that channel). See the raw
* event for details on the message object.
*/
export interface IRecievedMessage {
/**
* @param nick - who sent the message
* @param to - to whom was the message sent
* @param text - message text
* @param message - raw message
*/
(
nick: string, to: string, text: string, message: IMessage
): void;
}
/**
* 'message#': Emitted when a message is sent to any channel (i.e.
* exactly the same as the message event but excluding private
* messages. See the raw event for details on the message object.
*/
export interface IMessageAllChannels {
/**
* @param nick - who sent the message
* @param to - to whom was the message sent
* @param text - message text
* @param message - raw message
*/
(
nick: string, to: string, text: string, message: IMessage
): void;
}
/**
* 'message#*': As per ‘message’ event but only emits for the
* subscribed channel. See the raw event for details on the message
* object.
*/
export interface IMessageChannel {
/**
* @param nick - who sent the message
* @param text - message text
* @param message - raw message
*/
(nick: string, text: string, message: IMessage): void;
}
/**
* 'selfMessage': Emitted when a message is sent from the client.
* `to` is who the message was sent to. It can be either a nick
* (which most likely means a private message), or a channel (which
* means a message to that channel).
*/
export interface ISelfMessage {
(to: string, text: string): void;
}
/**
* 'notice': Emitted when a notice is sent. to can be either a nick
* (which is most likely this clients nick and means a private
* message), or a channel (which means a message to that channel). nick
* is either the senders nick or null which means that the notice comes
* from the server. See the raw event for details on the message object.
*/
export interface INotice {
/**
* @param nick - from
* @param to - to
* @param text - text
* @param message - raw message
*/
(nick: string, to: string, text: string, message: IMessage): void;
}
/**
* 'ping': Emitted when a server PINGs the client. The client will
* automatically send a PONG request just before this is emitted.
*/
export interface IPing {
/**
* @param server - server that adiministered the ping
*/
(server: string): void;
}
/**
* 'pm': As per ‘message’ event but only emits when the message is
* direct to the client. See the raw event for details on the message
* object.
*/
export interface IPm {
/**
* @param nick - sender
* @param text - message text
* @param message - raw message
*/
(nick: string, text: string, message: IMessage): void;
}
/**
* 'ctcp': Emitted when a CTCP notice or privmsg was received (type
* is either ‘notice’ or ‘privmsg’). See the raw event for details
* on the message object.
*/
export interface ICtcp {
/**
* @param from - sender
* @param to - recievier
* @param text - ctcp text
* @param type - ctcp type
* @param message - raw message
*/
(
from: string,
to: string,
text: string,
type: string,
message: IMessage
): void;
}
/**
* 'ctcp-*': Emitted when a specific type of CTCP request was
* recieved.
*/
export interface ICtcpSpecific {
/**
* @param from - sender
* @param to - recievier
* @param message - raw message
*/
(
from: string,
to: string,
text: string,
message: IMessage
): void;
(
from: string,
to: string,
text: string,
type: string,
message: IMessage
): void;
}
/**
* 'nick': Emitted when a user changes nick along with the channels
* the user is in. See the raw event for details on the message
* object.
*/
export interface INick {
/**
* @param oldnick - old nickname
* @param newnick - new nickname
* @param channels - channels the nick changed in
* @param message - raw message
*/
(
oldnick: string,
newnick: string,
channels: string[],
message: IMessage
): void;
}
/**
* 'invite': Emitted when the client receives an /invite. See the
* raw event for details on the message object.
*/
export interface IInvite {
/**
* @param channel - channel user was invited to
* @param from - user who invited
* @param message - raw message
*/
(channel: string, from: string, message: IMessage): void;
}
/**
* '+mode'/'-mode': Emitted when a mode is added or removed from a user or
* channel. channel is the channel which the mode is being set on/in
* . by is the user setting the mode. mode is the single character
* mode identifier. If the mode is being set on a user, argument is
* the nick of the user. If the mode is being set on a channel,
* argument is the argument to the mode. If a channel mode doesn’t
* have any arguments, argument will be ‘undefined’. See the raw
* event for details on the message object.
*/
export interface IModeChange {
/**
* @param channel - channel
* @param by - nick that changed mode
* @param mode - single character mode identifier
* @param argument - mode argument
* @param message - raw message
*/
(
channel: string,
by: string,
mode: string,
argument: string,
message: IMessage
): void;
}
/**
* 'whois': Emitted whenever the server finishes outputting a WHOIS
* response.
*/
export interface IWhois {
(info: IWhoisData): void;
}
/**
* 'channellist': Emitted when the server has finished returning a
* channel list. The channel_list array is simply a list of the
* objects that were returned in the intervening channellist_item
* events.
*
* This data is also available via the Client.channellist property
* after this event has fired.
*/
export interface IChannelList {
/**
* @param list - channels
*/
(
list: IChannel[]
): void;
}
/**
* 'raw': Emitted when ever the client receives a “message” from
* the server. A message is a parsed line from the server.
*/
export interface IRaw {
/**
* @param message - raw message
*/
(message: IMessage): void;
}
/**
* 'error': Emitted when ever the server responds with an error-type message. The message parameter is exactly as in the ‘raw’ event.
*/
export interface IError {
/**
* @param message - raw message
*/
(message: IMessage): void;
}
/**
* 'action': Emitted whenever a user performs an action
* (e.g. /me waves).
*/
export interface IAction {
/**
* @param from - sender
* @param to - reciever
* @param text - text
* @param message - raw message
*/
(
from: string, to: string, text: string, message: IMessage
): void;
}
}
}
/** Colors */
namespace NodeIRC.colors {
/**
* Takes a color by name, text, and optionally what color to return.
* @param color - name of color
* @param text - text to color
* @param reset_color - color to set after text
*/
export function wrap(
color: string, text: string, reset_color?: string
): string;
/**
* This contains the set of colors available and a function to wrap
* text in a color.
*/
export var codes: {
[index: string]: string;
};
}
export = NodeIRC;
}