do some mini cleany cleany
This commit is contained in:
@@ -4,3 +4,5 @@ CLIENT_ID=clientId
|
|||||||
CLIENT_SECRET=clientSecret
|
CLIENT_SECRET=clientSecret
|
||||||
CHANNELS=channelsOfBot(,separated)
|
CHANNELS=channelsOfBot(,separated)
|
||||||
DEVELOPERS=userIdOfDeveloper(,separated)
|
DEVELOPERS=userIdOfDeveloper(,separated)
|
||||||
|
TIDAL_HOST=http://localhost
|
||||||
|
TIDAL_PORT=47836
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { ChatMessage } from "@twurple/chat";
|
import type { ChatMessage } from "@twurple/chat";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { Config } from "../config/config.ts";
|
||||||
import { logError, logSuccess } from "../util/logger.ts";
|
import { logError, logSuccess } from "../util/logger.ts";
|
||||||
import { BaseCommand } from "./base-command.ts";
|
import { BaseCommand } from "./base-command.ts";
|
||||||
import type { ICommandRequirements } from "./interface.ts";
|
import type { ICommandRequirements } from "./interface.ts";
|
||||||
@@ -38,7 +39,7 @@ export class SongCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getSongFromTidal() {
|
async function getSongFromTidal() {
|
||||||
axios.get<ISong>("http://localhost:47836/current").then(
|
axios.get<ISong>(`${Config.tidal.host}:${Config.tidal.port}/current`).then(
|
||||||
(response) => {
|
(response) => {
|
||||||
const currentSong = response.data;
|
const currentSong = response.data;
|
||||||
|
|
||||||
|
|||||||
@@ -9,4 +9,9 @@ export const Config = {
|
|||||||
client_secret: process.env.CLIENT_SECRET || "",
|
client_secret: process.env.CLIENT_SECRET || "",
|
||||||
channels: process.env.CHANNELS?.split(",") || [],
|
channels: process.env.CHANNELS?.split(",") || [],
|
||||||
developers: process.env.DEVELOPERS?.split(",") || [],
|
developers: process.env.DEVELOPERS?.split(",") || [],
|
||||||
|
|
||||||
|
tidal: {
|
||||||
|
host: process.env.TIDAL_HOST || "",
|
||||||
|
port: process.env.TIDAL_PORT || "",
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const authProviderPrivate = new RefreshingAuthProvider({
|
|||||||
});
|
});
|
||||||
|
|
||||||
authProviderPrivate.onRefresh(async (_userId, newTokenData: AccessToken) =>
|
authProviderPrivate.onRefresh(async (_userId, newTokenData: AccessToken) =>
|
||||||
tokenManager.updateToken(newTokenData),
|
tokenManager.createTokenFile(newTokenData),
|
||||||
);
|
);
|
||||||
|
|
||||||
authProviderPrivate.addUser(Config.bot_user_id, tokenData, ["chat"]);
|
authProviderPrivate.addUser(Config.bot_user_id, tokenData, ["chat"]);
|
||||||
|
|||||||
@@ -14,17 +14,13 @@ export class TokenManager {
|
|||||||
return JSON.parse(tokenFile);
|
return JSON.parse(tokenFile);
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
console.log(
|
console.log(
|
||||||
`Token file ${this.tokenFilePath} not found. Please run the setup`,
|
`token file ${this.tokenFilePath} not found. please run the setup`,
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateToken(token: AccessToken): Promise<void> {
|
async createTokenFile(tokenData: AccessToken): Promise<void> {
|
||||||
this.createTokenFile(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createTokenFile(tokenData: AccessToken): Promise<void> {
|
|
||||||
const formattedTokens = JSON.stringify(tokenData, null, 4);
|
const formattedTokens = JSON.stringify(tokenData, null, 4);
|
||||||
await fs.writeFile(this.tokenFilePath, formattedTokens, "utf-8");
|
await fs.writeFile(this.tokenFilePath, formattedTokens, "utf-8");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,6 @@ const code = await auth.startCallbackServer(port, 120);
|
|||||||
|
|
||||||
const tokenManager = new TokenManager(botId);
|
const tokenManager = new TokenManager(botId);
|
||||||
|
|
||||||
tokenManager.updateToken(
|
tokenManager.createTokenFile(
|
||||||
await exchangeCode(Config.client_id, Config.client_secret, code, redirectUri),
|
await exchangeCode(Config.client_id, Config.client_secret, code, redirectUri),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user