mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-20 04:11:38 +01:00
change sendMessage wrapper, migrate from websocket connection to webhook for EventSub (reverse proxy)
This commit is contained in:
19
bot/index.ts
19
bot/index.ts
@@ -1,16 +1,21 @@
|
||||
import { createAuthProvider } from "./auth";
|
||||
import { ApiClient } from "@twurple/api";
|
||||
import { EventSubWsListener } from "@twurple/eventsub-ws";
|
||||
import { EventSubHttpListener, ReverseProxyAdapter } from "@twurple/eventsub-http";
|
||||
import { intents } from "./commands";
|
||||
|
||||
const CHATTERBASEINTENTS = ["user:read:chat", "user:write:chat", "user:bot"];
|
||||
const STREAMERBASEINTENTS = ["user:read:chat"];
|
||||
const STREAMERBASEINTENTS = ["user:read:chat", "channel:bot", "moderation:read"];
|
||||
|
||||
export const singleUserMode = process.env.CHATTER_IS_STREAMER === 'true';
|
||||
export const chatterId = process.env.CHATTER_ID ?? "";
|
||||
if (chatterId === "") { console.error('Please set a CHATTER_ID in the .env'); process.exit(1); };
|
||||
export const streamerId = process.env.STREAMER_ID ?? "";
|
||||
if (streamerId === "") { console.log('Please set a STREAMER_ID in the .env'); process.exit(1); };
|
||||
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); };
|
||||
|
||||
const chatterIntents = singleUserMode ? CHATTERBASEINTENTS.concat(STREAMERBASEINTENTS) : CHATTERBASEINTENTS;
|
||||
const streamerIntents = STREAMERBASEINTENTS.concat(intents);
|
||||
@@ -25,10 +30,12 @@ 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 EventSubWsListener({ apiClient: streamerApi });
|
||||
export const eventSub = new EventSubHttpListener({
|
||||
apiClient: streamerApi,
|
||||
adapter: new ReverseProxyAdapter({ hostName, port }),
|
||||
secret: Bun.randomUUIDv7()
|
||||
});
|
||||
|
||||
export const commandPrefix = process.env.COMMAND_PREFIX ?? "!";
|
||||
|
||||
await import("./events");
|
||||
|
||||
eventSub.start();
|
||||
|
||||
Reference in New Issue
Block a user