forked from lsongdev/node-irc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.js
44 lines (41 loc) · 1.05 KB
/
message.js
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
/**
* Represents an IRC message.
*/
class Message {
/**
* @param {string|Object|null} prefix Message prefix. (Optional.)
* @param {string} command Command name.
* @param {Array.<string>} parameters IRC Command parameters.
*/
constructor (prefix, command, parameters) {
if (prefix && typeof prefix.mask === 'function') {
prefix = prefix.mask()
}
/**
* Message Prefix. Basically just the sender nickmask.
* @member {string}
*/
this.prefix = prefix
/**
* Command, i.e. what this message actually means to us!
* @member {string}
*/
this.command = command
/**
* Parameters given to this command.
* @member {Array.<string>}
*/
this.parameters = parameters
}
/**
* Compiles the message back down into an IRC command string.
*
* @return {string} IRC command.
*/
toString () {
return (this.prefix ? `:${this.prefix} ` : '') +
this.command +
(this.parameters.length ? ` ${this.parameters.join(' ')}` : '')
}
}
module.exports = Message;