@twurple/eventsub-base
Version:
Base for the other Twurple EventSub packages
129 lines (128 loc) • 4.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventSubChannelAutomaticRewardRedemptionAddEvent = void 0;
const tslib_1 = require("tslib");
const shared_utils_1 = require("@d-fischer/shared-utils");
const common_1 = require("@twurple/common");
/**
* An EventSub event representing an automatic reward being redeemed by a user in a channel.
*/
let EventSubChannelAutomaticRewardRedemptionAddEvent = class EventSubChannelAutomaticRewardRedemptionAddEvent extends common_1.DataObject {
/** @internal */
constructor(data, client) {
super(data);
this._client = client;
}
/**
* The ID of the redemption.
*/
get id() {
return this[common_1.rawDataSymbol].id;
}
/**
* The ID of the broadcaster in whose channel the reward was redeemed.
*/
get broadcasterId() {
return this[common_1.rawDataSymbol].broadcaster_user_id;
}
/**
* The name of the broadcaster in whose channel the reward was redeemed.
*/
get broadcasterName() {
return this[common_1.rawDataSymbol].broadcaster_user_login;
}
/**
* The display name of the broadcaster in whose channel the reward was redeemed.
*/
get broadcasterDisplayName() {
return this[common_1.rawDataSymbol].broadcaster_user_name;
}
/**
* Gets more information about the broadcaster.
*/
async getBroadcaster() {
return (0, common_1.checkRelationAssertion)(await this._client.users.getUserById(this[common_1.rawDataSymbol].broadcaster_user_id));
}
/**
* The ID of the redeeming user.
*/
get userId() {
return this[common_1.rawDataSymbol].user_id;
}
/**
* The name of the redeeming user.
*/
get userName() {
return this[common_1.rawDataSymbol].user_login;
}
/**
* The display name of the redeeming user.
*/
get userDisplayName() {
return this[common_1.rawDataSymbol].user_name;
}
/**
* Gets more information about the redeeming user.
*/
async getUser() {
return (0, common_1.checkRelationAssertion)(await this._client.users.getUserById(this[common_1.rawDataSymbol].user_id));
}
/**
* The type of the reward.
*/
get rewardType() {
return this[common_1.rawDataSymbol].reward.type;
}
/**
* The cost of the reward.
*/
get rewardCost() {
return this[common_1.rawDataSymbol].reward.cost;
}
/**
* The emote that was unlocked by the corresponding rewards, or `null` if this field is not relevant.
*/
get unlockedEmote() {
return this[common_1.rawDataSymbol].reward.unlocked_emote;
}
/**
* The input text given by the user.
*
* If there is no input to be given, this is an empty string.
*/
get input() {
return this[common_1.rawDataSymbol].user_input || null;
}
/**
* The text of the message, or `null` if there is no message.
*/
get messageText() {
var _a, _b;
return (_b = (_a = this[common_1.rawDataSymbol].message) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : null;
}
/**
* The offsets of emote usages in the message, or `null` if there is no message.
*/
get emoteOffsets() {
if (this[common_1.rawDataSymbol].message) {
return new Map(Object.entries((0, shared_utils_1.groupBy)(this[common_1.rawDataSymbol].message.emotes, 'id')).map(([id, ranges]) => [
id,
ranges.map(({ begin, end }) => `${begin}-${end}`),
]));
}
return null;
}
/**
* The date when the user redeemed the reward.
*/
get redemptionDate() {
return new Date(this[common_1.rawDataSymbol].redeemed_at);
}
};
exports.EventSubChannelAutomaticRewardRedemptionAddEvent = EventSubChannelAutomaticRewardRedemptionAddEvent;
tslib_1.__decorate([
(0, shared_utils_1.Enumerable)(false)
], EventSubChannelAutomaticRewardRedemptionAddEvent.prototype, "_client", void 0);
exports.EventSubChannelAutomaticRewardRedemptionAddEvent = EventSubChannelAutomaticRewardRedemptionAddEvent = tslib_1.__decorate([
(0, common_1.rtfm)('eventsub-base', 'EventSubChannelAutomaticRewardRedemptionAddEvent', 'id')
], EventSubChannelAutomaticRewardRedemptionAddEvent);