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
// eslint-disable-next-line no-control-regex
const actionRegex = /^\x01ACTION( (.+)?)?\x01$/;
/**
* Bancho incoming message
* @abstract
* @prop {BanchoUser} user User the message was sent by
* @prop {string} message Message body
* @prop {boolean} self Set to true if this message was sent by this instance of bancho.js
*/
class BanchoMessage {
/**
* Creates an instance of Message.
* @param {BanchoUser} user User the message was sent by
* @param {string} message Message body
* @param {boolean} self Set to true if this message was sent by this instance of bancho.js
*/
constructor(user, message, self) {
if(new.target === BanchoMessage)
throw new Error("Don't instanciate an abstract class you dumbass");
this.user = user;
this.message = message;
this.self = self;
}
/**
* The content of this message
* @returns {string}
*/
get content() {
return this.message;
}
/**
* Tries to parse this message as an ACTION (/me message).
* @returns {string}
*/
getAction() {
const action = actionRegex.exec(this.message);
if(action)
return action[2] || "";
}
}
module.exports = BanchoMessage;