From 42ad0795891c2ef15a3c3dfe3f974157def3b860 Mon Sep 17 00:00:00 2001 From: Darius Date: Fri, 26 Sep 2025 21:54:16 +0200 Subject: [PATCH] do some mini cleany cleany --- .env.example | 2 ++ src/commands/command-song.ts | 3 ++- src/config/config.ts | 5 +++++ src/core/chat-client.ts | 2 +- src/core/token-manager.ts | 8 ++------ src/setup.ts | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 769ffea..650e43f 100644 --- a/.env.example +++ b/.env.example @@ -4,3 +4,5 @@ CLIENT_ID=clientId CLIENT_SECRET=clientSecret CHANNELS=channelsOfBot(,separated) DEVELOPERS=userIdOfDeveloper(,separated) +TIDAL_HOST=http://localhost +TIDAL_PORT=47836 diff --git a/src/commands/command-song.ts b/src/commands/command-song.ts index 3ac3754..7883d55 100644 --- a/src/commands/command-song.ts +++ b/src/commands/command-song.ts @@ -1,5 +1,6 @@ import type { ChatMessage } from "@twurple/chat"; import axios from "axios"; +import { Config } from "../config/config.ts"; import { logError, logSuccess } from "../util/logger.ts"; import { BaseCommand } from "./base-command.ts"; import type { ICommandRequirements } from "./interface.ts"; @@ -38,7 +39,7 @@ export class SongCommand extends BaseCommand { } async function getSongFromTidal() { - axios.get("http://localhost:47836/current").then( + axios.get(`${Config.tidal.host}:${Config.tidal.port}/current`).then( (response) => { const currentSong = response.data; diff --git a/src/config/config.ts b/src/config/config.ts index e36aae0..84e56d0 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -9,4 +9,9 @@ export const Config = { client_secret: process.env.CLIENT_SECRET || "", channels: process.env.CHANNELS?.split(",") || [], developers: process.env.DEVELOPERS?.split(",") || [], + + tidal: { + host: process.env.TIDAL_HOST || "", + port: process.env.TIDAL_PORT || "", + }, } as const; diff --git a/src/core/chat-client.ts b/src/core/chat-client.ts index d9ae383..ab254ef 100644 --- a/src/core/chat-client.ts +++ b/src/core/chat-client.ts @@ -18,7 +18,7 @@ const authProviderPrivate = new RefreshingAuthProvider({ }); authProviderPrivate.onRefresh(async (_userId, newTokenData: AccessToken) => - tokenManager.updateToken(newTokenData), + tokenManager.createTokenFile(newTokenData), ); authProviderPrivate.addUser(Config.bot_user_id, tokenData, ["chat"]); diff --git a/src/core/token-manager.ts b/src/core/token-manager.ts index f52c87b..cc36eac 100644 --- a/src/core/token-manager.ts +++ b/src/core/token-manager.ts @@ -14,17 +14,13 @@ export class TokenManager { return JSON.parse(tokenFile); } catch (_error) { console.log( - `Token file ${this.tokenFilePath} not found. Please run the setup`, + `token file ${this.tokenFilePath} not found. please run the setup`, ); return null; } } - async updateToken(token: AccessToken): Promise { - this.createTokenFile(token); - } - - private async createTokenFile(tokenData: AccessToken): Promise { + async createTokenFile(tokenData: AccessToken): Promise { const formattedTokens = JSON.stringify(tokenData, null, 4); await fs.writeFile(this.tokenFilePath, formattedTokens, "utf-8"); } diff --git a/src/setup.ts b/src/setup.ts index fab5553..5903f9e 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -44,6 +44,6 @@ const code = await auth.startCallbackServer(port, 120); const tokenManager = new TokenManager(botId); -tokenManager.updateToken( +tokenManager.createTokenFile( await exchangeCode(Config.client_id, Config.client_secret, code, redirectUri), );