From 7b0f985f18241a35fed559949857e4659fbcc802 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:51:00 +0100 Subject: [PATCH] Add macro properties for 'reward' object in redemption events --- data/locale/en-US.ini | 13 ++++++- plugins/twitch/macro-condition-twitch.cpp | 47 +++++++++++++++++++++-- plugins/twitch/macro-condition-twitch.hpp | 1 + 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index cd8c9e8f..6b90a2d4 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -1602,12 +1602,21 @@ AdvSceneSwitcher.tempVar.twitch.started_at.shoutoutReceived="Shoutout time" AdvSceneSwitcher.tempVar.twitch.started_at.shoutoutReceived.description="The UTC timestamp (in RFC3339 format) of when the moderator sent the Shoutout." AdvSceneSwitcher.tempVar.twitch.id.reward="Reward ID" +AdvSceneSwitcher.tempVar.twitch.id.redemption="Redemption ID" AdvSceneSwitcher.tempVar.twitch.user_id.reward="User ID redeeming the reward" AdvSceneSwitcher.tempVar.twitch.user_login.reward="User login redeeming the reward" AdvSceneSwitcher.tempVar.twitch.user_name.reward="User name redeeming the reward" AdvSceneSwitcher.tempVar.twitch.user_input.reward="User input for reward" -AdvSceneSwitcher.tempVar.twitch.reward.reward="Reward Information" -AdvSceneSwitcher.tempVar.twitch.reward.reward.description="Basic information about the reward that was redeemed, at the time it was redeemed." +AdvSceneSwitcher.tempVar.twitch.reward.reward="Reward Information (JSON)" +AdvSceneSwitcher.tempVar.twitch.reward.reward.description="Basic information about the reward that was redeemed in JSON form, at the time it was redeemed." +AdvSceneSwitcher.tempVar.twitch.reward.id.reward="Reward ID" +AdvSceneSwitcher.tempVar.twitch.reward.id.reward.description="The ID that uniquely identifies the reward." +AdvSceneSwitcher.tempVar.twitch.reward.title.reward="Reward title" +AdvSceneSwitcher.tempVar.twitch.reward.title.reward.description="The reward’s title." +AdvSceneSwitcher.tempVar.twitch.reward.prompt.reward="Reward prompt" +AdvSceneSwitcher.tempVar.twitch.reward.prompt.reward.description="The prompt displayed to the viewer if user input is required." +AdvSceneSwitcher.tempVar.twitch.reward.cost.reward="Reward cost" +AdvSceneSwitcher.tempVar.twitch.reward.cost.reward.description="The reward’s cost, in Channel Points." AdvSceneSwitcher.tempVar.twitch.status.reward="Reward status" AdvSceneSwitcher.tempVar.twitch.status.reward.description="Defaults to unfulfilled. Possible values are unknown, unfulfilled, fulfilled, and canceled." AdvSceneSwitcher.tempVar.twitch.redeemed_at.reward="Redemption time" diff --git a/plugins/twitch/macro-condition-twitch.cpp b/plugins/twitch/macro-condition-twitch.cpp index ccdbc2b4..345527dc 100644 --- a/plugins/twitch/macro-condition-twitch.cpp +++ b/plugins/twitch/macro-condition-twitch.cpp @@ -359,6 +359,42 @@ bool MacroConditionTwitch::CheckChannelLiveEvents() return false; } +bool MacroConditionTwitch::CheckChannelRewardRedemptionEvents() +{ + if (!_eventBuffer) { + return false; + } + + while (!_eventBuffer->Empty()) { + auto event = _eventBuffer->ConsumeMessage(); + if (!event) { + continue; + } + if (_subscriptionID != event->id) { + continue; + } + SetVariableValue(event->ToString()); + setTempVarsHelper(event->data, + [this](const char *id, const char *value) { + SetTempVarValue(id, value); + }); + OBSDataAutoRelease rewardInfo = + obs_data_get_obj(event->data, "reward"); + setTempVarsHelper(rewardInfo, [this](const char *nestedId, + const char *value) { + std::string id = "reward." + std::string(nestedId); + SetTempVarValue(id, value); + }); + + if (_clearBufferOnMatch) { + _eventBuffer->Clear(); + } + return true; + } + + return false; +} + static bool stringMatches(const RegexConfig ®ex, const std::string &string, const std::string &expr) { @@ -621,13 +657,14 @@ bool MacroConditionTwitch::CheckCondition() case Condition::POINTS_REWARD_ADDITION_EVENT: case Condition::POINTS_REWARD_UPDATE_EVENT: case Condition::POINTS_REWARD_DELETION_EVENT: - case Condition::POINTS_REWARD_REDEMPTION_EVENT: - case Condition::POINTS_REWARD_REDEMPTION_UPDATE_EVENT: case Condition::USER_BAN_EVENT: case Condition::USER_UNBAN_EVENT: case Condition::USER_MODERATOR_ADDITION_EVENT: case Condition::USER_MODERATOR_DELETION_EVENT: return CheckChannelGenericEvents(); + case Condition::POINTS_REWARD_REDEMPTION_EVENT: + case Condition::POINTS_REWARD_REDEMPTION_UPDATE_EVENT: + return CheckChannelRewardRedemptionEvents(); case Condition::STREAM_ONLINE_LIVE_EVENT: case Condition::STREAM_ONLINE_PLAYLIST_EVENT: case Condition::STREAM_ONLINE_WATCHPARTY_EVENT: @@ -1218,13 +1255,17 @@ void MacroConditionTwitch::SetupTempVars() break; case Condition::POINTS_REWARD_REDEMPTION_EVENT: case Condition::POINTS_REWARD_REDEMPTION_UPDATE_EVENT: - setupTempVarHelper("id", ".reward"); + setupTempVarHelper("id", ".redemption"); setupTempVarHelper("user_id", ".reward"); setupTempVarHelper("user_login", ".reward"); setupTempVarHelper("user_name", ".reward"); setupTempVarHelper("user_input", ".reward"); setupTempVarHelper("status", ".reward"); setupTempVarHelper("reward", ".reward"); + setupTempVarHelper("reward.id", ".reward"); + setupTempVarHelper("reward.title", ".reward"); + setupTempVarHelper("reward.prompt", ".reward"); + setupTempVarHelper("reward.cost", ".reward"); setupTempVarHelper("redeemed_at", ".reward"); break; case Condition::USER_BAN_EVENT: diff --git a/plugins/twitch/macro-condition-twitch.hpp b/plugins/twitch/macro-condition-twitch.hpp index eba6f480..ded8bbc6 100644 --- a/plugins/twitch/macro-condition-twitch.hpp +++ b/plugins/twitch/macro-condition-twitch.hpp @@ -111,6 +111,7 @@ public: private: bool CheckChannelGenericEvents(); bool CheckChannelLiveEvents(); + bool CheckChannelRewardRedemptionEvents(); bool CheckChatMessages(TwitchToken &token); bool CheckChatUserJoinOrLeave(TwitchToken &token);