* fix: workflow env * update: center title on readme * update: readme goals and format * add: icons in readme * fix: plus margin * update: environment variables in contr. * add: queue for chat history * add: set -e for workflow failure * update: version increment * fix: client null info * fix: shutoff issues
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { Client, GatewayIntentBits } from 'discord.js'
|
|
import { UserMessage, registerEvents } from './utils/events.js'
|
|
import Events from './events/index.js'
|
|
import { Ollama } from 'ollama'
|
|
import { Queue } from './queues/queue.js'
|
|
|
|
// Import keys/tokens
|
|
import Keys from './keys.js'
|
|
|
|
|
|
// initialize the client with the following permissions when logging in
|
|
const client = new Client({
|
|
intents: [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMembers,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.MessageContent
|
|
]
|
|
});
|
|
|
|
// initialize connection to ollama container
|
|
const ollama = new Ollama({
|
|
host: `http://${Keys.ipAddress}:${Keys.portAddress}`,
|
|
})
|
|
|
|
// Create Queue managed by Events
|
|
const messageHistory: Queue<UserMessage> = new Queue<UserMessage>
|
|
|
|
/**
|
|
* register events for bot to listen to in discord
|
|
* @param messageHistory message history for the llm
|
|
* @param Events events to register
|
|
* @param client the bot reference
|
|
* @param Keys tokens from .env files
|
|
*/
|
|
registerEvents(client, Events, messageHistory, Keys, ollama)
|
|
|
|
// Try to log in the client
|
|
await client.login(Keys.clientToken)
|
|
.catch((error) => {
|
|
console.error('[Login Error]', error)
|
|
process.exit(1)
|
|
})
|
|
|
|
// queue up bots name
|
|
messageHistory.enqueue({
|
|
role: 'assistant',
|
|
content: `My name is ${client.user?.username}`
|
|
}) |