linkup-bot-lib
Version:
49 lines (45 loc) • 1.35 kB
text/typescript
/**
* @module Message
*/
import {Message} from "./Message";
import {Client} from "../Client";
export class TextMessage extends Message {
message: string;
/**
* @description Creates a new text message.
* @since 1.0
* @author MiTask
* @constructor
* @param peerName Peer username
* @param peerAvatar Peer avatar URL
* @param topic Chat room topic string
* @param timestamp UNIX Timestamp
* @param message Text of the message
*/
constructor(peerName: string, peerAvatar: string, topic: string | null, timestamp: number, message: string) {
super("message", peerName, peerAvatar, topic, timestamp);
this.message = message;
}
/**
* @since 1.0
* @author MiTask
* @returns {String} JSON String with all of the information about the message
*/
toJsonString(): string {
return JSON.stringify({
...this.toJson(),
message: this.message,
});
}
/**
* @description Creates a new text message instance.
* @since 1.0
* @author MiTask
* @param bot Bot Client class
* @param message Text of the message
* @returns {TextMessage} TextMessage instance
*/
static new(bot: Client, message: string): TextMessage {
return new TextMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), message);
}
}