From a0cad7a34809dc6d45abd76ca95ab6b147e40859 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Fri, 28 Jul 2023 09:12:59 +0200 Subject: [PATCH 1/2] fix and flip empty reply check of the model --- src/execution.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/execution.ts b/src/execution.ts index 038f32e..8e4e083 100644 --- a/src/execution.ts +++ b/src/execution.ts @@ -273,15 +273,14 @@ async function executeFromQueue(channel: string) { const answerContent = answer.data.choices[0].message?.content; - if (answerContent != undefined || answerContent != "") { - + if (answerContent == undefined || answerContent == "") { + if (message instanceof DiscordApi.Message) message.react("😶").catch(/*it's okay*/); + } + else { const response = requestReply(message, {content: answerContent}, {allowedMentions: { repliedUser: false }}); response.then(rval => Moderation.checkMessage(rval)); } - else { - if (message instanceof DiscordApi.Message) message.react("😶").catch(/*it's okay*/); - } } catch (e) { console.error(`Error ocurred while handling chat completion request (${(e as object).constructor.name}):`); console.error(e); From c7b36885a3421ead1b972ee534596363fbde8c3b Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Fri, 28 Jul 2023 09:22:47 +0200 Subject: [PATCH 2/2] Fix overflow of the reply of 2000 character now it will send more than one message if it gets overflown fixes #6 --- src/execution.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/execution.ts b/src/execution.ts index 8e4e083..5982a6f 100644 --- a/src/execution.ts +++ b/src/execution.ts @@ -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)); } @@ -277,9 +279,22 @@ async function executeFromQueue(channel: string) { if (message instanceof DiscordApi.Message) message.react("😶").catch(/*it's okay*/); } else { - const response = requestReply(message, {content: answerContent}, {allowedMentions: { repliedUser: false }}); + 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); + } + } - response.then(rval => Moderation.checkMessage(rval)); + 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}):`);