Compare commits

...

2 commits

Author SHA1 Message Date
c7b36885a3 Fix overflow of the reply of 2000 character
now it will send more than one message if it gets overflown
fixes #6
2023-07-28 09:22:47 +02:00
a0cad7a348 fix and flip empty reply check of the model 2023-07-28 09:12:59 +02:00

View file

@ -110,6 +110,8 @@ function requestReply(
else {
if (!request.deferred)
return request.reply(Object.assign(message, interactionOptions));
else if (request.replied)
return request.followUp(Object.assign(message, interactionOptions));
else
return request.editReply(Object.assign(message, interactionOptions));
}
@ -273,14 +275,26 @@ async function executeFromQueue(channel: string) {
const answerContent = answer.data.choices[0].message?.content;
if (answerContent != undefined || answerContent != "") {
const response = requestReply(message, {content: answerContent}, {allowedMentions: { repliedUser: false }});
response.then(rval => Moderation.checkMessage(rval));
if (answerContent == undefined || answerContent == "") {
if (message instanceof DiscordApi.Message) message.react("😶").catch(/*it's okay*/);
}
else {
if (message instanceof DiscordApi.Message) message.react("😶").catch(/*it's okay*/);
const answerMessagesContent :string[] = [""];
for (const i in answerContent.split(/\n\n/)) {
if (answerMessagesContent[answerMessagesContent.length-1].length + i.length < 2000) {
answerMessagesContent[answerMessagesContent.length-1] += "\n\n" + i;
}
else {
answerMessagesContent.push(i);
}
}
for (const i in answerMessagesContent) {
const response = requestReply(message, {content: i}, {allowedMentions: { repliedUser: false }});
response.then(rval => Moderation.checkMessage(rval));
await response;
}
}
} catch (e) {
console.error(`Error ocurred while handling chat completion request (${(e as object).constructor.name}):`);