From c11118667e356c2cb77b8395e47ef1958f8410ac Mon Sep 17 00:00:00 2001 From: Stef Dunlap Date: Sat, 11 Mar 2023 00:18:45 -0500 Subject: [PATCH] Make commands customizable --- config.example.json | 4 +++- index.js | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config.example.json b/config.example.json index 2646613..64c4870 100644 --- a/config.example.json +++ b/config.example.json @@ -5,5 +5,7 @@ "channels": ["#chatgpt"], "openaiApiKey": "[redacted]", "initialSystemMessage": "You are a helpful assistant.", + "newChatCmd": "!chat", + "contChatCmd": "!cont", "alwaysRemember": false -} \ No newline at end of file +} diff --git a/index.js b/index.js index 018f26b..a1374ae 100644 --- a/index.js +++ b/index.js @@ -66,8 +66,10 @@ const client = new irc.Client(config.server, config.nick, { // listen for messages that start with !chat and call the chatgpt api with a callback that prints the response line by line client.addListener('message', async (from, to, message) => { - let is_chat_cmd = message.startsWith('!chat'); - let is_cont_cmd = message.startsWith('!cont'); + const chatCmd = config.newChatCmd; + const contCmd = config.contChatCmd; + let is_chat_cmd = message.startsWith(chatCmd); + let is_cont_cmd = contCmd.length > 0 && message.startsWith(contCmd); if (is_chat_cmd || is_cont_cmd) { if (context.is_response_in_progress()) { @@ -78,7 +80,7 @@ client.addListener('message', async (from, to, message) => { context.clear(); } context.add_user_prompt(message); - const query = message.slice(6); + const query = message.slice(chatCmd.length + 1); try { await chatgpt(query, context.messages, handleChatGPTResponseLine); context.finish_current_response();