feat(eventsub): implement channel.chat.user_message_(hold/update) (#6008)

This commit is contained in:
pajlada
2025-03-01 17:00:40 +01:00
committed by GitHub
parent f4541b0208
commit c03b883f05
22 changed files with 1123 additions and 1 deletions
+38
View File
@@ -1554,6 +1554,9 @@ void TwitchChannel::refreshPubSub()
},
},
});
this->eventSubChannelChatUserMessageHoldHandle.reset();
this->eventSubChannelChatUserMessageUpdateHandle.reset();
}
else
{
@@ -1561,7 +1564,42 @@ void TwitchChannel::refreshPubSub()
this->eventSubAutomodMessageHoldHandle.reset();
this->eventSubAutomodMessageUpdateHandle.reset();
this->eventSubSuspiciousUserMessageHandle.reset();
this->eventSubChannelChatUserMessageHoldHandle =
getApp()->getEventSub()->subscribe(eventsub::SubscriptionRequest{
.subscriptionType = "channel.chat.user_message_hold",
.subscriptionVersion = "1",
.conditions =
{
{
"broadcaster_user_id",
roomId,
},
{
"user_id",
currentAccount->getUserId(),
},
},
});
this->eventSubChannelChatUserMessageUpdateHandle =
getApp()->getEventSub()->subscribe(eventsub::SubscriptionRequest{
.subscriptionType = "channel.chat.user_message_update",
.subscriptionVersion = "1",
.conditions =
{
{
"broadcaster_user_id",
roomId,
},
{
"user_id",
currentAccount->getUserId(),
},
},
});
}
getApp()->getTwitchPubSub()->listenToChannelPointRewards(roomId);
}
+2
View File
@@ -512,6 +512,8 @@ private:
eventsub::SubscriptionHandle eventSubAutomodMessageHoldHandle;
eventsub::SubscriptionHandle eventSubAutomodMessageUpdateHandle;
eventsub::SubscriptionHandle eventSubSuspiciousUserMessageHandle;
eventsub::SubscriptionHandle eventSubChannelChatUserMessageHoldHandle;
eventsub::SubscriptionHandle eventSubChannelChatUserMessageUpdateHandle;
friend class TwitchIrcServer;
friend class MessageBuilder;
@@ -305,6 +305,57 @@ void Connection::onChannelSuspiciousUserUpdate(
<< payload.event.broadcasterUserLogin.qt();
}
void Connection::onChannelChatUserMessageHold(
const lib::messages::Metadata &metadata,
const lib::payload::channel_chat_user_message_hold::v1::Payload &payload)
{
auto *channel = dynamic_cast<TwitchChannel *>(
getApp()
->getTwitch()
->getChannelOrEmpty(payload.event.broadcasterUserLogin.qt())
.get());
if (!channel || channel->isEmpty())
{
qCDebug(LOG) << "Channel Chat User Message Hold for broadcaster we're "
"not interested in"
<< payload.event.broadcasterUserLogin.qt();
return;
}
auto time = chronoToQDateTime(metadata.messageTimestamp);
auto message = makeUserMessageHeldMessage(channel, time, payload.event);
runInGuiThread([channel, message] {
channel->addMessage(message, MessageContext::Original);
});
}
void Connection::onChannelChatUserMessageUpdate(
const lib::messages::Metadata &metadata,
const lib::payload::channel_chat_user_message_update::v1::Payload &payload)
{
auto *channel = dynamic_cast<TwitchChannel *>(
getApp()
->getTwitch()
->getChannelOrEmpty(payload.event.broadcasterUserLogin.qt())
.get());
if (!channel || channel->isEmpty())
{
qCDebug(LOG)
<< "Channel Chat User Message Update for broadcaster we're "
"not interested in"
<< payload.event.broadcasterUserLogin.qt();
return;
}
auto time = chronoToQDateTime(metadata.messageTimestamp);
auto message = makeUserMessageUpdateMessage(channel, time, payload.event);
runInGuiThread([channel, message] {
channel->addMessage(message, MessageContext::Original);
});
}
QString Connection::getSessionID() const
{
return this->sessionID;
@@ -71,6 +71,16 @@ public:
const lib::payload::channel_suspicious_user_update::v1::Payload
&payload) override;
void onChannelChatUserMessageHold(
const lib::messages::Metadata &metadata,
const lib::payload::channel_chat_user_message_hold::v1::Payload
&payload) override;
void onChannelChatUserMessageUpdate(
const lib::messages::Metadata &metadata,
const lib::payload::channel_chat_user_message_update::v1::Payload
&payload) override;
QString getSessionID() const;
bool isSubscribedTo(const SubscriptionRequest &request) const;
@@ -756,4 +756,86 @@ MessagePtr makeSuspiciousUserMessageBody(
return builder.release();
}
MessagePtr makeUserMessageHeldMessage(
TwitchChannel *channel, const QDateTime &time,
const lib::payload::channel_chat_user_message_hold::v1::Event &event)
{
QString text("AutoMod: Hey! Your message is being checked by mods and has "
"not been sent.");
EventSubMessageBuilder builder(channel);
builder->serverReceivedTime = time;
builder->id = u"automod_" % event.messageID.qt();
builder->loginName = u"automod"_s;
builder->channelName = event.broadcasterUserLogin.qt();
builder->flags.set(MessageFlag::PubSub, MessageFlag::Timeout,
MessageFlag::AutoMod);
// AutoMod shield badge
builder.emplace<BadgeElement>(makeAutoModBadge(),
MessageElementFlag::BadgeChannelAuthority);
// AutoMod "username"
builder.emplace<TextElement>("AutoMod:", MessageElementFlag::Text,
QColor(0, 0, 255), FontStyle::ChatMediumBold);
builder.emplace<TextElement>(
"Hey! Your message is being checked by mods and has not been sent.",
MessageElementFlag::Text, MessageColor::Text);
builder->messageText = text;
builder->searchText = text;
return builder.release();
}
MessagePtr makeUserMessageUpdateMessage(
TwitchChannel *channel, const QDateTime &time,
const lib::payload::channel_chat_user_message_update::v1::Event &event)
{
using lib::payload::channel_chat_user_message_update::v1::Status;
QString text("AutoMod: ");
EventSubMessageBuilder builder(channel);
builder->serverReceivedTime = time;
builder->id = u"automod_" % event.messageID.qt();
builder->loginName = u"automod"_s;
builder->channelName = event.broadcasterUserLogin.qt();
builder->flags.set(MessageFlag::PubSub, MessageFlag::Timeout,
MessageFlag::AutoMod);
// AutoMod shield badge
builder.emplace<BadgeElement>(makeAutoModBadge(),
MessageElementFlag::BadgeChannelAuthority);
// AutoMod "username"
builder.emplace<TextElement>("AutoMod:", MessageElementFlag::Text,
QColor(0, 0, 255), FontStyle::ChatMediumBold);
switch (event.status)
{
case Status::Approved:
text += "Mods have accepted your message.";
builder.emplace<TextElement>("Mods have accepted your message.",
MessageElementFlag::Text,
MessageColor::Text);
break;
case Status::Denied:
text += "Mods have denied your message.";
builder.emplace<TextElement>("Mods have denied your message.",
MessageElementFlag::Text,
MessageColor::Text);
break;
case Status::Invalid:
text += "Your message was lost in the void.";
builder.emplace<TextElement>("Your message was lost in the void.",
MessageElementFlag::Text,
MessageColor::Text);
break;
}
builder->messageText = text;
builder->searchText = text;
return builder.release();
}
} // namespace chatterino::eventsub
@@ -3,6 +3,8 @@
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "twitch-eventsub-ws/payloads/automod-message-hold-v2.hpp"
#include "twitch-eventsub-ws/payloads/channel-chat-user-message-hold-v1.hpp"
#include "twitch-eventsub-ws/payloads/channel-chat-user-message-update-v1.hpp"
#include "twitch-eventsub-ws/payloads/channel-moderate-v2.hpp"
#include "twitch-eventsub-ws/payloads/channel-suspicious-user-message-v1.hpp"
@@ -165,4 +167,12 @@ MessagePtr makeSuspiciousUserMessageBody(
TwitchChannel *channel, const QDateTime &time,
const lib::payload::channel_suspicious_user_message::v1::Event &event);
MessagePtr makeUserMessageHeldMessage(
TwitchChannel *channel, const QDateTime &time,
const lib::payload::channel_chat_user_message_hold::v1::Event &event);
MessagePtr makeUserMessageUpdateMessage(
TwitchChannel *channel, const QDateTime &time,
const lib::payload::channel_chat_user_message_update::v1::Event &event);
} // namespace chatterino::eventsub