mirror-chatterino2/src/providers/twitch/TwitchMessageBuilder.hpp

143 lines
4.7 KiB
C++
Raw Normal View History

#pragma once
2017-04-12 17:46:44 +02:00
#include "common/Aliases.hpp"
#include "common/Outcome.hpp"
#include "messages/MessageThread.hpp"
#include "messages/SharedMessageBuilder.hpp"
#include "providers/twitch/ChannelPointReward.hpp"
#include "providers/twitch/PubSubActions.hpp"
2019-12-01 13:32:41 +01:00
#include "providers/twitch/TwitchBadge.hpp"
#include "providers/twitch/api/Helix.hpp"
2017-12-31 00:50:07 +01:00
#include <IrcMessage>
2017-04-12 17:46:44 +02:00
#include <QString>
#include <QVariant>
2017-04-12 17:46:44 +02:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
2018-06-26 16:37:59 +02:00
class Channel;
2017-12-31 00:50:07 +01:00
class TwitchChannel;
2017-04-12 17:46:44 +02:00
2022-11-05 11:04:35 +01:00
struct TwitchEmoteOccurrence {
int start;
int end;
EmotePtr ptr;
EmoteName name;
2022-11-05 11:04:35 +01:00
bool operator==(const TwitchEmoteOccurrence &other) const
{
return std::tie(this->start, this->end, this->ptr, this->name) ==
std::tie(other.start, other.end, other.ptr, other.name);
}
};
class TwitchMessageBuilder : public SharedMessageBuilder
2017-04-12 17:46:44 +02:00
{
public:
2017-07-02 18:12:11 +02:00
TwitchMessageBuilder() = delete;
2017-04-12 17:46:44 +02:00
2018-09-30 13:37:39 +02:00
explicit TwitchMessageBuilder(Channel *_channel,
const Communi::IrcPrivateMessage *_ircMessage,
const MessageParseArgs &_args);
2018-09-30 13:37:39 +02:00
explicit TwitchMessageBuilder(Channel *_channel,
const Communi::IrcMessage *_ircMessage,
const MessageParseArgs &_args,
QString content, bool isAction);
2017-07-02 18:12:11 +02:00
TwitchChannel *twitchChannel;
2017-07-02 18:12:11 +02:00
[[nodiscard]] bool isIgnored() const override;
void triggerHighlights() override;
MessagePtr build() override;
2017-04-12 17:46:44 +02:00
void setThread(std::shared_ptr<MessageThread> thread);
void setMessageOffset(int offset);
static void appendChannelPointRewardMessage(
const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
bool isBroadcaster);
// Message in the /live chat for channel going live
static void liveMessage(const QString &channelName,
MessageBuilder *builder);
// Messages in normal chat for channel stuff
static void liveSystemMessage(const QString &channelName,
MessageBuilder *builder);
static void offlineSystemMessage(const QString &channelName,
MessageBuilder *builder);
static void hostingSystemMessage(const QString &channelName,
MessageBuilder *builder, bool hostOn);
static void deletionMessage(const MessagePtr originalMessage,
MessageBuilder *builder);
static void deletionMessage(const DeleteAction &action,
MessageBuilder *builder);
static void listOfUsersSystemMessage(QString prefix, QStringList users,
Channel *channel,
MessageBuilder *builder);
static void listOfUsersSystemMessage(
QString prefix, const std::vector<HelixModerator> &users,
Channel *channel, MessageBuilder *builder);
// Shares some common logic from SharedMessageBuilder::parseBadgeTag
static std::unordered_map<QString, QString> parseBadgeInfoTag(
const QVariantMap &tags);
2022-11-05 11:04:35 +01:00
static std::vector<TwitchEmoteOccurrence> parseTwitchEmotes(
const QVariantMap &tags, const QString &originalMessage,
int messageOffset);
private:
void parseUsernameColor() override;
void parseUsername() override;
2017-07-02 18:12:11 +02:00
void parseMessageID();
void parseRoomID();
void appendUsername();
2022-11-05 11:04:35 +01:00
void runIgnoreReplaces(std::vector<TwitchEmoteOccurrence> &twitchEmotes);
2017-07-02 18:12:11 +02:00
2019-12-01 13:32:41 +01:00
boost::optional<EmotePtr> getTwitchBadge(const Badge &badge);
Outcome tryAppendEmote(const EmoteName &name) override;
2018-08-02 14:23:27 +02:00
void addWords(const QStringList &words,
2022-11-05 11:04:35 +01:00
const std::vector<TwitchEmoteOccurrence> &twitchEmotes);
void addTextOrEmoji(EmotePtr emote) override;
void addTextOrEmoji(const QString &value) override;
2017-07-02 18:12:11 +02:00
2018-01-23 23:28:06 +01:00
void appendTwitchBadges();
void appendChatterinoBadges();
void appendFfzBadges();
void appendSeventvBadges();
2018-08-02 14:23:27 +02:00
Outcome tryParseCheermote(const QString &string);
2018-07-06 19:23:47 +02:00
bool shouldAddModerationElements() const;
2018-07-06 19:23:47 +02:00
QString roomID_;
2018-08-02 14:23:27 +02:00
bool hasBits_ = false;
QString bits;
int bitsLeft;
2019-12-21 10:36:46 +01:00
bool bitsStacked = false;
bool historicalMessage_ = false;
std::shared_ptr<MessageThread> thread_;
2018-07-06 19:23:47 +02:00
/**
* Starting offset to be used on index-based operations on `originalMessage_`.
*
* For example:
* originalMessage_ = "there"
* messageOffset_ = 4
* (the irc message is "hey there")
*
* then the index 6 would resolve to 6 - 4 = 2 => 'e'
*/
int messageOffset_ = 0;
2019-08-23 16:52:04 +02:00
QString userId_;
2018-07-06 19:23:47 +02:00
bool senderIsBroadcaster{};
2017-04-12 17:46:44 +02:00
};
} // namespace chatterino