Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 889b710

Browse files
committed
feat: Allow filtering of gifted subs in onSubscriber and onTestSubscriber in stream elements
1 parent 4ce99b7 commit 889b710

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

services/nodecg-io-streamelements/extension/StreamElements.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ export class StreamElementsServiceClient extends EventEmitter {
6262
this.onEvent((data: StreamElementsEvent) => {
6363
if (data.type === "subscriber") {
6464
if (data.data.gifted) {
65-
this.handleSubGift(data.data.sender, data,
65+
this.handleSubGift(
66+
data.data.sender,
67+
data,
6668
(subBomb) => this.emit("subbomb", subBomb),
67-
(gift) => this.emit("gift", gift)
69+
(gift) => this.emit("gift", gift),
6870
);
6971
}
7072
}
@@ -81,9 +83,11 @@ export class StreamElementsServiceClient extends EventEmitter {
8183

8284
this.onTestSubscriber((data) => {
8385
if (data.event.gifted) {
84-
this.handleSubGift(data.event.sender, data,
86+
this.handleSubGift(
87+
data.event.sender,
88+
data,
8589
(subBomb) => this.emit("test:subbomb", subBomb),
86-
(gift) => this.emit("test:gift", gift)
90+
(gift) => this.emit("test:gift", gift),
8791
);
8892
}
8993
});
@@ -186,8 +190,11 @@ export class StreamElementsServiceClient extends EventEmitter {
186190
});
187191
}
188192

189-
public onSubscriber(handler: (data: StreamElementsSubscriberEvent) => void): void {
190-
this.on("subscriber", handler);
193+
public onSubscriber(handler: (data: StreamElementsSubscriberEvent) => void, includeSubGifts = true): void {
194+
this.on("subscriber", (data) => {
195+
if (data.data.gifted && !includeSubGifts) return;
196+
handler(data);
197+
});
191198
}
192199

193200
public onSubscriberBomb(handler: (data: StreamElementsSubBombEvent<StreamElementsSubscriberEvent>) => void): void {
@@ -222,8 +229,11 @@ export class StreamElementsServiceClient extends EventEmitter {
222229
this.on("test", handler);
223230
}
224231

225-
public onTestSubscriber(handler: (data: StreamElementsTestSubscriberEvent) => void): void {
226-
this.on("test:subscriber-latest", handler);
232+
public onTestSubscriber(handler: (data: StreamElementsTestSubscriberEvent) => void, includeSubGifts = true): void {
233+
this.on("test:subscriber-latest", (data) => {
234+
if (data.event.gifted && !includeSubGifts) return;
235+
handler(data);
236+
});
227237
}
228238

229239
public onTestSubscriberBomb(
@@ -261,13 +271,13 @@ export class StreamElementsServiceClient extends EventEmitter {
261271
rep.value = {};
262272
}
263273

264-
this.onSubscriber(data => rep.value.lastSubscriber = data);
265-
this.onSubscriberBomb(data => rep.value.lastSubBomb = data);
266-
this.onTip(data => rep.value.lastTip = data);
267-
this.onCheer(data => rep.value.lastCheer = data);
268-
this.onGift(data => rep.value.lastGift = data);
269-
this.onFollow(data => rep.value.lastFollow = data);
270-
this.onRaid(data => rep.value.lastRaid = data);
271-
this.onHost(data => rep.value.lastHost = data);
274+
this.onSubscriber((data) => (rep.value.lastSubscriber = data));
275+
this.onSubscriberBomb((data) => (rep.value.lastSubBomb = data));
276+
this.onTip((data) => (rep.value.lastTip = data));
277+
this.onCheer((data) => (rep.value.lastCheer = data));
278+
this.onGift((data) => (rep.value.lastGift = data));
279+
this.onFollow((data) => (rep.value.lastFollow = data));
280+
this.onRaid((data) => (rep.value.lastRaid = data));
281+
this.onHost((data) => (rep.value.lastHost = data));
272282
}
273283
}

0 commit comments

Comments
 (0)