From 5723abacdd0660a1988c8bd3db16968e645246dc Mon Sep 17 00:00:00 2001 From: powermaker450 Date: Fri, 26 Jul 2024 01:40:17 -0400 Subject: [PATCH] Fix Logger things --- src/bot.ts | 22 +++++++++++++--------- src/utils/logger.ts | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 1a0b206..98b31b3 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -24,7 +24,6 @@ import { key, } from "./assistant"; import { ImagesResponse } from "openai/resources"; -import chalk from "chalk"; import dotenv from "dotenv"; dotenv.config(); const logger = new Logger(); @@ -36,7 +35,7 @@ export const APPSECRET = process.env.SECRET; const allVarsFilled = HOST && APPID && APPSECRET; if (!allVarsFilled) { - logger.warn("Not all the required environment variables are filled in."); + logger.error("Not all the required environment variables are filled in."); process.exit(1); } @@ -44,7 +43,7 @@ if (!allVarsFilled) { const session = new GuildData(checkFile("messages.json", "utf-8")); session.data.toString() - ? logger.log(`Our conversation is: ${session.data}`) + ? logger.log("Our conversation is:", session.data) : logger.log( "Looks like we're starting fresh, no previous chat history was found.", ); @@ -61,7 +60,7 @@ client.connect().then(async () => { const SELF = await client.whoami().then((response) => { return response.userId; }); - logger.log(`Our userId is: ${emp(SELF)}`); + logger.log("Our userId is:", SELF); logger.log("Messages from this userId are automatically ignored."); client.onMessage(async (message) => { @@ -87,7 +86,7 @@ client.connect().then(async () => { .replace("Please generate: ", "") .replace("please generate: ", "") .replace("without", "|"); - logger.log(`Generating image: ${emp(prompt)}`); + logger.log("Generating image:", prompt); await client.sendMessage({ converseId: message.converseId, @@ -116,7 +115,7 @@ client.connect().then(async () => { .replace(/(\[(.*?)\])/g, "") .replace("{BACKEND}", HOST); const username = await getUsername(HOST, message.author!); - logger.log(`Analyzing the image at: ${emp(imageData)}`); + logger.log("Analyzing the image at:", imageData); await client.sendMessage({ converseId: message.converseId, @@ -153,7 +152,8 @@ client.connect().then(async () => { JSON.stringify(session.data), "utf8", ); - logger.log(`Now our conversation is: ${session.data}`); + + logger.log("Now our conversation is:", session.data); } else { const username = await getUsername(HOST, message.author!); @@ -188,9 +188,11 @@ client.connect().then(async () => { JSON.stringify(session.data), "utf8", ); + + logger.log("Now our conversation is:", session.data); } } catch (err) { - logger.error(`fs write failed: ${err}`); + logger.error("fs write failed:", err); await client.sendMessage({ converseId: message.converseId, @@ -231,8 +233,10 @@ client.connect().then(async () => { JSON.stringify(session.data), "utf8", ); + + logger.log("Now our conversation is:", session.data); } catch (err) { - logger.error(`fs write failed: ${err}`); + logger.error("fs write failed:", err); await client.sendMessage({ converseId: message.converseId, diff --git a/src/utils/logger.ts b/src/utils/logger.ts index b0ccb4c..aeb40e4 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,27 +1,27 @@ import chalk, { ChalkFunction } from "chalk"; export class Logger { - private _wrn: ChalkFunction; - private _err: ChalkFunction; + private _wrn: string; + private _err: string; private _main: string; constructor() { - this._wrn = chalk.yellow; - this._err = chalk.red; + this._wrn = chalk.yellow("[WARN] "); + this._err = chalk.red("[ERROR] "); - this._main = chalk.bold.gray("[Tailchat Assistant]"); + this._main = chalk.bold.gray("[Tailchat Assistant] "); } - log(text: any): void { - console.log(this._main, text); + log(text: any, args?: any): void { + console.log(this._main + text, args); } - warn(text: any): void { - console.warn(this._main, this._wrn(text)) + warn(text: any, args?: any): void { + console.warn(this._wrn + this._main + text, args); } - error(text: any): void { - console.error(this._main, this._err(text)); + error(text: any, args?: any): void { + console.error(this._err + this._main + text, args); } }