- Rename config.json → seed.json to clarify seeding purpose - Update ConfigManager to be database-first with minimal file fallbacks - Store Discord token in database instead of environment variables - Remove allowedSfxChannels functionality completely - Update seeding script to import token from seed.json to database - Add token field to bot_config table in database schema - Update Docker volume mount to use seed.json - Update gitignore to protect seed.json while allowing seed.example.json Configuration Flow: 1. First run: Import from seed.json to database (one-time seeding) 2. Runtime: All configuration from SQLite database 3. Fallback: Environment variables if database unavailable Security: All sensitive data now stored in encrypted SQLite database 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
81 lines
2.0 KiB
JavaScript
81 lines
2.0 KiB
JavaScript
// Database-first configuration manager
|
|
class ConfigManager {
|
|
constructor() {
|
|
this.databaseService = null; // Will be injected
|
|
}
|
|
|
|
/**
|
|
* Inject database service (to avoid circular dependency)
|
|
*/
|
|
setDatabaseService(databaseService) {
|
|
this.databaseService = databaseService;
|
|
}
|
|
|
|
/**
|
|
* Get bot configuration from database (with environment variable fallbacks)
|
|
*/
|
|
getBotConfig() {
|
|
if (!this.databaseService) {
|
|
// Fallback to environment variables if database not available
|
|
return {
|
|
botName: "GHBot",
|
|
debug: false,
|
|
discord: {
|
|
token: process.env.DISCORD_TOKEN,
|
|
adminUserId: process.env.ADMIN_USER_ID,
|
|
activities: ["Playing sounds", "Serving facts"],
|
|
blacklistedUsers: [],
|
|
},
|
|
};
|
|
}
|
|
|
|
const dbConfig = this.databaseService.getBotConfiguration();
|
|
|
|
return {
|
|
botName: dbConfig.botName || "GHBot",
|
|
debug: dbConfig.debug || false,
|
|
discord: {
|
|
token: dbConfig.token || process.env.DISCORD_TOKEN,
|
|
adminUserId: dbConfig.adminUserId || process.env.ADMIN_USER_ID,
|
|
activities: dbConfig.activities || ["Playing sounds", "Serving facts"],
|
|
blacklistedUsers: dbConfig.blacklistedUsers || [],
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get guild configuration (database only)
|
|
*/
|
|
getGuildConfig(guildId) {
|
|
if (!this.databaseService) {
|
|
// Return minimal default config if database not available
|
|
return {
|
|
id: guildId,
|
|
name: "Unknown Guild",
|
|
internalName: "Unknown Guild",
|
|
prefix: "!",
|
|
enableSfx: true,
|
|
sfxVolume: 0.5,
|
|
enableFunFacts: true,
|
|
enableHamFacts: true,
|
|
allowedRolesForRequest: [],
|
|
};
|
|
}
|
|
|
|
return this.databaseService.getGuildConfig(guildId);
|
|
}
|
|
|
|
/**
|
|
* Get all guild configurations (database only)
|
|
*/
|
|
getAllGuildConfigs() {
|
|
if (!this.databaseService) {
|
|
return [];
|
|
}
|
|
|
|
return this.databaseService.getAllGuildConfigs();
|
|
}
|
|
}
|
|
|
|
module.exports = new ConfigManager();
|