kythia-core 0.9.4-beta.1 → 0.9.4-beta.3

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/changelog.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.9.4-beta.3](https://github.com/kenndeclouv/kythia-core/compare/v0.9.4-beta.2...v0.9.4-beta.3) (2025-11-10)
6
+
7
+
8
+ ### 🔧 Changed
9
+
10
+ * Enhance KythiaORM with dialect-specific UPSERT queries for improved database compatibility. Adjusted InteractionManager button handler logic for better flexibility in handling interactions. ([2bfafc4](https://github.com/kenndeclouv/kythia-core/commit/2bfafc47e83b06f5f72a57da162d0c6b244bfe6d))
11
+
12
+ ### [0.9.4-beta.2](https://github.com/kenndeclouv/kythia-core/compare/v0.9.4-beta.1...v0.9.4-beta.2) (2025-11-10)
13
+
14
+
15
+ ### ✨ Added
16
+
17
+ * Enhance configuration validation in Kythia by adding checks for required bot and database settings, defaulting to SQLite if no driver is specified, and improving error logging for missing configurations. ([72148fa](https://github.com/kenndeclouv/kythia-core/commit/72148fa6b29a97da026746eb44fa4b8696744cb5))
18
+
5
19
  ### [0.9.4-beta.1](https://github.com/kenndeclouv/kythia-core/compare/v0.9.4-beta.0...v0.9.4-beta.1) (2025-11-09)
6
20
 
7
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kythia-core",
3
- "version": "0.9.4-beta.1",
3
+ "version": "0.9.4-beta.3",
4
4
  "description": "Core library for the Kythia main Discord bot: extensible, modular, and scalable foundation for commands, components, and event management.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/Kythia.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * @file src/Kythia.js
5
5
  * @copyright © 2025 kenndeclouv
6
6
  * @assistant chaa & graa
7
- * @version 0.9.4-beta
7
+ * @version 0.9.4-beta.3
8
8
  *
9
9
  * @description
10
10
  * This file contains the main Bot class - acting as an orchestrator (CEO) that
@@ -97,30 +97,62 @@ class Kythia {
97
97
  * Throws an error if any required config is missing.
98
98
  */
99
99
  _checkRequiredConfig() {
100
- const requiredConfig = [
100
+ const requiredBotConfig = [
101
101
  ['bot', 'token'],
102
102
  ['bot', 'clientId'],
103
103
  ['bot', 'clientSecret'],
104
+ ];
105
+ const missingBotConfigs = [];
106
+ for (const pathArr of requiredBotConfig) {
107
+ let value = this.kythiaConfig;
108
+ for (const key of pathArr) {
109
+ value = value?.[key];
110
+ }
111
+ if (value === undefined || value === null || value === '') {
112
+ missingBotConfigs.push(pathArr.join('.'));
113
+ }
114
+ }
115
+
116
+ if (!this.kythiaConfig.db) this.kythiaConfig.db = {};
117
+
118
+ let driver = this.kythiaConfig.db.driver;
119
+ if (!driver || driver === '') {
120
+ this.kythiaConfig.db.driver = 'sqlite';
121
+ driver = 'sqlite';
122
+ this.logger.info('💡 DB driver not specified. Defaulting to: sqlite');
123
+ } else {
124
+ driver = driver.toLowerCase();
125
+ this.kythiaConfig.db.driver = driver;
126
+ }
127
+
128
+ if (driver === 'sqlite') {
129
+ if (!this.kythiaConfig.db.name || this.kythiaConfig.db.name === '') {
130
+ this.kythiaConfig.db.name = 'kythiadata.sqlite';
131
+ }
132
+ }
133
+
134
+ const requiredDbConfig = [
104
135
  ['db', 'driver'],
105
- ['db', 'host'],
106
- ['db', 'port'],
107
136
  ['db', 'name'],
108
- ['db', 'user'],
109
137
  ];
110
138
 
111
- const missingConfigs = [];
139
+ if (driver !== 'sqlite') {
140
+ requiredDbConfig.push(['db', 'host'], ['db', 'port'], ['db', 'user'], ['db', 'pass']);
141
+ }
112
142
 
113
- for (const pathArr of requiredConfig) {
143
+ const missingDbConfigs = [];
144
+ for (const pathArr of requiredDbConfig) {
114
145
  let value = this.kythiaConfig;
115
146
  for (const key of pathArr) {
116
147
  value = value?.[key];
117
148
  }
118
-
119
149
  if (value === undefined || value === null || value === '') {
120
- missingConfigs.push(pathArr.join('.'));
150
+ missingDbConfigs.push(pathArr.join('.'));
121
151
  }
122
152
  }
123
153
 
154
+ const missingConfigs = missingBotConfigs.concat(missingDbConfigs);
155
+
124
156
  if (missingConfigs.length > 0) {
125
157
  this.logger.error('❌ Required configurations are not set:');
126
158
  for (const missing of missingConfigs) {
@@ -4,7 +4,7 @@
4
4
  * @file src/database/KythiaModel.js
5
5
  * @copyright © 2025 kenndeclouv
6
6
  * @assistant chaa & graa
7
- * @version 0.9.4-beta
7
+ * @version 0.9.4-beta.3
8
8
  *
9
9
  * @description
10
10
  * Caching layer for Sequelize Models, now sharding-aware. When config.db.redis.shard === true,
@@ -4,7 +4,7 @@
4
4
  * @file src/database/KythiaORM.js
5
5
  * @copyright © 2025 kenndeclouv
6
6
  * @assistant chaa & graa
7
- * @version 0.9.4-beta
7
+ * @version 0.9.4-beta.3
8
8
  *
9
9
  * @description
10
10
  * A utility for intelligent, hash-based syncing of Sequelize models.
@@ -448,7 +448,7 @@ async function KythiaORM({ kythiaInstance, sequelize, KythiaModel, logger, confi
448
448
  }
449
449
  }
450
450
 
451
- const modelNamesToSync = modelsToSync.map(m => m.model.name);
451
+ const modelNamesToSync = modelsToSync.map((m) => m.model.name);
452
452
 
453
453
  logger.info(`🔄 Syncing models via sequelize.sync(): ${modelNamesToSync.join(', ')}...`);
454
454
  await sequelize.sync({
@@ -459,16 +459,50 @@ async function KythiaORM({ kythiaInstance, sequelize, KythiaModel, logger, confi
459
459
 
460
460
  logger.info('💾 Updating version hashes in model_versions table...');
461
461
  for (const { model, newHash } of modelsToSync) {
462
- await sequelize.query(
463
- `INSERT INTO ${versionTableName} (model_name, version_hash, updated_at)
464
- VALUES (?, ?, CURRENT_TIMESTAMP)
465
- ON DUPLICATE KEY UPDATE
466
- version_hash = VALUES(version_hash), updated_at = CURRENT_TIMESTAMP`,
467
- {
468
- replacements: [model.name, newHash],
469
- type: sequelize.QueryTypes.INSERT,
470
- }
471
- );
462
+ const dialect = sequelize.getDialect();
463
+ let upsertQuery;
464
+
465
+ switch (dialect) {
466
+ case 'mysql':
467
+ case 'mariadb':
468
+ upsertQuery = `INSERT INTO ${versionTableName} (model_name, version_hash, updated_at)
469
+ VALUES (?, ?, CURRENT_TIMESTAMP)
470
+ ON DUPLICATE KEY UPDATE
471
+ version_hash = VALUES(version_hash), updated_at = CURRENT_TIMESTAMP`;
472
+ break;
473
+
474
+ case 'sqlite':
475
+ case 'postgres':
476
+ upsertQuery = `INSERT INTO ${versionTableName} (model_name, version_hash, updated_at)
477
+ VALUES (?, ?, CURRENT_TIMESTAMP)
478
+ ON CONFLICT(model_name)
479
+ DO UPDATE SET version_hash = excluded.version_hash, updated_at = CURRENT_TIMESTAMP`;
480
+ break;
481
+
482
+ case 'mssql':
483
+ upsertQuery = `MERGE INTO ${versionTableName} AS T
484
+ USING (VALUES (?, ?, CURRENT_TIMESTAMP)) AS S (model_name, version_hash, updated_at)
485
+ ON (T.model_name = S.model_name)
486
+ WHEN MATCHED THEN
487
+ UPDATE SET T.version_hash = S.version_hash, T.updated_at = S.updated_at
488
+ WHEN NOT MATCHED THEN
489
+ INSERT (model_name, version_hash, updated_at)
490
+ VALUES (S.model_name, S.version_hash, S.updated_at);`;
491
+ break;
492
+
493
+ default:
494
+ logger.warn(`Dialect "${dialect}" does not have a custom UPSERT, attempting fallback to ON CONFLICT...`);
495
+ upsertQuery = `INSERT INTO ${versionTableName} (model_name, version_hash, updated_at)
496
+ VALUES (?, ?, CURRENT_TIMESTAMP)
497
+ ON CONFLICT(model_name)
498
+ DO UPDATE SET version_hash = excluded.version_hash, updated_at = CURRENT_TIMESTAMP`;
499
+ }
500
+
501
+ await sequelize.query(upsertQuery, {
502
+ replacements: [model.name, newHash],
503
+
504
+ type: sequelize.QueryTypes.INSERT,
505
+ });
472
506
  }
473
507
 
474
508
  logger.info('✨ Database sync completed successfully!');
@@ -4,10 +4,10 @@
4
4
  * @file src/database/KythiaSequelize.js
5
5
  * @copyright © 2025 kenndeclouv
6
6
  * @assistant chaa & graa
7
- * @version 0.9.4-beta
7
+ * @version 0.9.4-beta.3
8
8
  *
9
9
  * @description
10
- * Main Sequelize connection factory for the application
10
+ * Main Sequelize connection factory for the application.
11
11
  */
12
12
  const { Sequelize } = require('sequelize');
13
13
 
@@ -21,14 +21,35 @@ const { Sequelize } = require('sequelize');
21
21
  */
22
22
  function createSequelizeInstance(config, logger) {
23
23
  const dbConfig = config.db || {};
24
+ if (!config.db) config.db = dbConfig;
24
25
 
25
- const dialect = dbConfig.driver || process.env.DB_DRIVER;
26
- const dbName = dbConfig.name || process.env.DB_NAME;
26
+ let driver = dbConfig.driver || process.env.DB_DRIVER;
27
+ let name = dbConfig.name || process.env.DB_NAME;
28
+
29
+ if (!driver || driver === '') {
30
+ driver = 'sqlite';
31
+ if (logger) logger.info('💡 DB driver not specified. Defaulting to: sqlite');
32
+ } else {
33
+ driver = driver.toLowerCase();
34
+ }
35
+
36
+ if (driver === 'sqlite') {
37
+ if (!name || name === '') {
38
+ name = 'kythiadata.sqlite';
39
+ if (logger) logger.info('💡 DB name for sqlite not specified. Defaulting to: kythiadata.sqlite');
40
+ }
41
+ }
42
+
43
+ dbConfig.driver = driver;
44
+ dbConfig.name = name;
45
+
46
+ const dialect = dbConfig.driver;
47
+ const dbName = dbConfig.name;
27
48
  const dbUser = dbConfig.user || process.env.DB_USER;
28
49
  const dbPassword = dbConfig.password || process.env.DB_PASSWORD;
29
50
  const dbHost = dbConfig.host || process.env.DB_HOST;
30
51
  const dbPort = dbConfig.port || process.env.DB_PORT;
31
- const dbStorage = dbConfig.storagePath || process.env.DB_STORAGE_PATH;
52
+
32
53
  const dbSocket = dbConfig.socketPath || process.env.DB_SOCKET_PATH;
33
54
  const dbSsl = dbConfig.ssl || process.env.DB_SSL;
34
55
  const dbDialectOptions = dbConfig.dialectOptions || process.env.DB_DIALECT_OPTIONS;
@@ -45,12 +66,16 @@ function createSequelizeInstance(config, logger) {
45
66
  charset: 'utf8mb4',
46
67
  collate: 'utf8mb4_unicode_ci',
47
68
  },
48
- timezone: dbConfig.timezone || '+00:00',
49
69
  };
50
70
 
71
+ if (dialect !== 'sqlite') {
72
+ seqConfig.timezone = dbConfig.timezone || '+00:00';
73
+ }
74
+
51
75
  switch (dialect) {
52
76
  case 'sqlite':
53
- seqConfig.storage = dbStorage;
77
+ seqConfig.storage = dbConfig.name;
78
+ delete seqConfig.database;
54
79
  break;
55
80
 
56
81
  case 'mysql':
@@ -4,7 +4,7 @@
4
4
  * @file src/managers/AddonManager.js
5
5
  * @copyright © 2025 kenndeclouv
6
6
  * @assistant chaa & graa
7
- * @version 0.9.4-beta
7
+ * @version 0.9.4-beta.3
8
8
  *
9
9
  * @description
10
10
  * Handles all addon loading, command registration, and component management.
@@ -4,7 +4,7 @@
4
4
  * @file src/managers/EventManager.js
5
5
  * @copyright © 2025 kenndeclouv
6
6
  * @assistant chaa & graa
7
- * @version 0.9.4-beta
7
+ * @version 0.9.4-beta.3
8
8
  *
9
9
  * @description
10
10
  * Handles all Discord event listeners except InteractionCreate.
@@ -4,7 +4,7 @@
4
4
  * @file src/managers/InteractionManager.js
5
5
  * @copyright © 2025 kenndeclouv
6
6
  * @assistant chaa & graa
7
- * @version 0.9.4-beta
7
+ * @version 0.9.4-beta.3
8
8
  *
9
9
  * @description
10
10
  * Handles all Discord interaction events including slash commands, buttons, modals,
@@ -280,8 +280,19 @@ class InteractionManager {
280
280
  * @private
281
281
  */
282
282
  async _handleButton(interaction) {
283
- const handler = this.buttonHandlers.get(interaction.customId.split('_')[0]);
284
- if (handler) await handler(interaction, this.container);
283
+ const customIdPrefix = interaction.customId.includes('|')
284
+ ? interaction.customId.split('|')[0]
285
+ : interaction.customId.split(':')[0];
286
+
287
+ const handler = this.buttonHandlers.get(customIdPrefix);
288
+
289
+ if (handler) {
290
+ if (handler.length === 2) {
291
+ await handler(interaction, this.container);
292
+ } else {
293
+ await handler(interaction);
294
+ }
295
+ }
285
296
  }
286
297
 
287
298
  /**
@@ -4,7 +4,7 @@
4
4
  * @file src/managers/ShutdownManager.js
5
5
  * @copyright © 2025 kenndeclouv
6
6
  * @assistant chaa & graa
7
- * @version 0.9.4-beta
7
+ * @version 0.9.4-beta.3
8
8
  *
9
9
  * @description
10
10
  * Handles graceful shutdown procedures including interval tracking,