Message Blocks for Normal Message Style (#37)

* add: if check for message length

* update: version increment

* update: readme
This commit is contained in:
Kevin Dang
2024-04-07 16:09:27 -07:00
committed by GitHub
parent 2bdc7b8583
commit da1f08a070
5 changed files with 13 additions and 9 deletions

View File

@@ -21,7 +21,7 @@ export async function normalMessage(
// bot's respnse
let response: ChatResponse
await message.reply('Generating Response . . .').then(async sentMessage => {
await message.channel.send('Generating Response . . .').then(async sentMessage => {
try {
// Attempt to query model for message
response = await ollama.chat({
@@ -35,9 +35,13 @@ export async function normalMessage(
},
stream: false
})
// edit the 'generic' response to new message
sentMessage.edit(response.message.content)
// check if message length > discord max for normal messages
if (response.message.content.length > 2000) {
sentMessage.edit(response.message.content.slice(0, 2000))
message.channel.send(response.message.content.slice(2000))
} else // edit the 'generic' response to new message
sentMessage.edit(response.message.content)
} catch(error: any) {
console.log(`[Util: messageNormal] Error creating message: ${error.message}`)
sentMessage.edit(`**Response generation failed.**\n\nReason: ${error.message}`)