summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-04-30 00:57:09 +0500
committerilotterytea <iltsu@alright.party>2024-04-30 00:57:09 +0500
commit4eb4d18ea4ddaf927f8a37bc702228f7ef468c40 (patch)
tree87c1e474d116fad3bd252732ec9cfca05026a117 /src
parentd8d62ca07f55b88674b3c59d95c7eb7e8b2e4f4d (diff)
feat: database configuration
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp13
-rw-r--r--src/config.hpp9
-rw-r--r--src/main.cpp8
3 files changed, 30 insertions, 0 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 2d1b876..1a11f0b 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -19,6 +19,7 @@ namespace bot {
}
Configuration cfg;
+ DatabaseConfiguration db_cfg;
std::string line;
while (std::getline(ifs, line, '\n')) {
@@ -37,9 +38,21 @@ namespace bot {
cfg.bot_username = value;
} else if (key == "bot_password") {
cfg.bot_password = value;
+ } else if (key == "db_name") {
+ db_cfg.name = value;
+ } else if (key == "db_user") {
+ db_cfg.user = value;
+ } else if (key == "db_password") {
+ db_cfg.password = value;
+ } else if (key == "db_host") {
+ db_cfg.host = value;
+ } else if (key == "db_port") {
+ db_cfg.port = value;
}
}
+ cfg.database = db_cfg;
+
return cfg;
}
}
diff --git a/src/config.hpp b/src/config.hpp
index 3c10d86..6f4c765 100644
--- a/src/config.hpp
+++ b/src/config.hpp
@@ -4,9 +4,18 @@
#include <string>
namespace bot {
+ struct DatabaseConfiguration {
+ std::string name;
+ std::string user;
+ std::string password;
+ std::string host;
+ std::string port;
+ };
+
struct Configuration {
std::string bot_username;
std::string bot_password;
+ DatabaseConfiguration database;
};
std::optional<Configuration> parse_configuration_from_file(
diff --git a/src/main.cpp b/src/main.cpp
index 7ba4c2e..9593863 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -26,6 +26,14 @@ int main(int argc, char *argv[]) {
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_username, cfg.bot_password);
bot::command::CommandLoader command_loader;
bot::loc::Localization localization("localization");