Add more Twitch chat tag temp vars and properties

This commit is contained in:
Przemek Pawlas
2024-10-05 01:26:38 +02:00
committed by WarmUpTill
parent a4970b1b07
commit 8ecee0070d
5 changed files with 194 additions and 28 deletions

View File

@@ -77,21 +77,53 @@ static void parseTags(const std::string &tags, IRCMessage &message)
continue;
}
if (tagName == "badges" || tagName == "badge-info") {
if (tagName == "badge-info") {
message.properties.badgeInfoString = tagValue;
} else if (tagName == "badges") {
message.properties.badges = parseBadgeTag(tagValue);
message.properties.badgesString = tagValue;
} else if (tagName == "bits") {
message.properties.bits = std::stoi(tagValue);
} else if (tagName == "color") {
message.properties.color = tagValue;
} else if (tagName == "display-name") {
message.properties.displayName = tagValue;
} else if (tagName == "first-msg") {
message.properties.isFirstMessage = tagValue == "1";
} else if (tagName == "emote-only") {
message.properties.isUsingOnlyEmotes = tagValue == "1";
} else if (tagName == "emotes") {
message.properties.emotesString = tagValue;
} else if (tagName == "first-msg") {
message.properties.isFirstMessage = tagValue == "1";
} else if (tagName == "id") {
message.properties.id = tagValue;
} else if (tagName == "mod") {
message.properties.isMod = tagValue == "1";
} else if (tagName == "reply-parent-msg-body") {
message.properties.replyParentBody = tagValue;
} else if (tagName == "reply-parent-display-name") {
message.properties.replyParentDisplayName = tagValue;
} else if (tagName == "reply-parent-msg-id") {
message.properties.replyParentId = tagValue;
} else if (tagName == "reply-parent-user-id") {
message.properties.replyParentUserId = tagValue;
} else if (tagName == "reply-parent-user-login") {
message.properties.replyParentUserLogin = tagValue;
} else if (tagName == "reply-thread-parent-msg-id") {
message.properties.rootParentId = tagValue;
} else if (tagName == "reply-thread-parent-user-login") {
message.properties.rootParentUserLogin = tagValue;
} else if (tagName == "subscriber") {
message.properties.isSubscriber = tagValue == "1";
} else if (tagName == "tmi-sent-ts") {
message.properties.timestamp = std::stoull(tagValue);
} else if (tagName == "turbo") {
message.properties.isTurbo = tagValue == "1";
} else if (tagName == "user-id") {
message.properties.userId = tagValue;
} else if (tagName == "user-type") {
message.properties.userType = tagValue;
} else if (tagName == "vip") {
message.properties.isVIP = tagValue == "1";
}
}
}

View File

@@ -20,24 +20,43 @@ struct IRCMessage {
bool enabled;
};
struct {
std::string badgeInfoString;
std::string badgesString;
std::vector<Badge> badges;
int bits = 0;
std::string color;
std::string displayName;
bool isFirstMessage = false;
bool isUsingOnlyEmotes = false;
std::string emotesString;
bool isFirstMessage = false;
std::string id;
bool isMod = false;
std::string replyParentBody;
std::string replyParentDisplayName;
std::string replyParentId;
std::string replyParentUserId;
std::string replyParentUserLogin;
std::string rootParentId;
std::string rootParentUserLogin;
bool isSubscriber = false;
unsigned long long timestamp;
bool isTurbo = false;
std::string userId;
std::string userType;
bool isVIP = false;
} properties;
struct {
std::string nick;
std::string host;
} source;
struct {
std::string command;
std::variant<std::string, bool, std::vector<std::string>>
parameters;
} command;
std::string message;
};

View File

@@ -41,6 +41,22 @@ const std::vector<ChatMessageProperty::PropertyInfo> ChatMessageProperty::_suppo
return message.properties.isTurbo ==
std::get<bool>(property._value);
}},
{"vip", "AdvSceneSwitcher.condition.twitch.type.chat.properties.vip",
true,
[](const IRCMessage &message, const ChatMessageProperty &property) {
return message.properties.isVIP ==
std::get<bool>(property._value);
}},
{"color",
"AdvSceneSwitcher.condition.twitch.type.chat.properties.color",
std::string(),
[](const IRCMessage &message, const ChatMessageProperty &property) {
auto value = std::get<StringVariable>(property._value);
return !property._regex.Enabled()
? message.properties.color == std::string(value)
: property._regex.Matches(
message.properties.color, value);
}},
{"displayName",
"AdvSceneSwitcher.condition.twitch.type.chat.properties.displayName",
std::string(),

View File

@@ -389,10 +389,47 @@ bool MacroConditionTwitch::CheckChatMessages(TwitchToken &token)
continue;
}
SetTempVarValue("id", message->properties.id);
SetTempVarValue("chat_message", message->message);
SetTempVarValue("user_id", message->properties.userId);
SetTempVarValue("user_login", message->source.nick);
SetTempVarValue("user_name", message->properties.displayName);
SetTempVarValue("chat_message", message->message);
SetTempVarValue("user_type", message->properties.userType);
SetTempVarValue("reply_parent_id",
message->properties.replyParentId);
SetTempVarValue("reply_parent_message",
message->properties.replyParentBody);
SetTempVarValue("reply_parent_user_id",
message->properties.replyParentUserId);
SetTempVarValue("reply_parent_user_login",
message->properties.replyParentUserLogin);
SetTempVarValue("reply_parent_user_name",
message->properties.replyParentDisplayName);
SetTempVarValue("root_parent_id",
message->properties.rootParentId);
SetTempVarValue("root_parent_user_login",
message->properties.rootParentUserLogin);
SetTempVarValue("badge_info",
message->properties.badgeInfoString);
SetTempVarValue("badges", message->properties.badgesString);
SetTempVarValue("bits",
std::to_string(message->properties.bits));
SetTempVarValue("color", message->properties.color);
SetTempVarValue("emotes", message->properties.emotesString);
SetTempVarValue("timestamp",
std::to_string(message->properties.timestamp));
SetTempVarValue("is_first_message",
message->properties.isFirstMessage ? "true"
: "false");
SetTempVarValue("is_mod",
message->properties.isMod ? "true" : "false");
SetTempVarValue("is_subscriber",
message->properties.isSubscriber ? "true"
: "false");
SetTempVarValue("is_turbo",
message->properties.isTurbo ? "true" : "false");
SetTempVarValue("is_vip",
message->properties.isVIP ? "true" : "false");
if (_clearBufferOnMatch) {
_eventBuffer->Clear();
@@ -1236,10 +1273,30 @@ void MacroConditionTwitch::SetupTempVars()
setupTempVarHelper("is_branded_content");
break;
case Condition::CHAT_MESSAGE_RECEIVED:
setupTempVarHelper("id", ".chatReceive");
setupTempVarHelper("chat_message", ".chatReceive");
setupTempVarHelper("user_id", ".chatReceive");
setupTempVarHelper("user_login", ".chatReceive");
setupTempVarHelper("user_name", ".chatReceive");
setupTempVarHelper("user_type", ".chatReceive");
setupTempVarHelper("reply_parent_id", ".chatReceive");
setupTempVarHelper("reply_parent_message", ".chatReceive");
setupTempVarHelper("reply_parent_user_id", ".chatReceive");
setupTempVarHelper("reply_parent_user_login", ".chatReceive");
setupTempVarHelper("reply_parent_user_name", ".chatReceive");
setupTempVarHelper("root_parent_id", ".chatReceive");
setupTempVarHelper("root_parent_user_login", ".chatReceive");
setupTempVarHelper("badge_info", ".chatReceive");
setupTempVarHelper("badges", ".chatReceive");
setupTempVarHelper("bits", ".chatReceive");
setupTempVarHelper("color", ".chatReceive");
setupTempVarHelper("emotes", ".chatReceive");
setupTempVarHelper("timestamp", ".chatReceive");
setupTempVarHelper("is_first_message", ".chatReceive");
setupTempVarHelper("is_mod", ".chatReceive");
setupTempVarHelper("is_subscriber", ".chatReceive");
setupTempVarHelper("is_turbo", ".chatReceive");
setupTempVarHelper("is_vip", ".chatReceive");
break;
default:
break;