25 struct PubSubChatRoomMessageContentSchema;
26 struct PubSubChatRoomMessageSenderSchema;
27 struct GraphQLChatRoomMessageContentSchema;
28 struct GraphQLChatRoomMessageSenderSchema;
29 struct RoomMessageDeletedSchema;
30 struct EmoticonTokenSchema;
44 const auto& jFragments = value[
"fragments"];
45 if (jFragments.isNull() || !jFragments.isArray())
51 bool firstFragment =
true;
52 for (
const auto& jFragment : jFragments)
54 const auto& jText = jFragment[
"text"];
55 if (!jText.isNull() && jText.isString())
59 const auto& jEmoticon = jFragment[
"emoticon"];
60 const auto& jMention = jFragment[
"mention"];
62 if (!jEmoticon.isNull() && jEmoticon.isObject())
65 const auto& jEmoticonId = jEmoticon[
"id"];
68 info.
tokens.emplace_back(std::make_unique<ttv::chat::EmoticonToken>(text, emoticonId));
72 else if (!jMention.isNull() && jMention.isObject())
75 if (
ParseString(jMention,
"display_name", userName))
77 info.
tokens.emplace_back(std::make_unique<ttv::chat::MentionToken>(userName, text,
false));
83 info.
tokens.emplace_back(std::make_unique<ttv::chat::UrlToken>(text,
false));
90 std::string fragmentText = jText.asString();
95 std::string mePrefix =
"/me ";
99 fragmentText = fragmentText.substr(mePrefix.size());
103 info.
tokens.emplace_back(std::make_unique<ttv::chat::TextToken>(fragmentText));
106 firstFragment =
false;
134 const auto& jBadges = value[
"badges"];
135 if (jBadges.isNull() || !jBadges.isArray())
139 for (
auto& jBadge : jBadges)
145 if (badge.
name ==
"moderator")
149 else if (badge.
name ==
"broadcaster")
153 else if (badge.
name ==
"staff")
157 else if (badge.
name ==
"admin")
161 else if (badge.
name ==
"global_mod")
166 message.
badges.emplace_back(std::move(badge));
185 const auto& jId = value[
"user_id"];
210 const auto& jFragments = value[
"fragments"];
211 if (jFragments.isNull() || !jFragments.isArray())
217 bool firstFragment =
true;
218 for (
const auto& jFragment : jFragments)
220 const auto& jText = jFragment[
"text"];
221 if (!jText.isNull() && jText.isString())
224 std::string text = jText.
asString();
225 const auto& jContent = jFragment[
"content"];
226 if (!jContent.isNull() && jContent.isObject())
233 const auto& jEmoticonId = jContent[
"id"];
236 info.
tokens.emplace_back(std::make_unique<ttv::chat::EmoticonToken>(text, emoticonId));
240 else if (type ==
"User")
242 std::string userName;
243 if (
ParseString(jContent,
"displayName", userName))
245 info.
tokens.emplace_back(std::make_unique<ttv::chat::MentionToken>(userName, text,
false));
252 info.
tokens.emplace_back(std::make_unique<ttv::chat::UrlToken>(text,
false));
262 std::string mePrefix =
"/me ";
266 text = text.substr(mePrefix.size());
270 info.
tokens.emplace_back(std::make_unique<ttv::chat::TextToken>(text));
273 firstFragment =
false;
301 const auto& jBadges = value[
"displayBadges"];
302 if (jBadges.isNull() || !jBadges.isArray())
306 for (
auto& jBadge : jBadges)
312 if (badge.
name ==
"moderator")
316 else if (badge.
name ==
"broadcaster")
321 message.
badges.emplace_back(std::move(badge));
340 const auto& jId = value[
"id"];
347 const auto& jRoles = value[
"roles"];
349 ParseBool(jRoles,
"isGlobalMod", isMode,
false);
351 ParseBool(jRoles,
"isSiteAdmin", isMode,
false);
353 ParseBool(jRoles,
"isStaff", isMode,
false);
403 std::string token = value.
asString();
413 static std::regex isRegexRegex = std::regex(
"[\\|\\\\\\^\\$\\*\\+\\?\\:\\#]");
415 if (std::regex_search(token, isRegexRegex))
417 emoticon.
regex = std::regex(std::string(
"^") + token + std::string(
"$"));
418 emoticon.
match = token;
423 emoticon.
match = token;
bool ParseTimestamp(const json::Value &jTimestamp, Timestamp &result)
bool administrator
An admin.
Definition: chattypes.h:103
bool moderator
A moderator.
Definition: chattypes.h:101
bool StartsWith(const std::string &str, const std::string &prefix)
Definition: chatjsonobjectschemas.h:201
bool ParseBool(const ttv::json::Value &root, const char *key, bool &result)
bool ParseString(const ttv::json::Value &root, const char *key, std::string &result)
static bool Emit(ttv::chat::MessageInfo &message, const ttv::json::Value &value)
Definition: chatjsonobjectschemas.h:387
std::string name
Corresponds to Badge::name.
Definition: chattypes.h:284
Definition: chatjsonobjectschemas.h:291
bool staff
A member of Twitch.
Definition: chattypes.h:104
Definition: chattypes.h:299
std::vector< std::unique_ptr< MessageToken > > tokens
The array of message tokens.
Definition: chattypes.h:315
std::string asString() const
uint32_t Timestamp
Definition: coretypes.h:27
Definition: chatjsonobjectschemas.h:124
static bool Emit(std::vector< std::unique_ptr< ttv::chat::MessageToken >> &tokens, const ttv::json::Value &value)
Definition: chatjsonobjectschemas.h:117
Definition: chattypes.h:293
std::vector< MessageBadge > badges
The array of badges.
Definition: chattypes.h:316
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
static bool Parse(const ttv::json::Value &value, MessageInfo &info)
Definition: chatjsonobjectschemas.h:203
Color GetRandomUserColor(const std::string &username)
static bool Parse(const ttv::json::Value &value, ttv::chat::MessageInfo &message)
Definition: chatjsonobjectschemas.h:293
Flags flags
Any additional details about the message.
Definition: chattypes.h:318
Definition: chattypes.h:652
Represents a JSON value.
Definition: value.h:114
std::string match
Definition: chattypes.h:658
Color nameColorARGB
The current ARGB color of the user's name text.
Definition: chattypes.h:319
bool broadcaster
The broadcaster.
Definition: chattypes.h:102
bool isRegex
Definition: chattypes.h:660
bool ParseUInt32(const json::Value &jValue, uint32_t &result)
bool IsTwitchChatUrl(const std::string &url)
static bool Emit(std::vector< std::unique_ptr< ttv::chat::MessageToken >> &tokens, const ttv::json::Value &value)
Definition: chatjsonobjectschemas.h:284
static bool Emit(Emoticon &message, const ttv::json::Value &value)
Definition: chatjsonobjectschemas.h:430
UserMode userMode
The modes of the user who sent the message.
Definition: chattypes.h:317
std::string displayName
The UTF-8 encoded displayed name.
Definition: chattypes.h:314
Definition: chatjsonobjectschemas.h:35
bool action
Whether or not the message is an action. If true, it should be displayed entirely in the name text co...
Definition: chattypes.h:306
static bool Parse(const ttv::json::Value &value, Emoticon &emoticon)
Definition: chatjsonobjectschemas.h:396
Definition: chattypes.h:282
static bool Emit(ttv::chat::MessageInfo &message, const ttv::json::Value &value)
Definition: chatjsonobjectschemas.h:359
bool globalModerator
A global moderator.
Definition: chattypes.h:106
std::regex regex
Definition: chattypes.h:657
UserId userId
The unique user id.
Definition: chattypes.h:321
void UnescapeEmoticonToken(std::string &token)
static bool Emit(ttv::chat::MessageInfo &message, const ttv::json::Value &value)
Definition: chatjsonobjectschemas.h:194
Definition: chatjsonobjectschemas.h:366
bool deleted
Whether or not the message has been deleted.
Definition: chattypes.h:309
bool ParseUserId(const json::Value &jId, UserId &result)
Definition: chatjsonobjectschemas.h:394
static bool Parse(const ttv::json::Value &value, MessageInfo::Flags &flags)
Definition: chatjsonobjectschemas.h:368
bool ParseColor(const std::string &str, Color &result)
static bool Parse(const ttv::json::Value &value, MessageInfo &info)
Definition: chatjsonobjectschemas.h:37
std::string userName
The UTF-8 encoded user name.
Definition: chattypes.h:313
static bool Parse(const ttv::json::Value &value, ttv::chat::MessageInfo &message)
Definition: chatjsonobjectschemas.h:126
std::string version
Corresponds to BadgeVersion::name.
Definition: chattypes.h:285