From 186b4284546c1b17168cafc1fd17bd344028edc3 Mon Sep 17 00:00:00 2001 From: JT2M0L3Y Date: Sat, 1 Feb 2025 20:44:58 -0800 Subject: [PATCH] Update: utility method logs use method name --- src/utils/handlers/chatHistoryHandler.ts | 4 ++-- src/utils/handlers/configHandler.ts | 4 ++-- src/utils/messageNormal.ts | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/handlers/chatHistoryHandler.ts b/src/utils/handlers/chatHistoryHandler.ts index 186e342..40e2405 100644 --- a/src/utils/handlers/chatHistoryHandler.ts +++ b/src/utils/handlers/chatHistoryHandler.ts @@ -64,7 +64,7 @@ export async function clearChannelInfo(filename: string, channel: TextChannel, u * @param user the user's name * @param messages their messages */ -export async function openChannelInfo(filename: string, channel: TextChannel | ThreadChannel, user: string, messages: UserMessage[] = []): Promise { +export async function openChannelInfo(this: any, filename: string, channel: TextChannel | ThreadChannel, user: string, messages: UserMessage[] = []): Promise { const fullFileName = `data/${filename}-${user}.json` if (fs.existsSync(fullFileName)) { fs.readFile(fullFileName, 'utf8', (error, data) => { @@ -95,7 +95,7 @@ export async function openChannelInfo(filename: string, channel: TextChannel | T // only creating it, no need to add anything fs.writeFileSync(fullFileName, JSON.stringify(object, null, 2)) - console.log(`[Util: openChannelInfo] Created '${fullFileName}' in working directory`) + console.log(`[Util: ${this.name}] Created '${fullFileName}' in working directory`) } } diff --git a/src/utils/handlers/configHandler.ts b/src/utils/handlers/configHandler.ts index b347c74..cf78730 100644 --- a/src/utils/handlers/configHandler.ts +++ b/src/utils/handlers/configHandler.ts @@ -10,7 +10,7 @@ import path from 'path' * @param value new value to assign */ // add type of change (server, user) -export function openConfig(filename: string, key: string, value: any) { +export function openConfig(this: any, filename: string, key: string, value: any) { const fullFileName = `data/${filename}` // check if the file exists, if not then make the config file @@ -41,7 +41,7 @@ export function openConfig(filename: string, key: string, value: any) { fs.mkdirSync(directory, { recursive: true }) fs.writeFileSync(`data/${filename}`, JSON.stringify(object, null, 2)) - console.log(`[Util: openConfig] Created '${filename}' in working directory`) + console.log(`[Util: ${this.name}] Created '${filename}' in working directory`) } } diff --git a/src/utils/messageNormal.ts b/src/utils/messageNormal.ts index 969f388..5659ccc 100644 --- a/src/utils/messageNormal.ts +++ b/src/utils/messageNormal.ts @@ -11,6 +11,7 @@ import { AbortableAsyncIterator } from 'ollama/src/utils.js' * @param msgHist message history between user and model */ export async function normalMessage( + this: any, message: Message, ollama: Ollama, model: string, @@ -73,12 +74,11 @@ export async function normalMessage( sentMessage.edit(result) } } catch (error: any) { - console.log(`[Util: messageNormal] Error creating message: ${error.message}`) - if (error.message.includes('fetch failed')) - error.message = 'Missing ollama service on machine' - else if (error.message.includes('try pulling it first')) - error.message = `You do not have the ${model} downloaded. Ask an admin to pull it using the \`pull-model\` command.` - sentMessage.edit(`**Response generation failed.**\n\nReason: ${error.message}`) + console.log(`[Util: ${this.name}] Error creating message: ${error.message}`) + if (error.message.includes('try pulling it first')) + sentMessage.edit(`**Response generation failed.**\n\nReason: You do not have the ${model} downloaded. Ask an admin to pull it using the \`pull-model\` command.`) + else + sentMessage.edit(`**Response generation failed.**\n\nReason: ${error.message}`) } })