@twurple/eventsub-base
Version:
Base for the other Twurple EventSub packages
98 lines (97 loc) • 9.05 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");
const EventSubChannelChatSharedChatSubNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSharedChatSubNotificationEvent");
const EventSubChannelChatSharedChatResubNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSharedChatResubNotificationEvent");
const EventSubChannelChatSharedChatSubGiftNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSharedChatSubGiftNotificationEvent");
const EventSubChannelChatSharedChatCommunitySubGiftNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSharedChatCommunitySubGiftNotificationEvent");
const EventSubChannelChatSharedChatGiftPaidUpgradeNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSharedChatGiftPaidUpgradeNotificationEvent");
const EventSubChannelChatSharedChatPrimePaidUpgradeNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSharedChatPrimePaidUpgradeNotificationEvent");
const EventSubChannelChatSharedChatPayItForwardNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSharedChatPayItForwardNotificationEvent");
const EventSubChannelChatSharedChatAnnouncementNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSharedChatAnnouncementNotificationEvent");
const EventSubChannelChatSharedChatRaidNotificationEvent_1 = require("../events/chatNotifications/EventSubChannelChatSharedChatRaidNotificationEvent");
/** @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);
case 'shared_chat_sub':
return new EventSubChannelChatSharedChatSubNotificationEvent_1.EventSubChannelChatSharedChatSubNotificationEvent(data, this._client._apiClient);
case 'shared_chat_resub':
return new EventSubChannelChatSharedChatResubNotificationEvent_1.EventSubChannelChatSharedChatResubNotificationEvent(data, this._client._apiClient);
case 'shared_chat_sub_gift':
return new EventSubChannelChatSharedChatSubGiftNotificationEvent_1.EventSubChannelChatSharedChatSubGiftNotificationEvent(data, this._client._apiClient);
case 'shared_chat_community_sub_gift':
return new EventSubChannelChatSharedChatCommunitySubGiftNotificationEvent_1.EventSubChannelChatSharedChatCommunitySubGiftNotificationEvent(data, this._client._apiClient);
case 'shared_chat_gift_paid_upgrade':
return new EventSubChannelChatSharedChatGiftPaidUpgradeNotificationEvent_1.EventSubChannelChatSharedChatGiftPaidUpgradeNotificationEvent(data, this._client._apiClient);
case 'shared_chat_prime_paid_upgrade':
return new EventSubChannelChatSharedChatPrimePaidUpgradeNotificationEvent_1.EventSubChannelChatSharedChatPrimePaidUpgradeNotificationEvent(data, this._client._apiClient);
case 'shared_chat_pay_it_forward':
return new EventSubChannelChatSharedChatPayItForwardNotificationEvent_1.EventSubChannelChatSharedChatPayItForwardNotificationEvent(data, this._client._apiClient);
case 'shared_chat_raid':
return new EventSubChannelChatSharedChatRaidNotificationEvent_1.EventSubChannelChatSharedChatRaidNotificationEvent(data, this._client._apiClient);
case 'shared_chat_announcement':
return new EventSubChannelChatSharedChatAnnouncementNotificationEvent_1.EventSubChannelChatSharedChatAnnouncementNotificationEvent(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);