Skip to content

Commit

Permalink
Add reward.cost reward.id, reward.title filter variables (#5275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mm2PL committed Mar 30, 2024
1 parent 09b2c53 commit 69bdac9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
- Minor: Image links now reflect the scale of their image instead of an internal label. (#5201)
- Minor: IPC files are now stored in the Chatterino directory instead of system directories on Windows. (#5226)
- Minor: 7TV emotes now have a 4x image rather than a 3x image. (#5209)
- Minor: Add `reward.cost` `reward.id`, `reward.title` filter variables. (#5275)
- Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840)
- Bugfix: Fixed the `/shoutout` command not working with usernames starting with @'s (e.g. `/shoutout @forsen`). (#4800)
- Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848)
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/filters/lang/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)
vars["channel.live"] = false;
}
}
if (m->reward != nullptr)
{
vars["reward.title"] = m->reward->title;
vars["reward.cost"] = m->reward->cost;
vars["reward.id"] = m->reward->id;
}
else
{
vars["reward.title"] = "";
vars["reward.cost"] = -1;
vars["reward.id"] = "";
}
return vars;
}

Expand Down
3 changes: 3 additions & 0 deletions src/controllers/filters/lang/Filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ static const QMap<QString, Type> MESSAGE_TYPING_CONTEXT = {
{"flags.monitored", Type::Bool},
{"message.content", Type::String},
{"message.length", Type::Int},
{"reward.title", Type::String},
{"reward.cost", Type::Int},
{"reward.id", Type::String},
};

ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel);
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/filters/lang/Tokenizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ static const QMap<QString, QString> validIdentifiersMap = {
{"flags.restricted", "restricted message?"},
{"flags.monitored", "monitored message?"},
{"message.content", "message text"},
{"message.length", "message length"}};
{"message.length", "message length"},
{"reward.title", "point reward title"},
{"reward.cost", "point reward cost"},
{"reward.id", "point reward id"},
};

// clang-format off
static const QRegularExpression tokenRegex(
Expand Down
3 changes: 3 additions & 0 deletions src/messages/Message.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "common/FlagsEnum.hpp"
#include "providers/twitch/ChannelPointReward.hpp"
#include "util/QStringHash.hpp"

#include <magic_enum/magic_enum.hpp>
Expand Down Expand Up @@ -107,6 +108,8 @@ struct Message {
std::vector<std::unique_ptr<MessageElement>> elements;

ScrollbarHighlight getScrollBarHighlight() const;

std::shared_ptr<ChannelPointReward> reward = nullptr;
};

} // namespace chatterino
Expand Down
2 changes: 2 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,8 @@ void TwitchMessageBuilder::appendChannelPointRewardMessage(
builder->message().messageText = textList.join(" ");
builder->message().searchText = textList.join(" ");
builder->message().loginName = reward.user.login;

builder->message().reward = std::make_shared<ChannelPointReward>(reward);
}

void TwitchMessageBuilder::liveMessage(const QString &channelName,
Expand Down
14 changes: 14 additions & 0 deletions src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,20 @@ void addHiddenContextMenuItems(QMenu *menu,
jsonObject["searchText"] = message->searchText;
jsonObject["messageText"] = message->messageText;
jsonObject["flags"] = qmagicenum::enumFlagsName(message->flags.value());
if (message->reward)
{
QJsonObject reward;
reward["id"] = message->reward->id;
reward["title"] = message->reward->title;
reward["cost"] = message->reward->cost;
reward["isUserInputRequired"] =
message->reward->isUserInputRequired;
jsonObject["reward"] = reward;
}
else
{
jsonObject["reward"] = QJsonValue();
}

jsonDocument.setObject(jsonObject);

Expand Down

0 comments on commit 69bdac9

Please sign in to comment.