back to websockets (webhooks are a pain), new websocket EventSub fixer

This commit is contained in:
2025-07-04 16:36:06 +02:00
parent d4c5b29fe1
commit c0fc8bccf2
5 changed files with 46 additions and 57 deletions

View File

@@ -1,7 +1,4 @@
import { eventSub, streamerApi } from "..";
await streamerApi.eventSub.deleteAllSubscriptions();
console.info('Succesfully deleted all unused EventSub subscriptions');
import { eventSub, streamerApi, streamerId } from "..";
eventSub.onRevoke(event => {
console.info(`Successfully revoked EventSub subscription: ${event.id}`);
@@ -9,6 +6,7 @@ eventSub.onRevoke(event => {
eventSub.onSubscriptionCreateSuccess(event => {
console.info(`Successfully created EventSub subscription: ${event.id}`);
deleteDuplicateSubscriptions.refresh();
});
eventSub.onSubscriptionCreateFailure(event => {
@@ -32,3 +30,36 @@ for (const file of files) {
};
eventSub.start();
import { getAuthRecord } from "../db/dbAuth";
import { StaticAuthProvider } from "@twurple/auth";
import { ApiClient, HelixEventSubSubscription } from "@twurple/api";
const deleteDuplicateSubscriptions = setTimeout(async () => {
console.info('Deleting all double subscriptions');
const tokendata = await streamerApi.getTokenInfo();
const authdata = await getAuthRecord(streamerId, []);
const tempauth = new StaticAuthProvider(tokendata.clientId, authdata?.accesstoken.accessToken!);
const tempapi: ApiClient = new ApiClient({ authProvider: tempauth });
console.info('Created the temporary API client');
const subs = await tempapi.eventSub.getSubscriptionsForStatus('enabled');
const seen = new Map();
const duplicates: HelixEventSubSubscription[] = [];
for (const sub of subs.data) {
if (seen.has(sub.type)) {
if (!duplicates.some(o => o.type === sub.type)) {
duplicates.push(seen.get(sub.type));
};
} else {
seen.set(sub.type, sub);
};
};
for (const sub of duplicates) {
await tempapi.eventSub.deleteSubscription(sub.id);
console.info(`Deleted sub: id: ${sub.id}, type: ${sub.type}`);
};
if (duplicates.length === 0) console.info('No duplicate subscriptions found');
console.info('Removed temporary API client');
}, 5000);