Files
twitch-bot/src/setup.ts
2025-09-26 19:05:49 +02:00

48 lines
1.4 KiB
TypeScript

import { exchangeCode } from "@twurple/auth";
import { Config } from "./config/config";
import { TokenManager } from "./core/token-manager";
import { TwitchAuth } from "./util/auth";
import { getUserId } from "./util/general";
import { logError, logInfo, logWarning } from "./util/logger";
const botname = "";
const developers = [""];
const scopes = ["chat:read", "chat:edit", "channel:moderate"];
const port = 3000;
const redirectUri = `http://localhost:${port}`;
const botId = await getUserId(botname);
if (!botId) {
logError("bot not found. please check the configuration");
throw new Error();
}
const developerIds = [];
for (const dev in developers) {
const devId = await getUserId(dev);
if (devId) {
developerIds.push(devId);
} else {
logWarning(`dev '${dev}' not found. please check the configuration`);
}
}
logInfo(`Userid of bot '${botname}' => '${botId}'`);
logInfo(
`Userids of developers '${developers.join(",")}' => '${developerIds.join(",")}'`,
);
logInfo("--------");
const auth = new TwitchAuth(redirectUri);
const authUrl = auth.getAuthorizationUrl(scopes);
logInfo("To authorize your Twitch bot, visit this URL:");
logInfo(authUrl);
const code = await auth.startCallbackServer(port, 120);
const tokenManager = new TokenManager(botId);
tokenManager.updateToken(
await exchangeCode(Config.client_id, Config.client_secret, code, redirectUri),
);