diff options
| author | Andrew Lee <andrew@alee14.me> | 2025-03-03 18:57:06 -0500 |
|---|---|---|
| committer | Andrew Lee <andrew@alee14.me> | 2025-03-03 18:57:06 -0500 |
| commit | 11bb9ab6b30314d91209bc9888d95783cc247e98 (patch) | |
| tree | ceddb0f02d0b587deab83c3f13f83f086be23d27 /bot/src/events | |
| parent | fd7f8eba960981482fabf350995bf753feebb176 (diff) | |
| download | AleeBot-11bb9ab6b30314d91209bc9888d95783cc247e98.tar.gz AleeBot-11bb9ab6b30314d91209bc9888d95783cc247e98.tar.bz2 AleeBot-11bb9ab6b30314d91209bc9888d95783cc247e98.zip | |
Added back "addquote"; ollama integration; Cleaned up bot.js
Diffstat (limited to 'bot/src/events')
| -rw-r--r-- | bot/src/events/MessageCreate.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bot/src/events/MessageCreate.js b/bot/src/events/MessageCreate.js new file mode 100644 index 0000000..9394a20 --- /dev/null +++ b/bot/src/events/MessageCreate.js @@ -0,0 +1,46 @@ +import { Events } from 'discord.js'; +import { ollama } from '../utils/ollama.js'; +import { ollamaEnabled, ollamaModel } from '../storage/consts.js'; + +export default { + name: Events.MessageCreate, + async execute(msg) { + if (!msg.client.application?.owner) await msg.client.application?.fetch(); + if (msg.author.bot) return; + if (!msg.guild) return; + + const args = msg.content.slice(`<@${msg.client.user.id}>`.length).trim(); + + if (msg.mentions.has(msg.client.user)) { + if (ollamaEnabled) { + if (!args) return msg.reply('Sorry? What was that?'); + + try { + const response = await ollama.chat({ + model: ollamaModel, + messages: [{ role: 'user', content: args }], + }); + + let content = response.message.content; + content = content.replace(/<think>.*?<\/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 }); + } + } else { + msg.reply({ content }); + } + + } catch (err) { + console.error(err); + msg.reply('Something went wrong.'); + } + } else { + return msg.reply('Sorry, this feature has been turned off.'); + } + + } + } +}; |
