Chatterino
MessageBuilder.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <QRegularExpression>
6 #include <ctime>
7 #include <utility>
8 
9 namespace chatterino {
10 struct BanAction;
11 struct UnbanAction;
12 struct AutomodAction;
13 struct AutomodUserAction;
14 struct AutomodInfoAction;
15 struct Message;
16 using MessagePtr = std::shared_ptr<const Message>;
17 
19 };
21 };
23 };
25 };
27 };
29 };
36 
37 MessagePtr makeSystemMessage(const QString &text);
38 MessagePtr makeSystemMessage(const QString &text, const QTime &time);
39 std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
40  const AutomodAction &action);
42 
44  bool disablePingSounds = false;
45  bool isReceivedWhisper = false;
46  bool isSentWhisper = false;
47  bool trimSubscriberUsername = false;
48  bool isStaffOrBroadcaster = false;
49  bool isSubscriptionMessage = false;
50  QString channelPointRewardId = "";
51 };
52 
54 {
55 public:
57  MessageBuilder(SystemMessageTag, const QString &text,
58  const QTime &time = QTime::currentTime());
59  MessageBuilder(TimeoutMessageTag, const QString &timeoutUser,
60  const QString &sourceUser, const QString &systemMessageText,
61  int times, const QTime &time = QTime::currentTime());
62  MessageBuilder(TimeoutMessageTag, const QString &username,
63  const QString &durationInSeconds, bool multipleTimes,
64  const QTime &time = QTime::currentTime());
65  MessageBuilder(const BanAction &action, uint32_t count = 1);
66  MessageBuilder(const UnbanAction &action);
67  MessageBuilder(const AutomodUserAction &action);
68 
69  MessageBuilder(LiveUpdatesAddEmoteMessageTag, const QString &platform,
70  const QString &actor,
71  const std::vector<QString> &emoteNames);
72  MessageBuilder(LiveUpdatesRemoveEmoteMessageTag, const QString &platform,
73  const QString &actor,
74  const std::vector<QString> &emoteNames);
75  MessageBuilder(LiveUpdatesUpdateEmoteMessageTag, const QString &platform,
76  const QString &actor, const QString &emoteName,
77  const QString &oldEmoteName);
78  MessageBuilder(LiveUpdatesUpdateEmoteSetMessageTag, const QString &platform,
79  const QString &actor, const QString &emoteSetName);
80 
81  virtual ~MessageBuilder() = default;
82 
83  Message *operator->();
84  Message &message();
85  MessagePtr release();
86  std::weak_ptr<Message> weakOf();
87 
88  void append(std::unique_ptr<MessageElement> element);
89  QString matchLink(const QString &string);
90  void addLink(const QString &origLink, const QString &matchedLink);
91 
97  void addIrcMessageText(const QString &text);
98 
99  template <typename T, typename... Args>
100  // clang-format off
101  // clang-format can be enabled once clang-format v11+ has been installed in CI
102  T *emplace(Args &&...args)
103  // clang-format on
104  {
105  static_assert(std::is_base_of<MessageElement, T>::value,
106  "T must extend MessageElement");
107 
108  auto unique = std::make_unique<T>(std::forward<Args>(args)...);
109  auto pointer = unique.get();
110  this->append(std::move(unique));
111  return pointer;
112  }
113 
114 protected:
115  virtual void addTextOrEmoji(EmotePtr emote);
116  virtual void addTextOrEmoji(const QString &value);
117 
119 
120 private:
121  // Helper method that emplaces some text stylized as system text
122  // and then appends that text to the QString parameter "toUpdate".
123  // Returns the TextElement that was emplaced.
124  TextElement *emplaceSystemTextAndUpdate(const QString &text,
125  QString &toUpdate);
126 
135  void addIrcWord(const QString &text, const QColor &color,
136  bool addSpace = true);
137 
138  std::shared_ptr<Message> message_;
139 };
140 
141 } // namespace chatterino
EmotePtr emote
Definition: InputCompletionPopup.cpp:20
Definition: MessageColor.hpp:8
Definition: MessageElement.hpp:256
const SystemMessageTag systemMessage
Definition: MessageBuilder.hpp:30
const LiveUpdatesUpdateEmoteMessageTag liveUpdatesUpdateEmoteMessage
Definition: MessageBuilder.hpp:32
Definition: MessageBuilder.hpp:24
Definition: PubSubActions.hpp:148
std::pair< MessagePtr, MessagePtr > makeAutomodMessage(const AutomodAction &action)
Definition: MessageBuilder.cpp:141
const TimeoutMessageTag timeoutMessage
Definition: MessageBuilder.hpp:31
Definition: Application.cpp:48
MessagePtr makeSystemMessage(const QString &text)
Definition: MessageBuilder.cpp:69
T * emplace(Args &&...args)
Definition: MessageBuilder.hpp:102
MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action)
Definition: MessageBuilder.cpp:88
Definition: MessageBuilder.hpp:22
Definition: MessageColor.hpp:9
std::shared_ptr< const Emote > EmotePtr
Definition: Emote.hpp:38
Definition: PubSubActions.hpp:82
Definition: PubSubActions.hpp:106
Definition: PubSubActions.hpp:164
Definition: MessageBuilder.hpp:26
Command line arguments passed to Chatterino.
Definition: Args.hpp:10
Definition: MessageBuilder.hpp:20
Definition: MessageBuilder.hpp:53
const LiveUpdatesUpdateEmoteSetMessageTag liveUpdatesUpdateEmoteSetMessage
Definition: MessageBuilder.hpp:35
std::shared_ptr< const Message > MessagePtr
Definition: Channel.hpp:18
Definition: Message.hpp:54
Definition: PubSubActions.hpp:136
const LiveUpdatesAddEmoteMessageTag liveUpdatesAddEmoteMessage
Definition: MessageBuilder.hpp:34
Definition: MessageBuilder.hpp:43
Definition: MessageBuilder.hpp:28
Definition: MessageBuilder.hpp:18
std::weak_ptr< T > weakOf(T *element)
Definition: Common.hpp:44
const LiveUpdatesRemoveEmoteMessageTag liveUpdatesRemoveEmoteMessage
Definition: MessageBuilder.hpp:33