-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventsub.h
89 lines (84 loc) · 3.21 KB
/
eventsub.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include <QDateTime>
#include <QWebSocket>
#include <QJsonObject>
#include <queue>
#include "settings.h"
#include "security.h"
#include "entities.h"
inline const char *SUBSCRIPTION_TYPE_FOLLOW="channel.follow";
inline const char *SUBSCRIPTION_TYPE_REDEMPTION="channel.channel_points_custom_reward_redemption.add";
inline const char *SUBSCRIPTION_TYPE_CHEER="channel.cheer";
inline const char *SUBSCRIPTION_TYPE_RAID="channel.raid";
inline const char *SUBSCRIPTION_TYPE_SUBSCRIPTION="channel.subscribe";
inline const char *SUBSCRIPTION_TYPE_RESUBSCRIPTION="channel.subscription.message";
inline const char *SUBSCRIPTION_TYPE_HYPE_TRAIN_START="channel.hype_train.begin";
inline const char *SUBSCRIPTION_TYPE_HYPE_TRAIN_PROGRESS="channel.hype_train.progress";
inline const char *SUBSCRIPTION_TYPE_HYPE_TRAIN_END="channel.hype_train.end";
enum class MessageType
{
WELCOME,
KEEPALIVE,
NOTIFICATION
};
enum class SubscriptionType
{
UNKNOWN,
CHANNEL_FOLLOW,
CHANNEL_REDEMPTION,
CHANNEL_CHEER,
CHANNEL_RAID,
CHANNEL_SUBSCRIPTION,
CHANNEL_HYPE_TRAIN
};
class EventSub : public QObject
{
Q_OBJECT
using MessageTypes=std::unordered_map<QString,MessageType>;
using SubscriptionTypes=std::unordered_map<QString,SubscriptionType>;
public:
EventSub(Security &security,QObject *parent=nullptr);
void Subscribe();
void Subscribe(const QString &type);
protected:
Security &security;
QString buffer;
MessageTypes messageTypes;
SubscriptionTypes subscriptionTypes; // TODO: find a better name for this
std::queue<QString> defaultTypes;
QWebSocket socket;
QString sessionID;
QTimer keepalive;
ApplicationSetting settingURL;
static const char *SETTINGS_CATEGORY_EVENTS; // TODO: can this be removed later when I switch to modules (linking conflicts with definition in bot.cpp)
void Connect();
void NextSubscription();
const QByteArray ProcessRequest(const SubscriptionType type,const QString &data);
const QString BuildResponse(const QString &data=QString()) const;
std::optional<QString> ExtractPrompt(SubscriptionType type,const QJsonObject &event) const;
signals:
void Print(const QString &message,const QString &operation=QString(),const QString &subsystem=QString("EventSub"));
void EventSubscriptionFailed(const QString &type);
void Unauthorized();
void RateLimitHit();
void Follow();
void Redemption(const QString &login,const QString &viewer,const QString &rewardTitle,const QString &message);
void Cheer(const QString &viewer,const unsigned int count,const QString &message);
void Raid(const QString &raider,const unsigned int viewers);
void HypeTrain(int level,double progress);
void ChannelSubscription(const QString &login,const QString &displayName);
void EventSubscription(const QString &id,const QString &type,const QDateTime &creationDate,const QString &callbackURL);
void EventSubscriptionRemoved(const QString &id);
void ParseCommand(JSON::SignalPayload *payload,const QString &name,const QString &login);
void Connected();
void Disconnected();
protected slots:
void ParseMessage(QString message);
void ParseWelcome(QJsonObject payload);
void ParseNotification(QJsonObject payload);
void Dead();
void SocketClosed();
public slots:
void RequestEventSubscriptionList();
void RemoveEventSubscription(const QString &id);
};