Responses cant be too big now!
This commit is contained in:
parent
0969e9065a
commit
2a2942135a
3 changed files with 18 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { ApplyOptions } from '@sapphire/decorators';
|
import { ApplyOptions } from '@sapphire/decorators';
|
||||||
import { Args, Command } from '@sapphire/framework';
|
import { Args, Command } from '@sapphire/framework';
|
||||||
import { Message, blockQuote, codeBlock } from 'discord.js';
|
import { AttachmentBuilder, Message, blockQuote, codeBlock } from 'discord.js';
|
||||||
import { Configuration, OpenAIApi } from 'openai';
|
import { Configuration, OpenAIApi } from 'openai';
|
||||||
|
|
||||||
const configuration = new Configuration({
|
const configuration = new Configuration({
|
||||||
|
@ -53,14 +53,24 @@ export class UserCommand extends Command {
|
||||||
|
|
||||||
const content = blockQuote(`> ${prompt}\n${codeBlock(`${chatCompletion.data.choices[0].message?.content}`)}`);
|
const content = blockQuote(`> ${prompt}\n${codeBlock(`${chatCompletion.data.choices[0].message?.content}`)}`);
|
||||||
|
|
||||||
|
const messageAttachment: AttachmentBuilder[] = [];
|
||||||
|
|
||||||
|
if (content.length > 2000) {
|
||||||
|
messageAttachment.push(
|
||||||
|
new AttachmentBuilder(Buffer.from(`> ${prompt}\n${`${chatCompletion.data.choices[0].message?.content}`}`, 'utf-8'), {
|
||||||
|
name: 'response.txt',
|
||||||
|
description: "Himbot's Response"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (interactionOrMessage instanceof Message) {
|
if (interactionOrMessage instanceof Message) {
|
||||||
return askMessage.edit({
|
return askMessage.edit({
|
||||||
content:
|
content:
|
||||||
content.length < 2000
|
content.length < 2000
|
||||||
? content
|
? content
|
||||||
: `Oops! Discord only allows messages with 2000 characters or less. The prompt used ${
|
: `Discord only allows messages with 2000 characters or less. Please see your response in the attached file!`,
|
||||||
prompt.length
|
files: messageAttachment
|
||||||
} characters and the response took ${content.length - prompt.length}`
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,9 +78,8 @@ export class UserCommand extends Command {
|
||||||
content:
|
content:
|
||||||
content.length < 2000
|
content.length < 2000
|
||||||
? content
|
? content
|
||||||
: `Oops! Discord only allows messages with 2000 characters or less. The prompt used ${
|
: `Discord only allows messages with 2000 characters or less. Please see your response in the attached file!`,
|
||||||
prompt.length
|
files: messageAttachment
|
||||||
} characters and the response took ${content.length - prompt.length}`
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ export class UserCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
return interactionOrMessage.editReply({
|
return interactionOrMessage.editReply({
|
||||||
content: content,
|
content,
|
||||||
files: imageAttachment
|
files: imageAttachment
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ export class UserCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
return interactionOrMessage.editReply({
|
return interactionOrMessage.editReply({
|
||||||
content: content,
|
content,
|
||||||
files: imageAttachment
|
files: imageAttachment
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue