From 48a576ab5605ec3ec9272809668b8d7ce91c477e Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sat, 8 Mar 2025 17:23:34 -0500 Subject: Put LLM output on text file; Some fixes in logging; New command --- bot/src/events/MessageCreate.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'bot/src/events/MessageCreate.js') diff --git a/bot/src/events/MessageCreate.js b/bot/src/events/MessageCreate.js index e7af3a8..8753587 100644 --- a/bot/src/events/MessageCreate.js +++ b/bot/src/events/MessageCreate.js @@ -1,4 +1,4 @@ -import { Events } from 'discord.js'; +import {AttachmentBuilder, Events} from 'discord.js'; import { ollama } from '../utils/ollama.js'; import { ollamaGlobal, ollamaModel } from '../storage/consts.js'; import { guildSettings } from '../models/guild-settings.js'; @@ -12,11 +12,11 @@ export default { const guildSetting = await guildSettings.findOne({ where: { guildID: msg.guild.id } }); - const args = msg.content.slice(`<@${msg.client.user.id}>`.length).trim(); + const args = msg.content.slice(`${msg.client.user}`.length).trim(); if (msg.mentions.has(msg.client.user)) { if (!guildSetting.ollamaEnabled) return; - if (!ollamaGlobal) return msg.reply('Sorry, this feature has been turned off.'); + if (!ollamaGlobal) return msg.reply('Sorry, the LLM chatbot feature has been turned off.'); if (!args) return msg.reply('Sorry? What was that?'); try { @@ -26,15 +26,12 @@ export default { }); let content = response.message.content; - content = content.replace(/.*?<\/think>/g, ''); if (content.length > 2000) { - const chunks = content.match(/[\s\S]{1,2000}/g) || []; - for (const chunk of chunks) { - await msg.reply({ content: chunk }); - } + const attachment = new AttachmentBuilder(Buffer.from(content, 'utf-8'), { name: 'output.txt' }); + return await msg.reply({ files: [attachment] }); } else { - await msg.reply({ content }); + return await msg.reply({ content }); } } catch (err) { -- cgit v1.2.3