Refactor ask command options and response formatting for improved readability

This commit is contained in:
2025-02-02 14:15:11 -05:00
parent 9c74e724a8
commit b05c4844e0
+5 -13
View File
@@ -21,16 +21,13 @@ module.exports = {
.setName('ask') .setName('ask')
.setDescription('Ask a question to the AI') .setDescription('Ask a question to the AI')
.addStringOption(option => .addStringOption(option =>
option option.setName('prompt').setDescription('Your question or prompt').setRequired(true),
.setName('prompt')
.setDescription('Your question or prompt')
.setRequired(true)
) )
.addBooleanOption(option => .addBooleanOption(option =>
option option
.setName('websearch') .setName('websearch')
.setDescription('Enable web search for more up-to-date information') .setDescription('Enable web search for more up-to-date information')
.setRequired(false) .setRequired(false),
) )
// Only show the websearch option if overrides are allowed // Only show the websearch option if overrides are allowed
.setDMPermission(false), .setDMPermission(false),
@@ -84,13 +81,11 @@ module.exports = {
'HTTP-Referer': 'https://github.com/hllywluis/kekbot.js', 'HTTP-Referer': 'https://github.com/hllywluis/kekbot.js',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
} },
); );
const aiResponse = response.data.choices[0].message.content; const aiResponse = response.data.choices[0].message.content;
const webSearchStatus = webSearchEnabled const webSearchStatus = webSearchEnabled ? '\n> *Web search enabled* 🔍\n' : '';
? '\n> *Web search enabled* 🔍\n'
: '';
const formattedResponse = `> **Question:** ${prompt}${webSearchStatus}\n${aiResponse}`; const formattedResponse = `> **Question:** ${prompt}${webSearchStatus}\n${aiResponse}`;
if (formattedResponse.length <= 2000) { if (formattedResponse.length <= 2000) {
@@ -112,10 +107,7 @@ module.exports = {
// If we're in the middle of a code block, find a safe split point // If we're in the middle of a code block, find a safe split point
const lastCodeBlock = chunk.lastIndexOf('```'); const lastCodeBlock = chunk.lastIndexOf('```');
if ( if (lastCodeBlock !== -1 && !chunk.slice(lastCodeBlock).includes('\n```')) {
lastCodeBlock !== -1 &&
!chunk.slice(lastCodeBlock).includes('\n```')
) {
// Find the last newline before maxLength // Find the last newline before maxLength
const lastNewline = chunk.lastIndexOf('\n'); const lastNewline = chunk.lastIndexOf('\n');
if (lastNewline !== -1) { if (lastNewline !== -1) {