Chatterino
TwitchMessageBuilder.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "common/Aliases.hpp"
4 #include "common/Outcome.hpp"
11 
12 #include <IrcMessage>
13 #include <QString>
14 #include <QVariant>
15 
16 namespace chatterino {
17 
18 struct Emote;
19 using EmotePtr = std::shared_ptr<const Emote>;
20 
21 class Channel;
22 class TwitchChannel;
23 
25  int start;
26  int end;
28  EmoteName name;
29 
30  bool operator==(const TwitchEmoteOccurrence &other) const
31  {
32  return std::tie(this->start, this->end, this->ptr, this->name) ==
33  std::tie(other.start, other.end, other.ptr, other.name);
34  }
35 };
36 
38 {
39 public:
40  TwitchMessageBuilder() = delete;
41 
42  explicit TwitchMessageBuilder(Channel *_channel,
43  const Communi::IrcPrivateMessage *_ircMessage,
44  const MessageParseArgs &_args);
45  explicit TwitchMessageBuilder(Channel *_channel,
46  const Communi::IrcMessage *_ircMessage,
47  const MessageParseArgs &_args,
48  QString content, bool isAction);
49 
51 
52  [[nodiscard]] bool isIgnored() const override;
53  void triggerHighlights() override;
54  MessagePtr build() override;
55 
56  void setThread(std::shared_ptr<MessageThread> thread);
57  void setMessageOffset(int offset);
58 
59  static void appendChannelPointRewardMessage(
60  const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
61  bool isBroadcaster);
62 
63  // Message in the /live chat for channel going live
64  static void liveMessage(const QString &channelName,
65  MessageBuilder *builder);
66 
67  // Messages in normal chat for channel stuff
68  static void liveSystemMessage(const QString &channelName,
69  MessageBuilder *builder);
70  static void offlineSystemMessage(const QString &channelName,
71  MessageBuilder *builder);
72  static void hostingSystemMessage(const QString &channelName,
73  MessageBuilder *builder, bool hostOn);
74  static void deletionMessage(const MessagePtr originalMessage,
75  MessageBuilder *builder);
76  static void deletionMessage(const DeleteAction &action,
77  MessageBuilder *builder);
78  static void listOfUsersSystemMessage(QString prefix, QStringList users,
79  Channel *channel,
80  MessageBuilder *builder);
81  static void listOfUsersSystemMessage(
82  QString prefix, const std::vector<HelixModerator> &users,
83  Channel *channel, MessageBuilder *builder);
84 
85  // Shares some common logic from SharedMessageBuilder::parseBadgeTag
86  static std::unordered_map<QString, QString> parseBadgeInfoTag(
87  const QVariantMap &tags);
88 
89  static std::vector<TwitchEmoteOccurrence> parseTwitchEmotes(
90  const QVariantMap &tags, const QString &originalMessage,
91  int messageOffset);
92 
93 private:
94  void parseUsernameColor() override;
95  void parseUsername() override;
96  void parseMessageID();
97  void parseRoomID();
98  void appendUsername();
99 
100  void runIgnoreReplaces(std::vector<TwitchEmoteOccurrence> &twitchEmotes);
101 
102  boost::optional<EmotePtr> getTwitchBadge(const Badge &badge);
103  Outcome tryAppendEmote(const EmoteName &name) override;
104 
105  void addWords(const QStringList &words,
106  const std::vector<TwitchEmoteOccurrence> &twitchEmotes);
107  void addTextOrEmoji(EmotePtr emote) override;
108  void addTextOrEmoji(const QString &value) override;
109 
110  void appendTwitchBadges();
111  void appendChatterinoBadges();
112  void appendFfzBadges();
113  void appendSeventvBadges();
114  Outcome tryParseCheermote(const QString &string);
115 
116  bool shouldAddModerationElements() const;
117 
118  QString roomID_;
119  bool hasBits_ = false;
120  QString bits;
121  int bitsLeft;
122  bool bitsStacked = false;
123  bool historicalMessage_ = false;
124  std::shared_ptr<MessageThread> thread_;
125 
136  int messageOffset_ = 0;
137 
138  QString userId_;
139  bool senderIsBroadcaster{};
140 };
141 
142 } // namespace chatterino
EmotePtr emote
Definition: InputCompletionPopup.cpp:20
int start
Definition: TwitchMessageBuilder.hpp:25
Definition: TwitchChannel.hpp:60
Definition: Application.cpp:48
Definition: TwitchMessageBuilder.hpp:24
Definition: TwitchMessageBuilder.hpp:37
bool operator==(const TwitchEmoteOccurrence &other) const
Definition: TwitchMessageBuilder.hpp:30
std::shared_ptr< const Emote > EmotePtr
Definition: Emote.hpp:38
Definition: PubSubActions.hpp:97
Definition: Channel.hpp:30
Definition: MessageBuilder.hpp:53
TwitchChannel * twitchChannel
Definition: TwitchMessageBuilder.hpp:50
Definition: SharedMessageBuilder.hpp:14
Definition: ChannelPointReward.hpp:14
Definition: TwitchBadge.hpp:9
std::shared_ptr< const Message > MessagePtr
Definition: Channel.hpp:18
int end
Definition: TwitchMessageBuilder.hpp:26
Definition: MessageBuilder.hpp:43
EmoteName name
Definition: TwitchMessageBuilder.hpp:28
EmotePtr ptr
Definition: TwitchMessageBuilder.hpp:27
Definition: Outcome.hpp:14