feat(eventsub): Add support for channel.moderate Warn (#5932)
* fix(eventsub): Be less strict with strings & vectors
String foo from `{"foo":null}` is now accepted, and returns an empty string
std::vector<String> foo from `{"foo":null}` is now accepted, and returns an empty array
This commit is contained in:
@@ -164,12 +164,12 @@ void Connection::onChannelModerate(
|
||||
const auto now = QDateTime::currentDateTime();
|
||||
|
||||
std::visit(
|
||||
[&](auto &&oAction) {
|
||||
using Action = std::remove_cvref_t<decltype(oAction)>;
|
||||
[&](auto &&action) {
|
||||
using Action = std::remove_cvref_t<decltype(action)>;
|
||||
if constexpr (std::is_same_v<
|
||||
Action, lib::payload::channel_moderate::v2::Vip>)
|
||||
{
|
||||
auto msg = makeVipMessage(channel, now, payload.event, oAction);
|
||||
auto msg = makeVipMessage(channel, now, payload.event, action);
|
||||
runInGuiThread([channel, msg] {
|
||||
channel->addMessage(msg, MessageContext::Original);
|
||||
});
|
||||
@@ -179,7 +179,16 @@ void Connection::onChannelModerate(
|
||||
lib::payload::channel_moderate::v2::Unvip>)
|
||||
{
|
||||
auto msg =
|
||||
makeUnvipMessage(channel, now, payload.event, oAction);
|
||||
makeUnvipMessage(channel, now, payload.event, action);
|
||||
runInGuiThread([channel, msg] {
|
||||
channel->addMessage(msg, MessageContext::Original);
|
||||
});
|
||||
}
|
||||
else if constexpr (std::is_same_v<
|
||||
Action,
|
||||
lib::payload::channel_moderate::v2::Warn>)
|
||||
{
|
||||
auto msg = makeWarnMessage(channel, now, payload.event, action);
|
||||
runInGuiThread([channel, msg] {
|
||||
channel->addMessage(msg, MessageContext::Original);
|
||||
});
|
||||
|
||||
@@ -78,4 +78,66 @@ MessagePtr makeUnvipMessage(
|
||||
return builder.release();
|
||||
}
|
||||
|
||||
MessagePtr makeWarnMessage(
|
||||
TwitchChannel *channel, const QDateTime &time,
|
||||
const lib::payload::channel_moderate::v2::Event &event,
|
||||
const lib::payload::channel_moderate::v2::Warn &action)
|
||||
{
|
||||
MessageBuilder builder;
|
||||
|
||||
QString text;
|
||||
|
||||
builder.emplace<TimestampElement>();
|
||||
builder->flags.set(MessageFlag::System);
|
||||
builder->flags.set(MessageFlag::Timeout);
|
||||
builder->loginName = event.moderatorUserLogin.qt();
|
||||
|
||||
builder.emplace<MentionElement>(
|
||||
event.moderatorUserName.qt(), event.moderatorUserLogin.qt(),
|
||||
MessageColor::System,
|
||||
channel->getUserColor(event.moderatorUserLogin.qt()));
|
||||
text.append(event.moderatorUserLogin.qt() + " ");
|
||||
|
||||
builder.emplaceSystemTextAndUpdate("has warned", text);
|
||||
|
||||
builder
|
||||
.emplace<MentionElement>(action.userName.qt(), action.userLogin.qt(),
|
||||
MessageColor::System,
|
||||
channel->getUserColor(action.userLogin.qt()))
|
||||
->setTrailingSpace(false);
|
||||
text.append(action.userLogin.qt());
|
||||
|
||||
QStringList reasons;
|
||||
|
||||
if (!action.reason.qt().isEmpty())
|
||||
{
|
||||
reasons.append(action.reason.qt());
|
||||
}
|
||||
|
||||
for (const auto &rule : action.chatRulesCited)
|
||||
{
|
||||
if (!rule.qt().isEmpty())
|
||||
{
|
||||
reasons.append(rule.qt());
|
||||
}
|
||||
}
|
||||
|
||||
if (reasons.isEmpty())
|
||||
{
|
||||
builder.emplaceSystemTextAndUpdate(".", text);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.emplaceSystemTextAndUpdate(":", text);
|
||||
builder.emplaceSystemTextAndUpdate(reasons.join(", "), text);
|
||||
}
|
||||
|
||||
builder.message().messageText = text;
|
||||
builder.message().searchText = text;
|
||||
|
||||
builder.message().serverReceivedTime = time;
|
||||
|
||||
return builder.release();
|
||||
}
|
||||
|
||||
} // namespace chatterino::eventsub
|
||||
|
||||
@@ -20,4 +20,10 @@ MessagePtr makeUnvipMessage(
|
||||
const lib::payload::channel_moderate::v2::Event &event,
|
||||
const lib::payload::channel_moderate::v2::Unvip &action);
|
||||
|
||||
/// <MODERATOR> has warned <USER>: <REASON>
|
||||
MessagePtr makeWarnMessage(
|
||||
TwitchChannel *channel, const QDateTime &time,
|
||||
const lib::payload::channel_moderate::v2::Event &event,
|
||||
const lib::payload::channel_moderate::v2::Warn &action);
|
||||
|
||||
} // namespace chatterino::eventsub
|
||||
|
||||
Reference in New Issue
Block a user