UNPKG

@twitchfy/chatbot

Version:

A powerful node module to make your own Twitch ChatBot

37 lines (36 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initEvent = exports.handleSubscriptionReload = void 0; const eventsub_1 = require("@twitchfy/eventsub"); const handleOnMessage_1 = require("./handleOnMessage"); const handleEvent_1 = require("./handleEvent"); const structures_1 = require("../structures"); /** * Handle the subscription reload. * @param this The current instance of the chatbot. * @param subscription The subscription to reload. * @internal */ function handleSubscriptionReload(subscription) { let profile = this.profiles.get(subscription.options.broadcaster_user_id); if (subscription.checkSubscriptionType(eventsub_1.SubscriptionTypes.ChannelChatMessage) && subscription.options.user_id === this.userId) { if (!profile) { profile = new structures_1.ChannelProfile(this, { id: subscription.options.broadcaster_user_id, events: ['ChannelChatMessage'] }); this.profiles.set(subscription.options.broadcaster_user_id, profile); } const fn = handleOnMessage_1.handleOnMessage.bind(this); subscription.onMessage(fn); return; } initEvent(profile ?? null, subscription.type); } exports.handleSubscriptionReload = handleSubscriptionReload; function initEvent(profile, type) { if (!profile) return; const key = (0, handleEvent_1.getSubscriptonKey)(type); if (!key) return; profile.events.push(key); } exports.initEvent = initEvent;