mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-12 19:56:06 -05:00
* add redis container * Updated Guides and Goals (#134) * Update README.md * Update commands-guide.md * Update events-guide.md * Update commands-guide.md * Added: redis client * Fixed: redis mock in commands.test.ts * Updated: npm package patches * Fixed: redis ip name in keys.ts * update Node LTS version, workflow env vars * Updated: node package engine requirements * Updated: documentation * fix: upgrade dotenv from 16.4.5 to 16.4.7 (#152) Snyk has created this PR to upgrade dotenv from 16.4.5 to 16.4.7. See this package in npm: dotenv See this project in Snyk: https://app.snyk.io/org/jt2m0l3y/project/d8b070a3-e4a3-457a-977b-7eb6a4a48346?utm_source=github&utm_medium=referral&page=upgrade-pr Co-authored-by: snyk-bot <snyk-bot@snyk.io> * Update: docs patches, connection ordering --------- Co-authored-by: snyk-bot <snyk-bot@snyk.io>
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { Client, GatewayIntentBits } from 'discord.js'
|
|
import { Ollama } from 'ollama'
|
|
import { createClient } from 'redis'
|
|
import { Queue } from './queues/queue.js'
|
|
import { UserMessage, registerEvents } from './utils/index.js'
|
|
import Events from './events/index.js'
|
|
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 redis
|
|
const redis = createClient({
|
|
url: `redis://${Keys.redisHost}:${Keys.redisPort}`,
|
|
})
|
|
|
|
// initialize connection to ollama container
|
|
export const ollama = new Ollama({
|
|
host: `http://${Keys.ipAddress}:${Keys.portAddress}`,
|
|
})
|
|
|
|
// Create Queue managed by Events
|
|
const messageHistory: Queue<UserMessage> = new Queue<UserMessage>
|
|
|
|
// register all events
|
|
registerEvents(client, Events, messageHistory, ollama, Keys.defaultModel)
|
|
|
|
// Try to connect to redis
|
|
await redis.connect()
|
|
.then(() => console.log('[Redis] Connected'))
|
|
.catch((error) => {
|
|
console.error('[Redis] Connection Error', error)
|
|
process.exit(1)
|
|
})
|
|
|
|
// 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}`,
|
|
images: []
|
|
}) |