1 #pragma once
2 
3 #include "common/Aliases.hpp"
4 #include "common/Outcome.hpp"
5 #include "messages/SharedMessageBuilder.hpp"
6 #include "providers/twitch/ChannelPointReward.hpp"
7 #include "providers/twitch/PubsubActions.hpp"
8 #include "providers/twitch/TwitchBadge.hpp"
9 
10 #include <IrcMessage>
11 #include <QString>
12 #include <QVariant>
13 
14 namespace chatterino {
15 
16 struct Emote;
17 using EmotePtr = std::shared_ptr<const Emote>;
18 
19 class Channel;
20 class TwitchChannel;
21 
22 struct TwitchEmoteOccurence {
23     int start;
24     int end;
25     EmotePtr ptr;
26     EmoteName name;
27 };
28 
29 class TwitchMessageBuilder : public SharedMessageBuilder
30 {
31 public:
32     TwitchMessageBuilder() = delete;
33 
34     explicit TwitchMessageBuilder(Channel *_channel,
35                                   const Communi::IrcPrivateMessage *_ircMessage,
36                                   const MessageParseArgs &_args);
37     explicit TwitchMessageBuilder(Channel *_channel,
38                                   const Communi::IrcMessage *_ircMessage,
39                                   const MessageParseArgs &_args,
40                                   QString content, bool isAction);
41 
42     TwitchChannel *twitchChannel;
43 
44     [[nodiscard]] bool isIgnored() const override;
45     void triggerHighlights() override;
46     MessagePtr build() override;
47 
48     static void appendChannelPointRewardMessage(
49         const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
50         bool isBroadcaster);
51 
52     // Message in the /live chat for channel going live
53     static void liveMessage(const QString &channelName,
54                             MessageBuilder *builder);
55 
56     // Messages in normal chat for channel stuff
57     static void liveSystemMessage(const QString &channelName,
58                                   MessageBuilder *builder);
59     static void offlineSystemMessage(const QString &channelName,
60                                      MessageBuilder *builder);
61     static void hostingSystemMessage(const QString &channelName,
62                                      MessageBuilder *builder, bool hostOn);
63     static void deletionMessage(const MessagePtr originalMessage,
64                                 MessageBuilder *builder);
65     static void deletionMessage(const DeleteAction &action,
66                                 MessageBuilder *builder);
67 
68 private:
69     void parseUsernameColor() override;
70     void parseUsername() override;
71     void parseMessageID();
72     void parseRoomID();
73     void appendUsername();
74 
75     void runIgnoreReplaces(std::vector<TwitchEmoteOccurence> &twitchEmotes);
76 
77     boost::optional<EmotePtr> getTwitchBadge(const Badge &badge);
78     void appendTwitchEmote(const QString &emote,
79                            std::vector<TwitchEmoteOccurence> &vec,
80                            std::vector<int> &correctPositions);
81     Outcome tryAppendEmote(const EmoteName &name) override;
82 
83     void addWords(const QStringList &words,
84                   const std::vector<TwitchEmoteOccurence> &twitchEmotes);
85     void addTextOrEmoji(EmotePtr emote) override;
86     void addTextOrEmoji(const QString &value) override;
87 
88     void appendTwitchBadges();
89     void appendChatterinoBadges();
90     void appendFfzBadges();
91     Outcome tryParseCheermote(const QString &string);
92 
93     QString roomID_;
94     bool hasBits_ = false;
95     QString bits;
96     int bitsLeft;
97     bool bitsStacked = false;
98     bool historicalMessage_ = false;
99 
100     QString userId_;
101     bool senderIsBroadcaster{};
102 };
103 
104 }  // namespace chatterino
105