Skip to content

Commit

Permalink
New version, bug fixes, new error info, and npm scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Best-Codes committed Aug 21, 2024
1 parent f2f6fe0 commit 43a3fb9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
6 changes: 6 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["./src", "./config", "./package.json", "./nodemon.json", "./.env"],
"ext": "js,json",
"ignore": ["node_modules"],
"exec": "node --inspect"
}
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
{
"name": "capybot",
"version": "1.0.2",
"version": "1.0.3",
"description": "Your friendly Capybara Bot is capyble or fulfilling all your Discord needs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/index.js"
"start": "node src/index.js",
"dev": "npx nodemon src/index.js",
"clean": "rm -rf capybot.log",
"update": "npx npm-check -u",
"deploy": "git add . && git commit -m 'update' && git push"
},
"repository": {
"type": "git",
"url": "git+https://github.com/The-Best-Codes/capybot.git"
},
"bugs": {
"url": "https://github.com/The-Best-Codes/capybot/issues"
},
"homepage": "https://github.com/The-Best-Codes/capybot#readme",
"keywords": [
"bot",
"discord",
Expand All @@ -21,5 +33,8 @@
"openai": "^4.56.0",
"perf_hooks": "^0.0.1",
"winston": "^3.14.2"
},
"devDependencies": {
"nodemon": "^3.1.4"
}
}
10 changes: 6 additions & 4 deletions src/events/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ module.exports = {

const response = await generateResponse(userInfo, messageContent, message.channel, initialMessage);

if (initialMessage) {
// The response has already been edited into the initial message
} else {
if (!initialMessage) {
await message.reply(response);
}
} catch (error) {
logger.error('Error in AI response generation:', error);
message.reply('Sorry, I encountered an error while processing your message.');
if (error === 'OPENAI ERROR') {
message.reply('Sorry, I encountered an error while processing your message. [OPENAI ERROR]');
} else {
message.reply('Sorry, I encountered an error while processing your message. [UNCAUGHT MESSAGE ERROR]');
}
}
}
},
Expand Down
8 changes: 3 additions & 5 deletions src/utils/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,9 @@ async function generateResponse(userInfo, message, channel, initialMessage = nul

return content;
} catch (error) {
console.error('Error in generateResponse:', error);
if (error.response) {
console.error('OpenAI API Error:', error.response.data);
}
return 'Sorry, I encountered an error while processing your message.';
console.error('Error in generateResponse.');
throw 'OPENAI ERROR';
// return 'Sorry, I encountered an error while processing your message. [OPENAI ERROR]';
}
}

Expand Down

0 comments on commit 43a3fb9

Please sign in to comment.