@twurple/eventsub-base
Version:
Base for the other Twurple EventSub packages
68 lines (67 loc) • 4.74 kB
JavaScript
import { __decorate } from "tslib";
import { rtfm } from '@twurple/common';
import { EventSubChannelChatAnnouncementNotificationEvent } from "../events/chatNotifications/EventSubChannelChatAnnouncementNotificationEvent.mjs";
import { EventSubChannelChatBitsBadgeTierNotificationEvent } from "../events/chatNotifications/EventSubChannelChatBitsBadgeTierNotificationEvent.mjs";
import { EventSubChannelChatCharityDonationNotificationEvent } from "../events/chatNotifications/EventSubChannelChatCharityDonationNotificationEvent.mjs";
import { EventSubChannelChatCommunitySubGiftNotificationEvent } from "../events/chatNotifications/EventSubChannelChatCommunitySubGiftNotificationEvent.mjs";
import { EventSubChannelChatGiftPaidUpgradeNotificationEvent } from "../events/chatNotifications/EventSubChannelChatGiftPaidUpgradeNotificationEvent.mjs";
import { EventSubChannelChatPayItForwardNotificationEvent } from "../events/chatNotifications/EventSubChannelChatPayItForwardNotificationEvent.mjs";
import { EventSubChannelChatPrimePaidUpgradeNotificationEvent } from "../events/chatNotifications/EventSubChannelChatPrimePaidUpgradeNotificationEvent.mjs";
import { EventSubChannelChatRaidNotificationEvent } from "../events/chatNotifications/EventSubChannelChatRaidNotificationEvent.mjs";
import { EventSubChannelChatResubNotificationEvent } from "../events/chatNotifications/EventSubChannelChatResubNotificationEvent.mjs";
import { EventSubChannelChatSubGiftNotificationEvent } from "../events/chatNotifications/EventSubChannelChatSubGiftNotificationEvent.mjs";
import { EventSubChannelChatSubNotificationEvent } from "../events/chatNotifications/EventSubChannelChatSubNotificationEvent.mjs";
import { EventSubChannelChatUnraidNotificationEvent } from "../events/chatNotifications/EventSubChannelChatUnraidNotificationEvent.mjs";
import { EventSubSubscription } from "./EventSubSubscription.mjs";
/** @internal */
let EventSubChannelChatNotificationSubscription = class EventSubChannelChatNotificationSubscription extends 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(data, this._client._apiClient);
case 'resub':
return new EventSubChannelChatResubNotificationEvent(data, this._client._apiClient);
case 'sub_gift':
return new EventSubChannelChatSubGiftNotificationEvent(data, this._client._apiClient);
case 'community_sub_gift':
return new EventSubChannelChatCommunitySubGiftNotificationEvent(data, this._client._apiClient);
case 'gift_paid_upgrade':
return new EventSubChannelChatGiftPaidUpgradeNotificationEvent(data, this._client._apiClient);
case 'prime_paid_upgrade':
return new EventSubChannelChatPrimePaidUpgradeNotificationEvent(data, this._client._apiClient);
case 'raid':
return new EventSubChannelChatRaidNotificationEvent(data, this._client._apiClient);
case 'unraid':
return new EventSubChannelChatUnraidNotificationEvent(data, this._client._apiClient);
case 'pay_it_forward':
return new EventSubChannelChatPayItForwardNotificationEvent(data, this._client._apiClient);
case 'announcement':
return new EventSubChannelChatAnnouncementNotificationEvent(data, this._client._apiClient);
case 'charity_donation':
return new EventSubChannelChatCharityDonationNotificationEvent(data, this._client._apiClient);
case 'bits_badge_tier':
return new 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()));
}
};
EventSubChannelChatNotificationSubscription = __decorate([
rtfm('eventsub-base', 'EventSubSubscription')
], EventSubChannelChatNotificationSubscription);
export { EventSubChannelChatNotificationSubscription };