Files
EchoionCore/include/echoion/core/ConfigLoader.hpp
T

133 lines
3.7 KiB
C++

#pragma once
#include <ConfigTypes.hpp>
#include <Types.hpp>
#include <filesystem>
#include <string>
namespace Echoion::Core
{
// JSON structures for configuration (public for use by Core)
struct BotConfigJson {
std::string botName = "Echoion";
std::string commandPrefix = "!";
float defaultVolume = 0.5f;
uint32_t maxQueueSize = 100;
uint32_t trackTimeout = 30000;
bool autoReconnect = true;
uint32_t reconnectDelay = 5000;
uint32_t maxReconnectAttempts = 5;
std::string preferredQuality = "High";
bool allowPlaylistImports = true;
};
struct YouTubeConfigJson {
std::optional<std::string> youtubeApiKey;
std::optional<std::string> youtubeCookiesPath;
std::optional<std::string> cookiesFromBrowser;
uint32_t ytDlpMaxConcurrent = 4;
bool ytDlpAsyncEnabled = true;
bool enableUrlShortening = true;
};
struct NetworkConfigJson {
// Proxy settings (flat structure for backward compatibility)
std::string proxyType = "HTTP";
std::optional<std::string> proxyHost;
std::optional<uint16_t> proxyPort;
std::optional<std::string> proxyUsername;
std::optional<std::string> proxyPassword;
// RPC settings
bool rpcEnabled = true;
uint16_t rpcPort = 8765;
std::string rpcBindAddress = "127.0.0.1";
};
struct TeamSpeakConfigJson {
std::string address = "localhost";
uint16_t port = 9987;
std::string serverPassword = "";
std::string nickname = "EchoionBot";
std::optional<std::string> defaultChannelId;
std::optional<std::string> channelPassword;
std::vector<uint64_t> adminGroups;
std::vector<uint64_t> djGroups;
std::vector<uint64_t> bannedGroups;
};
struct SecurityConfigJson {
bool requireAuthForAdmin = true;
uint32_t maxLoginAttempts = 5;
uint32_t lockoutDuration = 300000;
uint32_t sessionTimeout = 3600000;
bool enableAuditLog = true;
std::optional<std::string> apiKey;
bool allowCors = false;
std::vector<std::string> corsOrigins;
};
struct FeaturesConfigJson {
bool enableHotReload = true;
bool enableAutoReload = false;
bool enableAutoUpdateCheck = true;
bool autoStartOnSubscribe = true;
bool pauseOnEmptySubscribers = true;
bool resumeOnSubscriberReturn = true;
std::string shuffleMode = "random";
std::string repeatMode = "off";
uint32_t maxHistorySize = 50;
};
struct AdvancedConfigJson {
uint32_t sampleRate = 192000;
uint32_t channels = 2;
uint32_t bufferSize = 7680;
uint32_t commandThreadPoolSize = 4;
uint32_t networkThreadPoolSize = 4;
uint32_t decoderThreads = 2;
bool cacheEnabled = true;
std::string cacheMaxSize = "1GB";
uint32_t cacheTTL = 86400;
uint32_t tempCleanupInterval = 3600;
};
struct AppConfigJson {
BotConfigJson bot;
YouTubeConfigJson youtube;
NetworkConfigJson network;
TeamSpeakConfigJson teamspeak;
SecurityConfigJson security;
FeaturesConfigJson features;
AdvancedConfigJson advanced;
};
// Configuration loader for JSON config files (internal to Core)
class ConfigLoader
{
public:
// Load configuration from JSON file
[[nodiscard]] static Api::Result<Api::AppConfig>
loadFromFile(const std::filesystem::path& path);
// Save configuration to JSON file
[[nodiscard]] static Api::Result<void>
saveToFile(const std::filesystem::path& path,
const Api::AppConfig& config);
// Get default configuration path
[[nodiscard]] static std::filesystem::path getDefaultConfigPath();
// Create default configuration
[[nodiscard]] static Api::AppConfig createDefaultConfig();
// Parse quality string to enum
[[nodiscard]] static Api::AudioQuality
parseQuality(const std::string& str);
[[nodiscard]] static std::string
qualityToString(Api::AudioQuality quality);
};
} // namespace Echoion::Core