@twurple/eventsub-base
Version:
Base for the other Twurple EventSub packages
71 lines (70 loc) • 5.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventSubChannelChatNotificationSubscription = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@twurple/common");
const EventSubChannelChatAnnouncementNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatAnnouncementNotificationEvent");
const EventSubChannelChatBitsBadgeTierNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatBitsBadgeTierNotificationEvent");
const EventSubChannelChatCharityDonationNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatCharityDonationNotificationEvent");
const EventSubChannelChatCommunitySubGiftNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatCommunitySubGiftNotificationEvent");
const EventSubChannelChatGiftPaidUpgradeNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatGiftPaidUpgradeNotificationEvent");
const EventSubChannelChatPayItForwardNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatPayItForwardNotificationEvent");
const EventSubChannelChatPrimePaidUpgradeNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatPrimePaidUpgradeNotificationEvent");
const EventSubChannelChatRaidNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatRaidNotificationEvent");
const EventSubChannelChatResubNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatResubNotificationEvent");
const EventSubChannelChatSubGiftNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSubGiftNotificationEvent");
const EventSubChannelChatSubNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSubNotificationEvent");
const EventSubChannelChatUnraidNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatUnraidNotificationEvent");
const EventSubSubscription_1 = require("./EventSubSubscription");
/** @internal */
let EventSubChannelChatNotificationSubscription = class EventSubChannelChatNotificationSubscription extends EventSubSubscription_1.EventSubSubscription {
constructor(handler, client, _broadcasterId, _userId) {
super(handler, client);
this._broadcasterId = _broadcasterId;
this._userId = _userId;
/** @protected */ this._cliName = 'chat-notification';
}
get id() {
return `channel.chat.notification.${this._broadcasterId}.${this._userId}`;
}
get authUserId() {
return this._userId;
}
transformData(data) {
switch (data.notice_type) {
case 'sub':
return new EventSubChannelChatSubNotificationEvent_1.EventSubChannelChatSubNotificationEvent(data, this._client._apiClient);
case 'resub':
return new EventSubChannelChatResubNotificationEvent_1.EventSubChannelChatResubNotificationEvent(data, this._client._apiClient);
case 'sub_gift':
return new EventSubChannelChatSubGiftNotificationEvent_1.EventSubChannelChatSubGiftNotificationEvent(data, this._client._apiClient);
case 'community_sub_gift':
return new EventSubChannelChatCommunitySubGiftNotificationEvent_1.EventSubChannelChatCommunitySubGiftNotificationEvent(data, this._client._apiClient);
case 'gift_paid_upgrade':
return new EventSubChannelChatGiftPaidUpgradeNotificationEvent_1.EventSubChannelChatGiftPaidUpgradeNotificationEvent(data, this._client._apiClient);
case 'prime_paid_upgrade':
return new EventSubChannelChatPrimePaidUpgradeNotificationEvent_1.EventSubChannelChatPrimePaidUpgradeNotificationEvent(data, this._client._apiClient);
case 'raid':
return new EventSubChannelChatRaidNotificationEvent_1.EventSubChannelChatRaidNotificationEvent(data, this._client._apiClient);
case 'unraid':
return new EventSubChannelChatUnraidNotificationEvent_1.EventSubChannelChatUnraidNotificationEvent(data, this._client._apiClient);
case 'pay_it_forward':
return new EventSubChannelChatPayItForwardNotificationEvent_1.EventSubChannelChatPayItForwardNotificationEvent(data, this._client._apiClient);
case 'announcement':
return new EventSubChannelChatAnnouncementNotificationEvent_1.EventSubChannelChatAnnouncementNotificationEvent(data, this._client._apiClient);
case 'charity_donation':
return new EventSubChannelChatCharityDonationNotificationEvent_1.EventSubChannelChatCharityDonationNotificationEvent(data, this._client._apiClient);
case 'bits_badge_tier':
return new EventSubChannelChatBitsBadgeTierNotificationEvent_1.EventSubChannelChatBitsBadgeTierNotificationEvent(data, this._client._apiClient);
default:
throw new Error(`Unknown chat notification type: ${data.notice_type}`);
}
}
async _subscribe() {
return await this._client._apiClient.asUser(this._userId, async (ctx) => await ctx.eventSub.subscribeToChannelChatNotificationEvents(this._broadcasterId, await this._getTransportOptions()));
}
};
exports.EventSubChannelChatNotificationSubscription = EventSubChannelChatNotificationSubscription;
exports.EventSubChannelChatNotificationSubscription = EventSubChannelChatNotificationSubscription = tslib_1.__decorate([
(0, common_1.rtfm)('eventsub-base', 'EventSubSubscription')
], EventSubChannelChatNotificationSubscription);