2020-10-18 15:54:48 +02:00
|
|
|
#pragma once
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "common/Aliases.hpp"
|
|
|
|
#include "common/Outcome.hpp"
|
2022-07-31 12:45:25 +02:00
|
|
|
#include "messages/MessageThread.hpp"
|
2020-07-04 15:15:59 +02:00
|
|
|
#include "messages/SharedMessageBuilder.hpp"
|
2020-08-08 15:37:22 +02:00
|
|
|
#include "providers/twitch/ChannelPointReward.hpp"
|
2022-05-07 17:22:39 +02:00
|
|
|
#include "providers/twitch/PubSubActions.hpp"
|
2019-12-01 13:32:41 +01:00
|
|
|
#include "providers/twitch/TwitchBadge.hpp"
|
2022-11-05 12:20:12 +01:00
|
|
|
#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>
|
2017-06-13 21:13:58 +02:00
|
|
|
#include <QVariant>
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
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 {
|
2020-09-26 14:21:46 +02:00
|
|
|
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);
|
|
|
|
}
|
2020-09-26 14:21:46 +02:00
|
|
|
};
|
|
|
|
|
2020-07-04 15:15:59 +02:00
|
|
|
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,
|
2018-06-28 19:38:57 +02:00
|
|
|
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
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
TwitchChannel *twitchChannel;
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2020-07-04 15:15:59 +02:00
|
|
|
[[nodiscard]] bool isIgnored() const override;
|
|
|
|
void triggerHighlights() override;
|
|
|
|
MessagePtr build() override;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void setThread(std::shared_ptr<MessageThread> thread);
|
2022-10-08 16:25:32 +02:00
|
|
|
void setMessageOffset(int offset);
|
2022-07-31 12:45:25 +02:00
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
static void appendChannelPointRewardMessage(
|
2021-08-01 15:44:04 +02:00
|
|
|
const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
|
|
|
|
bool isBroadcaster);
|
2021-05-09 16:17:04 +02:00
|
|
|
|
|
|
|
// Message in the /live chat for channel going live
|
|
|
|
static void liveMessage(const QString &channelName,
|
|
|
|
MessageBuilder *builder);
|
|
|
|
|
|
|
|
// Messages in normal chat for channel stuff
|
2021-05-08 16:46:41 +02:00
|
|
|
static void liveSystemMessage(const QString &channelName,
|
|
|
|
MessageBuilder *builder);
|
|
|
|
static void offlineSystemMessage(const QString &channelName,
|
|
|
|
MessageBuilder *builder);
|
|
|
|
static void hostingSystemMessage(const QString &channelName,
|
2021-06-27 15:50:12 +02:00
|
|
|
MessageBuilder *builder, bool hostOn);
|
2021-06-06 17:51:57 +02:00
|
|
|
static void deletionMessage(const MessagePtr originalMessage,
|
|
|
|
MessageBuilder *builder);
|
2021-06-19 13:56:00 +02:00
|
|
|
static void deletionMessage(const DeleteAction &action,
|
|
|
|
MessageBuilder *builder);
|
2021-11-20 14:53:05 +01:00
|
|
|
static void listOfUsersSystemMessage(QString prefix, QStringList users,
|
|
|
|
Channel *channel,
|
|
|
|
MessageBuilder *builder);
|
2022-11-05 12:20:12 +01:00
|
|
|
static void listOfUsersSystemMessage(
|
|
|
|
QString prefix, const std::vector<HelixModerator> &users,
|
|
|
|
Channel *channel, MessageBuilder *builder);
|
2020-08-08 15:37:22 +02:00
|
|
|
|
2022-05-28 11:55:48 +02:00
|
|
|
// 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);
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
private:
|
2020-07-04 15:15:59 +02:00
|
|
|
void parseUsernameColor() override;
|
|
|
|
void parseUsername() override;
|
2017-07-02 18:12:11 +02:00
|
|
|
void parseMessageID();
|
|
|
|
void parseRoomID();
|
2017-08-12 13:18:48 +02:00
|
|
|
void appendUsername();
|
2020-09-26 14:21:46 +02:00
|
|
|
|
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);
|
2020-10-04 12:47:23 +02:00
|
|
|
Outcome tryAppendEmote(const EmoteName &name) override;
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2020-09-26 14:21:46 +02:00
|
|
|
void addWords(const QStringList &words,
|
2022-11-05 11:04:35 +01:00
|
|
|
const std::vector<TwitchEmoteOccurrence> &twitchEmotes);
|
2020-07-04 15:15:59 +02:00
|
|
|
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();
|
2020-10-25 10:36:00 +01:00
|
|
|
void appendFfzBadges();
|
2022-10-16 13:22:17 +02:00
|
|
|
void appendSeventvBadges();
|
2018-08-02 14:23:27 +02:00
|
|
|
Outcome tryParseCheermote(const QString &string);
|
2018-07-06 19:23:47 +02:00
|
|
|
|
2021-08-14 13:06:58 +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;
|
2019-09-08 12:45:25 +02:00
|
|
|
QString bits;
|
2019-12-19 21:36:02 +01:00
|
|
|
int bitsLeft;
|
2019-12-21 10:36:46 +01:00
|
|
|
bool bitsStacked = false;
|
2019-08-04 14:31:57 +02:00
|
|
|
bool historicalMessage_ = false;
|
2022-07-31 12:45:25 +02:00
|
|
|
std::shared_ptr<MessageThread> thread_;
|
2018-07-06 19:23:47 +02:00
|
|
|
|
2022-10-08 16:25:32 +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
|
|
|
};
|
2017-06-07 10:09:24 +02:00
|
|
|
|
|
|
|
} // namespace chatterino
|