linkup-bot-lib
Version:
59 lines (58 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Message = void 0;
/**
* @description Base class for all messages
* @since 1.0
* @author MiTask
* @module Message
*/
class Message {
type;
peerName;
peerAvatar;
topic;
timestamp;
/**
* @since 1.0
* @author MiTask
* @constructor
* @param messageType Type of the message (text, file, audio, icon)
* @param peerName Peer username
* @param peerAvatar Peer avatar URL
* @param topic Chat room topic string
* @param timestamp UNIX Timestamp
*/
constructor(messageType, peerName, peerAvatar, topic, timestamp) {
this.type = messageType;
this.peerName = peerName;
this.peerAvatar = peerAvatar;
this.topic = topic;
this.timestamp = timestamp;
}
/**
* @since 1.0
* @author MiTask
* @returns JSON Object with all of the information about the message
*/
toJson() {
return {
type: this.type,
name: this.peerName,
avatar: this.peerAvatar,
topic: this.topic ? this.topic : "",
timestamp: this.timestamp
};
}
/**
* @since 1.0
* @author MiTask
* @returns {string} JSON String with all of the information about the message
*/
toJsonString() {
return JSON.stringify({
...this.toJson()
});
}
}
exports.Message = Message;