summaryrefslogtreecommitdiff
path: root/bot/src/rss.hpp
blob: cc925ffd5e816438767f872c28536e5c2c20cd38 (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
#pragma once

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

#include "api/twitch/helix_client.hpp"
#include "config.hpp"
#include "irc/client.hpp"

namespace bot {
  struct RSSMessage {
      std::string title, id, message;
      long timestamp;
  };

  struct RSSEvent {
      std::string name;
      int type;
  };

  struct RSSChannel {
      std::string name, url;
      std::optional<RSSEvent> event;
      std::vector<RSSMessage> messages;

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

  class RSSListener {
    public:
      RSSListener(irc::Client &irc_client,
                  api::twitch::HelixClient &helix_client,
                  Configuration &configuration)
          : irc_client(irc_client),
            helix_client(helix_client),
            configuration(configuration) {};
      ~RSSListener() = default;

      void run();
      void add_channel(const std::string &url);
      void remove_channel(const std::string &url);
      bool has_channel(const std::string &url) const;

    private:
      void add_channels();
      void check_channels();

      std::vector<RSSChannel> channels;
      irc::Client &irc_client;
      api::twitch::HelixClient &helix_client;
      Configuration &configuration;
  };

  std::optional<RSSChannel> get_rss_channel(const std::string &url);
}