@twurple/eventsub-base
Version:
Base for the other Twurple EventSub packages
213 lines (212 loc) • 7.69 kB
JavaScript
import { __decorate } from "tslib";
import { Enumerable } from '@d-fischer/shared-utils';
import { checkRelationAssertion, DataObject, rawDataSymbol, rtfm } from '@twurple/common';
/**
* An EventSub event representing a notification being sent to a channel's chat.
*/
let EventSubChannelChatMessageEvent = class EventSubChannelChatMessageEvent extends DataObject {
/** @internal */
constructor(data, client) {
super(data);
this._client = client;
}
/**
* The type of the message.
*/
get messageType() {
return this[rawDataSymbol].message_type;
}
/**
* The ID of the broadcaster.
*/
get broadcasterId() {
return this[rawDataSymbol].broadcaster_user_id;
}
/**
* The name of the broadcaster.
*/
get broadcasterName() {
return this[rawDataSymbol].broadcaster_user_login;
}
/**
* The display name of the broadcaster.
*/
get broadcasterDisplayName() {
return this[rawDataSymbol].broadcaster_user_name;
}
/**
* Gets more information about the broadcaster.
*/
async getBroadcaster() {
return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].broadcaster_user_id));
}
/**
* The ID of the chatter.
*/
get chatterId() {
return this[rawDataSymbol].chatter_user_id;
}
/**
* The name of the chatter.
*/
get chatterName() {
return this[rawDataSymbol].chatter_user_login;
}
/**
* The display name of the chatter.
*/
get chatterDisplayName() {
return this[rawDataSymbol].chatter_user_name;
}
/**
* Gets more information about the chatter.
*/
async getChatter() {
return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].chatter_user_id));
}
/**
* The color of the chatter, or null if they didn't choose a color.
*/
get color() {
return this[rawDataSymbol].color || null;
}
/**
* The badges the chatter has.
*
* The returned object contains the badge names as keys and the badge versions as the respective values.
*/
get badges() {
return Object.fromEntries(this[rawDataSymbol].badges.map(badge => [badge.set_id, badge.id]));
}
/**
* Checks whether the chatter has the specified badge.
*
* @param name The name of the badge to check.
*/
hasBadge(name) {
return this[rawDataSymbol].badges.some(badge => badge.set_id === name);
}
/**
* Gets the badge info for a specified badge, or null if the badge does not exist.
*
* @param name The name of the badge to get info for.
*/
getBadgeInfo(name) {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].badges.find(badge => badge.set_id === name)) === null || _a === void 0 ? void 0 : _a.info) !== null && _b !== void 0 ? _b : null;
}
/**
* The ID of the notification message.
*/
get messageId() {
return this[rawDataSymbol].message_id;
}
/**
* The text that was sent with the notification, e.g. the resub message or announcement text.
*/
get messageText() {
return this[rawDataSymbol].message.text;
}
/**
* The text that was sent with the notification, structured into pre-parsed parts.
*/
get messageParts() {
return this[rawDataSymbol].message.fragments;
}
/**
* The ID of the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageId() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].reply) === null || _a === void 0 ? void 0 : _a.parent_message_id) !== null && _b !== void 0 ? _b : null;
}
/**
* The text of the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageText() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].reply) === null || _a === void 0 ? void 0 : _a.parent_message_body) !== null && _b !== void 0 ? _b : null;
}
/**
* The ID of the user that wrote the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageUserId() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].reply) === null || _a === void 0 ? void 0 : _a.parent_user_id) !== null && _b !== void 0 ? _b : null;
}
/**
* The name of the user that wrote the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageUserName() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].reply) === null || _a === void 0 ? void 0 : _a.parent_user_login) !== null && _b !== void 0 ? _b : null;
}
/**
* The display name of the user that wrote the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageUserDisplayName() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].reply) === null || _a === void 0 ? void 0 : _a.parent_user_name) !== null && _b !== void 0 ? _b : null;
}
/**
* The ID of the message that is the thread starter of this message, or `null` if it's not a reply.
*/
get threadMessageId() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].reply) === null || _a === void 0 ? void 0 : _a.thread_message_id) !== null && _b !== void 0 ? _b : null;
}
/**
* The ID of the user that wrote the thread starter message of this message, or `null` if it's not a reply.
*/
get threadMessageUserId() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].reply) === null || _a === void 0 ? void 0 : _a.thread_user_id) !== null && _b !== void 0 ? _b : null;
}
/**
* The name of the user that wrote the thread starter message of this message, or `null` if it's not a reply.
*/
get threadMessageUserName() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].reply) === null || _a === void 0 ? void 0 : _a.thread_user_login) !== null && _b !== void 0 ? _b : null;
}
/**
* The display name of the user that wrote the thread starter message of this message, or `null` if it's not a reply.
*/
get threadMessageUserDisplayName() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].reply) === null || _a === void 0 ? void 0 : _a.thread_user_name) !== null && _b !== void 0 ? _b : null;
}
/**
* Whether the message is a cheer.
*/
get isCheer() {
return Boolean(this[rawDataSymbol].cheer);
}
/**
* The number of bits cheered with this message.
*/
get bits() {
var _a, _b;
return (_b = (_a = this[rawDataSymbol].cheer) === null || _a === void 0 ? void 0 : _a.bits) !== null && _b !== void 0 ? _b : 0;
}
/**
* Whether the message represents a redemption of a custom channel points reward.
*/
get isRedemption() {
return Boolean(this[rawDataSymbol].channel_points_custom_reward_id);
}
/**
* The ID of the redeemed reward, or `null` if the message does not represent a redemption.
*/
get rewardId() {
var _a;
return (_a = this[rawDataSymbol].channel_points_custom_reward_id) !== null && _a !== void 0 ? _a : null;
}
};
__decorate([
Enumerable(false)
], EventSubChannelChatMessageEvent.prototype, "_client", void 0);
EventSubChannelChatMessageEvent = __decorate([
rtfm('eventsub-base', 'EventSubChannelChatMessageEvent', 'broadcasterId')
], EventSubChannelChatMessageEvent);
export { EventSubChannelChatMessageEvent };