#include #include #include #include #include "api/twitch/helix_client.hpp" #include "bundle.hpp" #include "commands/command.hpp" #include "config.hpp" #include "handlers.hpp" #include "irc/client.hpp" #include "irc/message.hpp" #include "localization/localization.hpp" #include "stream.hpp" int main(int argc, char *argv[]) { std::cout << "hi world\n"; std::optional o_cfg = bot::parse_configuration_from_file(".env"); if (!o_cfg.has_value()) { return -1; } bot::Configuration cfg = o_cfg.value(); if (cfg.bot_password.empty() || cfg.bot_username.empty() || cfg.bot_client_id.empty()) { std::cerr << "*** BOT_USERNAME, BOT_CLIENT_ID and BOT_PASSWORD must be set!\n"; return -1; } if (cfg.database.name.empty() || cfg.database.user.empty() || cfg.database.password.empty() || cfg.database.host.empty() || cfg.database.port.empty()) { std::cerr << "*** DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, DB_PORT must be set!\n"; return -1; } bot::irc::Client client(cfg.bot_client_id, cfg.bot_password); bot::command::CommandLoader command_loader; bot::loc::Localization localization("localization"); client.join(cfg.bot_username); pqxx::connection conn(GET_DATABASE_CONNECTION_URL(cfg)); pqxx::work work(conn); auto rows = work.exec("SELECT alias_name FROM channels"); for (const auto &row : rows) { auto name = row[0].as(); client.join(name); } work.commit(); conn.close(); bot::api::twitch::HelixClient helix_client(cfg.bot_password, cfg.bot_client_id); bot::stream::StreamListenerClient stream_listener_client(helix_client, client, cfg); client.on( [&client, &command_loader, &localization, &cfg, &helix_client]( const bot::irc::Message &message) { bot::InstanceBundle bundle{client, helix_client, localization}; pqxx::connection conn(GET_DATABASE_CONNECTION_URL(cfg)); bot::handlers::handle_private_message(bundle, command_loader, message, conn); conn.close(); }); client.run(); stream_listener_client.run_thread(); return 0; }