MCPcopy Create free account
hub / github.com/Streamerbot/client / subscribe

Method subscribe

packages/client/src/ws/StreamerbotClient.ts:773–809  ·  view source on GitHub ↗

* Subscribe to events from your connected Streamer.bot instance

(events: StreamerbotEventsSubscription | '*')

Source from the content-addressed store, hash-verified

771 listener.events.forEach((event) => {
772 if (!acc[event]) {
773 acc[event] = [];
774 }
775 acc[event].push(listener.callback);
776 });
777 return acc;
778 },
779 {} as Record<StreamerbotEventName | '*', Array<(data: any) => void>>,
780 );
781 }
782
783 /**
784 * Parse the configured listeners and return a subscription object
785 *
786 * @param listeners - Optional array of listeners to parse. If not provided, it uses the current instance's listeners.
787 * @returns A StreamerbotEventsSubscription object ready to be used for subscribing to events.
788 */
789 private async getSubscriptionsFromListeners(
790 listeners?: typeof this.listeners,
791 ): Promise<StreamerbotEventsSubscription> {
792 const events = this.getEventsFromListeners(listeners);
793 return this.getSubscriptionsFromEventStrings(Object.keys(events));
794 }
795
796 /**
797 * Parse an array of event strings and return a structured subscription object
798 *
799 * @param events - An array of event strings to parse, e.g. ['Twitch.ChatMessage', 'YouTube.*', '*']
800 * @returns A StreamerbotEventsSubscription object mapping event sources to their types.
801 */
802 private async getSubscriptionsFromEventStrings(
803 events: string | string[],
804 ): Promise<StreamerbotEventsSubscription> {
805 const subscriptions: StreamerbotEventsSubscription = {};
806
807 if (typeof events === 'string') {
808 events = [events];
809 }
810
811 for (const event of events) {
812 const result = await this.parseEventString(event);

Callers 2

onOpenMethod · 0.95
onMethod · 0.95

Calls 2

getSupportedEventsMethod · 0.95
warnMethod · 0.80

Tested by

no test coverage detected