mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-20 05:51:39 +01:00
back to websockets (webhooks are a pain), new websocket EventSub fixer
This commit is contained in:
13
bot/index.ts
13
bot/index.ts
@@ -1,6 +1,6 @@
|
||||
import { createAuthProvider } from "./auth";
|
||||
import { ApiClient } from "@twurple/api";
|
||||
import { EventSubHttpListener, ReverseProxyAdapter } from "@twurple/eventsub-http";
|
||||
import { EventSubWsListener } from "@twurple/eventsub-ws";
|
||||
import { addAdmin } from "./lib/admins";
|
||||
|
||||
const CHATTERINTENTS = ["user:read:chat", "user:write:chat", "user:bot"];
|
||||
@@ -12,11 +12,6 @@ if (chatterId === "") { console.error('Please set a CHATTER_ID in the .env'); pr
|
||||
export const streamerId = process.env.STREAMER_ID ?? "";
|
||||
if (streamerId === "") { console.error('Please set a STREAMER_ID in the .env'); process.exit(1); };
|
||||
|
||||
const hostName = process.env.EVENTSUB_HOSTNAME ?? "";
|
||||
if (hostName === "") { console.error('Please set a EVENTSUB_HOSTNAME in the .env'); process.exit(1); };
|
||||
const port = Number(process.env.EVENTSUB_PORT) ?? 0;
|
||||
if (port === 0) { console.error('Please set a EVENTSUB_PORT in the .env'); process.exit(1); };
|
||||
|
||||
export const chatterAuthProvider = await createAuthProvider(chatterId, singleUserMode ? CHATTERINTENTS.concat(STREAMERINTENTS) : CHATTERINTENTS);
|
||||
export const streamerAuthProvider = singleUserMode ? undefined : await createAuthProvider(streamerId, STREAMERINTENTS, true);
|
||||
|
||||
@@ -27,11 +22,7 @@ export const chatterApi = new ApiClient({ authProvider: chatterAuthProvider });
|
||||
export const streamerApi = streamerAuthProvider ? new ApiClient({ authProvider: streamerAuthProvider }) : chatterApi; // if there is no streamer user, use the chatter user
|
||||
|
||||
/** As the streamerApi has either the streamer or the chatter if the chatter IS the streamer this has streamer permissions */
|
||||
export const eventSub = new EventSubHttpListener({
|
||||
apiClient: streamerApi,
|
||||
adapter: new ReverseProxyAdapter({ hostName, port }),
|
||||
secret: Bun.randomUUIDv7()
|
||||
});
|
||||
export const eventSub = new EventSubWsListener({ apiClient: streamerApi });
|
||||
|
||||
export const commandPrefix = process.env.COMMAND_PREFIX ?? "!";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user