summaryrefslogtreecommitdiff
path: root/bot/src/config.hpp
blob: 05ce0f0ac941502dcedbf6d76cde348204cc0646 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once

#include <optional>
#include <sol/sol.hpp>
#include <string>

#define GET_DATABASE_CONNECTION_URL(c)                                      \
  "dbname = " + c.database.name + " user = " + c.database.user +            \
      " password = " + c.database.password + " host = " + c.database.host + \
      " port = " + c.database.port

#define GET_DATABASE_CONNECTION_URL_POINTER(c)                                \
  "dbname = " + c->database.name + " user = " + c->database.user +            \
      " password = " + c->database.password + " host = " + c->database.host + \
      " port = " + c->database.port

namespace bot {
  struct DatabaseConfiguration {
      std::string name;
      std::string user;
      std::string password;
      std::string host;
      std::string port;
  };

  struct TwitchCredentialsConfiguration {
      std::string client_id;
      std::string token;
  };

  struct CommandConfiguration {
      bool join_allowed = true;
      bool join_allow_from_other_chats = false;

      std::optional<std::string> rpost_path = std::nullopt;
  };

  struct OwnerConfiguration {
      std::optional<std::string> name = std::nullopt;
      std::optional<int> id = std::nullopt;
  };

  struct UrlConfiguration {
      std::optional<std::string> help = std::nullopt;
      std::optional<std::string> paste_service = std::nullopt;
      std::optional<std::string> randompost = std::nullopt;
  };

  struct TokenConfiguration {
      std::optional<std::string> github_token = std::nullopt;
  };

  struct Configuration {
      TwitchCredentialsConfiguration twitch_credentials;
      DatabaseConfiguration database;
      CommandConfiguration commands;
      OwnerConfiguration owner;
      UrlConfiguration url;
      TokenConfiguration tokens;

      sol::table as_lua_table(std::shared_ptr<sol::state> luaState) const;
  };

  std::optional<Configuration> parse_configuration_from_file(
      const std::string &file_path);
}