UNPKG

twitch-core

Version:
122 lines (121 loc) 4 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TwitchChatMessage = void 0; const TwitchChatUser_1 = require("../users/TwitchChatUser"); const TwitchChatChannel_1 = require("../channels/TwitchChatChannel"); class TwitchChatMessage { constructor(originalMessage, channel, client) { this.client = client; this.originalMessage = originalMessage; this._channel = new TwitchChatChannel_1.TwitchChatChannel({ channel, room_id: originalMessage['room-id'] }, client); this._author = new TwitchChatUser_1.TwitchChatUser(originalMessage, client); this._timestamp = new Date(); } /** * Text of the message */ get text() { return this.originalMessage.message; } /** * The author of the message */ get author() { return this._author; } /** * The ID of the message */ get id() { return this.originalMessage.id; } /** * The channel where the message has been sent in */ get channel() { return this._channel; } /** * Text color */ get color() { return this.originalMessage.color; } /** * Emotes contained in the message */ get emotes() { return this.originalMessage.emotes; } /** * Message sent date */ get timestamp() { return this._timestamp; } /** * Message type */ get messageType() { return this.originalMessage['message-type']; } /** * Helper method to reply quickly to a message. Create a message to send in the channel with @author <text> * * @param text * @param addRandomEmote */ reply(text, addRandomEmote = false) { return __awaiter(this, void 0, void 0, function* () { if (this.messageType === 'whisper') { return this.client.whisper(this.author.username, text); } else { return this.client.say(this.channel.name, `@${this.author.displayName}, ${text}`, addRandomEmote); } }); } /** * Helper method to reply quickly to a message with an action * * @param text * @param addRandomEmote */ actionReply(text, addRandomEmote = false) { return __awaiter(this, void 0, void 0, function* () { return this.client.action(this.channel.name, `@${this.author.displayName}, ${text}`, addRandomEmote); }); } /** * Helper method to send message * * @param text * @param addRandomEmote */ say(text, addRandomEmote = false) { return __awaiter(this, void 0, void 0, function* () { return this.client.say(this.channel.name, text, addRandomEmote); }); } /** * Helper method to a message with an action * * @param text * @param addRandomEmote */ actionSay(text, addRandomEmote = false) { return __awaiter(this, void 0, void 0, function* () { return this.client.action(this.channel.name, text, addRandomEmote); }); } } exports.TwitchChatMessage = TwitchChatMessage;