130 lines
3.5 KiB
C++
130 lines
3.5 KiB
C++
#pragma once
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <ts6bot/Proxy.hpp>
|
|
|
|
#include <glaze/glaze.hpp>
|
|
|
|
#include "Singleton.hpp"
|
|
|
|
namespace ts6bot
|
|
{
|
|
|
|
enum class LogLevel { Trace, Debug, Info, Warning, Error, Critical, None };
|
|
|
|
struct ServerQueryConfig {
|
|
std::string host{"127.0.0.1"};
|
|
uint16_t port{10022}; // ServerQuery SSH default
|
|
// :contentReference[oaicite:6]{index=6}
|
|
std::string username{"serveradmin"};
|
|
std::string password{};
|
|
int virtual_server_id{1};
|
|
std::string nickname{"ts6bot"};
|
|
};
|
|
|
|
struct AfkConfig {
|
|
bool enabled{true};
|
|
int idle_seconds{600};
|
|
std::uint64_t afk_channel_id{0};
|
|
int poll_interval_ms{5000};
|
|
};
|
|
|
|
struct MusicConfig {
|
|
bool enabled{true};
|
|
std::string youtubeApiToken;
|
|
};
|
|
|
|
struct ProxyConfiguration : public ProxyConfig {
|
|
bool enabled{false};
|
|
};
|
|
|
|
struct Config {
|
|
std::string nickname;
|
|
std::string host;
|
|
std::string channel;
|
|
std::string password;
|
|
LogLevel loggingLevel;
|
|
AfkConfig afk{};
|
|
MusicConfig music{};
|
|
ProxyConfiguration proxy{};
|
|
};
|
|
} // namespace ts6bot
|
|
template <> struct glz::meta<ProxyType> {
|
|
using enum ProxyType;
|
|
static constexpr auto value = enumerate(HTTP, SOCKS5, SOCKS5_HOSTNAME);
|
|
};
|
|
template <> struct glz::meta<ts6bot::LogLevel> {
|
|
using enum ts6bot::LogLevel;
|
|
static constexpr auto value =
|
|
enumerate(Trace, Debug, Info, Warning, Error, Critical, None);
|
|
};
|
|
template <> struct glz::meta<ts6bot::ServerQueryConfig> {
|
|
using T = ts6bot::ServerQueryConfig;
|
|
static constexpr auto value =
|
|
object("host", &T::host, "port", &T::port, "username", &T::username,
|
|
"password", &T::password, "virtual_server_id",
|
|
&T::virtual_server_id, "nickname", &T::nickname);
|
|
};
|
|
|
|
template <> struct glz::meta<ts6bot::AfkConfig> {
|
|
using T = ts6bot::AfkConfig;
|
|
static constexpr auto value =
|
|
object("enabled", &T::enabled, "idle_seconds", &T::idle_seconds,
|
|
"afk_channel_id", &T::afk_channel_id, "poll_interval_ms",
|
|
&T::poll_interval_ms);
|
|
};
|
|
|
|
template <> struct glz::meta<ts6bot::MusicConfig> {
|
|
using T = ts6bot::MusicConfig;
|
|
static constexpr auto value = object(
|
|
"enabled", &T::enabled, "youtubeApiToken", &T::youtubeApiToken);
|
|
};
|
|
template <> struct glz::meta<ts6bot::ProxyConfiguration> {
|
|
using T = ts6bot::ProxyConfiguration;
|
|
static constexpr auto value =
|
|
object("url", &T::url, "username", &T::username, "password",
|
|
&T::password, "type", &T::type, "enabled", &T::enabled);
|
|
};
|
|
template <> struct glz::meta<ts6bot::Config> {
|
|
using T = ts6bot::Config;
|
|
static constexpr auto value = object(
|
|
"nickname", &T::nickname, "host", &T::host, "channel", &T::channel,
|
|
"password", &T::password, "loggingLevel", &T::loggingLevel, "afk",
|
|
&T::afk, "music", &T::music, "proxy", &T::proxy);
|
|
};
|
|
namespace ts6bot
|
|
{
|
|
class Configuration : public Singleton<Configuration>
|
|
{
|
|
friend class Singleton<Configuration>;
|
|
|
|
public:
|
|
|
|
const Config getConfig() const noexcept { return m_config; }
|
|
|
|
Configuration(std::string path)
|
|
{
|
|
auto config = Config();
|
|
std::string buffer;
|
|
auto ec = glz::read_file_json(config, path, buffer);
|
|
if (ec) {
|
|
std::string descriptive_error =
|
|
glz::format_error(ec, buffer);
|
|
std::cerr << "Not found configuration in " << path
|
|
<< " using default" << std::endl;
|
|
std::cerr << descriptive_error << std::endl;
|
|
std::cerr << ec.ec << std::endl;
|
|
m_config = Config();
|
|
}
|
|
this->m_config = config;
|
|
}
|
|
|
|
Config m_config{};
|
|
};
|
|
|
|
// Glaze meta (explicit, stable)
|
|
|
|
} // namespace ts6bot
|
|
|