Fix Logger things
This commit is contained in:
parent
9a5e3f299d
commit
5723abacdd
22
src/bot.ts
22
src/bot.ts
|
@ -24,7 +24,6 @@ import {
|
||||||
key,
|
key,
|
||||||
} from "./assistant";
|
} from "./assistant";
|
||||||
import { ImagesResponse } from "openai/resources";
|
import { ImagesResponse } from "openai/resources";
|
||||||
import chalk from "chalk";
|
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
const logger = new Logger();
|
const logger = new Logger();
|
||||||
|
@ -36,7 +35,7 @@ export const APPSECRET = process.env.SECRET;
|
||||||
const allVarsFilled = HOST && APPID && APPSECRET;
|
const allVarsFilled = HOST && APPID && APPSECRET;
|
||||||
|
|
||||||
if (!allVarsFilled) {
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ if (!allVarsFilled) {
|
||||||
const session = new GuildData(checkFile("messages.json", "utf-8"));
|
const session = new GuildData(checkFile("messages.json", "utf-8"));
|
||||||
|
|
||||||
session.data.toString()
|
session.data.toString()
|
||||||
? logger.log(`Our conversation is: ${session.data}`)
|
? logger.log("Our conversation is:", session.data)
|
||||||
: logger.log(
|
: logger.log(
|
||||||
"Looks like we're starting fresh, no previous chat history was found.",
|
"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) => {
|
const SELF = await client.whoami().then((response) => {
|
||||||
return response.userId;
|
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.");
|
logger.log("Messages from this userId are automatically ignored.");
|
||||||
|
|
||||||
client.onMessage(async (message) => {
|
client.onMessage(async (message) => {
|
||||||
|
@ -87,7 +86,7 @@ client.connect().then(async () => {
|
||||||
.replace("Please generate: ", "")
|
.replace("Please generate: ", "")
|
||||||
.replace("please generate: ", "")
|
.replace("please generate: ", "")
|
||||||
.replace("without", "|");
|
.replace("without", "|");
|
||||||
logger.log(`Generating image: ${emp(prompt)}`);
|
logger.log("Generating image:", prompt);
|
||||||
|
|
||||||
await client.sendMessage({
|
await client.sendMessage({
|
||||||
converseId: message.converseId,
|
converseId: message.converseId,
|
||||||
|
@ -116,7 +115,7 @@ client.connect().then(async () => {
|
||||||
.replace(/(\[(.*?)\])/g, "")
|
.replace(/(\[(.*?)\])/g, "")
|
||||||
.replace("{BACKEND}", HOST);
|
.replace("{BACKEND}", HOST);
|
||||||
const username = await getUsername(HOST, message.author!);
|
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({
|
await client.sendMessage({
|
||||||
converseId: message.converseId,
|
converseId: message.converseId,
|
||||||
|
@ -153,7 +152,8 @@ client.connect().then(async () => {
|
||||||
JSON.stringify(session.data),
|
JSON.stringify(session.data),
|
||||||
"utf8",
|
"utf8",
|
||||||
);
|
);
|
||||||
logger.log(`Now our conversation is: ${session.data}`);
|
|
||||||
|
logger.log("Now our conversation is:", session.data);
|
||||||
} else {
|
} else {
|
||||||
const username = await getUsername(HOST, message.author!);
|
const username = await getUsername(HOST, message.author!);
|
||||||
|
|
||||||
|
@ -188,9 +188,11 @@ client.connect().then(async () => {
|
||||||
JSON.stringify(session.data),
|
JSON.stringify(session.data),
|
||||||
"utf8",
|
"utf8",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
logger.log("Now our conversation is:", session.data);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`fs write failed: ${err}`);
|
logger.error("fs write failed:", err);
|
||||||
|
|
||||||
await client.sendMessage({
|
await client.sendMessage({
|
||||||
converseId: message.converseId,
|
converseId: message.converseId,
|
||||||
|
@ -231,8 +233,10 @@ client.connect().then(async () => {
|
||||||
JSON.stringify(session.data),
|
JSON.stringify(session.data),
|
||||||
"utf8",
|
"utf8",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
logger.log("Now our conversation is:", session.data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`fs write failed: ${err}`);
|
logger.error("fs write failed:", err);
|
||||||
|
|
||||||
await client.sendMessage({
|
await client.sendMessage({
|
||||||
converseId: message.converseId,
|
converseId: message.converseId,
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
import chalk, { ChalkFunction } from "chalk";
|
import chalk, { ChalkFunction } from "chalk";
|
||||||
|
|
||||||
export class Logger {
|
export class Logger {
|
||||||
private _wrn: ChalkFunction;
|
private _wrn: string;
|
||||||
private _err: ChalkFunction;
|
private _err: string;
|
||||||
private _main: string;
|
private _main: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._wrn = chalk.yellow;
|
this._wrn = chalk.yellow("[WARN] ");
|
||||||
this._err = chalk.red;
|
this._err = chalk.red("[ERROR] ");
|
||||||
|
|
||||||
this._main = chalk.bold.gray("[Tailchat Assistant] ");
|
this._main = chalk.bold.gray("[Tailchat Assistant] ");
|
||||||
}
|
}
|
||||||
|
|
||||||
log(text: any): void {
|
log(text: any, args?: any): void {
|
||||||
console.log(this._main, text);
|
console.log(this._main + text, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
warn(text: any): void {
|
warn(text: any, args?: any): void {
|
||||||
console.warn(this._main, this._wrn(text))
|
console.warn(this._wrn + this._main + text, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
error(text: any): void {
|
error(text: any, args?: any): void {
|
||||||
console.error(this._main, this._err(text));
|
console.error(this._err + this._main + text, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue