summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-05-07 00:23:22 +0500
committerilotterytea <iltsu@alright.party>2024-05-07 00:23:22 +0500
commit08714a202d0eff3dfd31a4b0dd7f3311b0fd3f0e (patch)
treeefadb1672e8c1b0a8aaaac989e8014b9ec26d5b8 /src
parent9069514f8425932ef998fc8a80b514eb81c88025 (diff)
upd: struct for twitch credentials
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp12
-rw-r--r--src/config.hpp9
-rw-r--r--src/main.cpp17
3 files changed, 21 insertions, 17 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 45209e4..3af6e24 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -19,6 +19,7 @@ namespace bot {
}
Configuration cfg;
+ TwitchCredentialsConfiguration ttv_crd_cfg;
DatabaseConfiguration db_cfg;
std::string line;
@@ -34,12 +35,10 @@ namespace bot {
c = tolower(c);
}
- if (key == "bot_username") {
- cfg.bot_username = value;
- } else if (key == "bot_password") {
- cfg.bot_password = value;
- } else if (key == "bot_client_id") {
- cfg.bot_client_id = value;
+ if (key == "twitch_credentials.client_id") {
+ ttv_crd_cfg.client_id = value;
+ } else if (key == "twitch_credentials.token") {
+ ttv_crd_cfg.token = value;
} else if (key == "db_name") {
db_cfg.name = value;
} else if (key == "db_user") {
@@ -53,6 +52,7 @@ namespace bot {
}
}
+ cfg.twitch_credentials = ttv_crd_cfg;
cfg.database = db_cfg;
return cfg;
diff --git a/src/config.hpp b/src/config.hpp
index afdf396..584fb09 100644
--- a/src/config.hpp
+++ b/src/config.hpp
@@ -17,10 +17,13 @@ namespace bot {
std::string port;
};
+ struct TwitchCredentialsConfiguration {
+ std::string client_id;
+ std::string token;
+ };
+
struct Configuration {
- std::string bot_username;
- std::string bot_password;
- std::string bot_client_id;
+ TwitchCredentialsConfiguration twitch_credentials;
DatabaseConfiguration database;
};
diff --git a/src/main.cpp b/src/main.cpp
index 3fbf024..ecae796 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -25,10 +25,10 @@ int main(int argc, char *argv[]) {
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";
+ if (cfg.twitch_credentials.client_id.empty() ||
+ cfg.twitch_credentials.token.empty()) {
+ std::cerr << "*** TWITCH_CREDENTIALS.CLIENT_ID and "
+ "TWITCH_CREDENTIALS.TOKEN must be set!\n";
return -1;
}
@@ -40,11 +40,12 @@ int main(int argc, char *argv[]) {
return -1;
}
- bot::irc::Client client(cfg.bot_client_id, cfg.bot_password);
+ bot::irc::Client client(cfg.twitch_credentials.client_id,
+ cfg.twitch_credentials.token);
bot::command::CommandLoader command_loader;
bot::loc::Localization localization("localization");
- client.join(cfg.bot_username);
+ client.join(client.get_bot_username());
pqxx::connection conn(GET_DATABASE_CONNECTION_URL(cfg));
pqxx::work work(conn);
@@ -59,8 +60,8 @@ int main(int argc, char *argv[]) {
work.commit();
conn.close();
- bot::api::twitch::HelixClient helix_client(cfg.bot_password,
- cfg.bot_client_id);
+ bot::api::twitch::HelixClient helix_client(cfg.twitch_credentials.token,
+ cfg.twitch_credentials.client_id);
bot::stream::StreamListenerClient stream_listener_client(helix_client, client,
cfg);