kimaki 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/discordBot.js +16 -2
- package/package.json +1 -1
- package/src/discordBot.ts +20 -3
package/dist/discordBot.js
CHANGED
|
@@ -8,6 +8,7 @@ import { spawn, exec } from 'node:child_process';
|
|
|
8
8
|
import fs, { createWriteStream } from 'node:fs';
|
|
9
9
|
import { mkdir } from 'node:fs/promises';
|
|
10
10
|
import net from 'node:net';
|
|
11
|
+
import os from 'node:os';
|
|
11
12
|
import path from 'node:path';
|
|
12
13
|
import { promisify } from 'node:util';
|
|
13
14
|
import { PassThrough, Transform } from 'node:stream';
|
|
@@ -322,7 +323,17 @@ export function frameMono16khz() {
|
|
|
322
323
|
}
|
|
323
324
|
export function getDatabase() {
|
|
324
325
|
if (!db) {
|
|
325
|
-
|
|
326
|
+
// Create ~/.kimaki directory if it doesn't exist
|
|
327
|
+
const kimakiDir = path.join(os.homedir(), '.kimaki');
|
|
328
|
+
try {
|
|
329
|
+
fs.mkdirSync(kimakiDir, { recursive: true });
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
dbLogger.error('Failed to create ~/.kimaki directory:', error);
|
|
333
|
+
}
|
|
334
|
+
const dbPath = path.join(kimakiDir, 'discord-sessions.db');
|
|
335
|
+
dbLogger.log(`Opening database at: ${dbPath}`);
|
|
336
|
+
db = new Database(dbPath);
|
|
326
337
|
// Initialize tables
|
|
327
338
|
db.exec(`
|
|
328
339
|
CREATE TABLE IF NOT EXISTS thread_sessions (
|
|
@@ -1748,7 +1759,10 @@ export async function startDiscordBot({ token, appId, discordClient, }) {
|
|
|
1748
1759
|
}
|
|
1749
1760
|
opencodeServers.clear();
|
|
1750
1761
|
discordLogger.log('Closing database...');
|
|
1751
|
-
|
|
1762
|
+
if (db) {
|
|
1763
|
+
db.close();
|
|
1764
|
+
db = null;
|
|
1765
|
+
}
|
|
1752
1766
|
discordLogger.log('Destroying Discord client...');
|
|
1753
1767
|
discordClient.destroy();
|
|
1754
1768
|
discordLogger.log('Cleanup complete, exiting.');
|
package/package.json
CHANGED
package/src/discordBot.ts
CHANGED
|
@@ -34,6 +34,7 @@ import { spawn, exec, type ChildProcess } from 'node:child_process'
|
|
|
34
34
|
import fs, { createWriteStream } from 'node:fs'
|
|
35
35
|
import { mkdir } from 'node:fs/promises'
|
|
36
36
|
import net from 'node:net'
|
|
37
|
+
import os from 'node:os'
|
|
37
38
|
import path from 'node:path'
|
|
38
39
|
import { promisify } from 'node:util'
|
|
39
40
|
import { PassThrough, Transform, type TransformCallback } from 'node:stream'
|
|
@@ -453,7 +454,19 @@ export function frameMono16khz(): Transform {
|
|
|
453
454
|
|
|
454
455
|
export function getDatabase(): Database.Database {
|
|
455
456
|
if (!db) {
|
|
456
|
-
|
|
457
|
+
// Create ~/.kimaki directory if it doesn't exist
|
|
458
|
+
const kimakiDir = path.join(os.homedir(), '.kimaki')
|
|
459
|
+
|
|
460
|
+
try {
|
|
461
|
+
fs.mkdirSync(kimakiDir, { recursive: true })
|
|
462
|
+
} catch (error) {
|
|
463
|
+
dbLogger.error('Failed to create ~/.kimaki directory:', error)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const dbPath = path.join(kimakiDir, 'discord-sessions.db')
|
|
467
|
+
|
|
468
|
+
dbLogger.log(`Opening database at: ${dbPath}`)
|
|
469
|
+
db = new Database(dbPath)
|
|
457
470
|
|
|
458
471
|
// Initialize tables
|
|
459
472
|
db.exec(`
|
|
@@ -685,7 +698,7 @@ async function processVoiceAttachment({
|
|
|
685
698
|
const apiKeys = getDatabase()
|
|
686
699
|
.prepare('SELECT gemini_api_key FROM bot_api_keys WHERE app_id = ?')
|
|
687
700
|
.get(appId) as { gemini_api_key: string | null } | undefined
|
|
688
|
-
|
|
701
|
+
|
|
689
702
|
if (apiKeys?.gemini_api_key) {
|
|
690
703
|
geminiApiKey = apiKeys.gemini_api_key
|
|
691
704
|
}
|
|
@@ -1534,6 +1547,7 @@ export async function startDiscordBot({
|
|
|
1534
1547
|
discordLogger.log(`Bot Application ID (provided): ${currentAppId}`)
|
|
1535
1548
|
}
|
|
1536
1549
|
|
|
1550
|
+
|
|
1537
1551
|
// List all guilds and channels that belong to this bot
|
|
1538
1552
|
for (const guild of c.guilds.cache.values()) {
|
|
1539
1553
|
discordLogger.log(`${guild.name} (${guild.id})`)
|
|
@@ -2348,7 +2362,10 @@ export async function startDiscordBot({
|
|
|
2348
2362
|
opencodeServers.clear()
|
|
2349
2363
|
|
|
2350
2364
|
discordLogger.log('Closing database...')
|
|
2351
|
-
|
|
2365
|
+
if (db) {
|
|
2366
|
+
db.close()
|
|
2367
|
+
db = null
|
|
2368
|
+
}
|
|
2352
2369
|
|
|
2353
2370
|
discordLogger.log('Destroying Discord client...')
|
|
2354
2371
|
discordClient.destroy()
|