feat: indicate which mods start and cancel raids (#5563)

This commit is contained in:
iProdigy 2024-08-31 03:12:25 -07:00 committed by GitHub
parent af309b726f
commit 956186d1a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 121 additions and 5 deletions

View file

@ -27,6 +27,7 @@
- Minor: Links can now have prefixes and suffixes such as parentheses. (#5486, #5515)
- Minor: Added support for scrolling in splits with touchscreen panning gestures. (#5524)
- Minor: Removed experimental IRC support. (#5547)
- Minor: Moderators can now see which mods start and cancel raids. (#5563)
- Bugfix: Fixed tab move animation occasionally failing to start after closing a tab. (#5426)
- Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378)
- Bugfix: Fixed restricted users usernames not being clickable. (#5405)

View file

@ -152,9 +152,8 @@ QString startRaid(const CommandContext &ctx)
channel{ctx.channel}](const HelixUser &targetUser) {
getHelix()->startRaid(
twitchChannel->roomId(), targetUser.id,
[channel, targetUser] {
channel->addSystemMessage(QString("You started to raid %1.")
.arg(targetUser.displayName));
[] {
// do nothing
},
[channel, targetUser](auto error, auto message) {
auto errorMessage = formatStartRaidError(error, message);
@ -202,8 +201,8 @@ QString cancelRaid(const CommandContext &ctx)
getHelix()->cancelRaid(
ctx.twitchChannel->roomId(),
[channel{ctx.channel}] {
channel->addSystemMessage("You cancelled the raid.");
[] {
// do nothing
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage = formatCancelRaidError(error, message);

View file

@ -880,6 +880,40 @@ MessageBuilder::MessageBuilder(const WarnAction &action)
this->message().searchText = text;
}
MessageBuilder::MessageBuilder(const RaidAction &action)
: MessageBuilder()
{
this->emplace<TimestampElement>();
this->message().flags.set(MessageFlag::System);
QString text;
this->emplaceSystemTextAndUpdate(action.source.login, text)
->setLink({Link::UserInfo, "id:" + action.source.id});
this->emplaceSystemTextAndUpdate("initiated a raid to", text);
this->emplaceSystemTextAndUpdate(action.target + ".", text)
->setLink({Link::UserInfo, action.target});
this->message().messageText = text;
this->message().searchText = text;
}
MessageBuilder::MessageBuilder(const UnraidAction &action)
: MessageBuilder()
{
this->emplace<TimestampElement>();
this->message().flags.set(MessageFlag::System);
QString text;
this->emplaceSystemTextAndUpdate(action.source.login, text)
->setLink({Link::UserInfo, "id:" + action.source.id});
this->emplaceSystemTextAndUpdate("canceled the raid.", text);
this->message().messageText = text;
this->message().searchText = text;
}
MessageBuilder::MessageBuilder(const AutomodUserAction &action)
: MessageBuilder()
{

View file

@ -23,6 +23,8 @@ namespace chatterino {
struct BanAction;
struct UnbanAction;
struct WarnAction;
struct RaidAction;
struct UnraidAction;
struct AutomodAction;
struct AutomodUserAction;
struct AutomodInfoAction;
@ -127,6 +129,8 @@ public:
MessageBuilder(const BanAction &action, uint32_t count = 1);
MessageBuilder(const UnbanAction &action);
MessageBuilder(const WarnAction &action);
MessageBuilder(const RaidAction &action);
MessageBuilder(const UnraidAction &action);
MessageBuilder(const AutomodUserAction &action);
MessageBuilder(LiveUpdatesAddEmoteMessageTag, const QString &platform,

View file

@ -172,6 +172,16 @@ struct AutomodInfoAction : PubSubAction {
} type;
};
struct RaidAction : PubSubAction {
using PubSubAction::PubSubAction;
QString target;
};
struct UnraidAction : PubSubAction {
using PubSubAction::PubSubAction;
};
struct WarnAction : PubSubAction {
using PubSubAction::PubSubAction;

View file

@ -320,6 +320,35 @@ PubSub::PubSub(const QString &host, std::chrono::seconds pingInterval)
this->moderation.userWarned.invoke(action);
};
this->moderationActionHandlers["raid"] = [this](const auto &data,
const auto &roomID) {
RaidAction action(data, roomID);
action.source.id = data.value("created_by_user_id").toString();
action.source.login = data.value("created_by").toString();
const auto args = data.value("args").toArray();
if (args.isEmpty())
{
return;
}
action.target = args[0].toString();
this->moderation.raidStarted.invoke(action);
};
this->moderationActionHandlers["unraid"] = [this](const auto &data,
const auto &roomID) {
UnraidAction action(data, roomID);
action.source.id = data.value("created_by_user_id").toString();
action.source.login = data.value("created_by").toString();
this->moderation.raidCanceled.invoke(action);
};
/*
// This handler is no longer required as we use the automod-queue topic now
this->moderationActionHandlers["automod_rejected"] =

View file

@ -44,6 +44,8 @@ struct PubSubAutoModQueueMessage;
struct AutomodAction;
struct AutomodUserAction;
struct AutomodInfoAction;
struct RaidAction;
struct UnraidAction;
struct WarnAction;
struct PubSubLowTrustUsersMessage;
struct PubSubWhisperMessage;
@ -104,6 +106,9 @@ public:
Signal<ModeChangedAction> modeChanged;
Signal<ModerationStateAction> moderationStateChanged;
Signal<RaidAction> raidStarted;
Signal<UnraidAction> raidCanceled;
Signal<BanAction> userBanned;
Signal<UnbanAction> userUnbanned;
Signal<WarnAction> userWarned;

View file

@ -648,6 +648,40 @@ void TwitchIrcServer::initialize()
});
});
this->connections_.managedConnect(
getApp()->getTwitchPubSub()->moderation.raidStarted,
[this](const auto &action) {
auto chan = this->getChannelOrEmptyByID(action.roomID);
if (chan->isEmpty())
{
return;
}
auto msg = MessageBuilder(action).release();
postToThread([chan, msg] {
chan->addMessage(msg, MessageContext::Original);
});
});
this->connections_.managedConnect(
getApp()->getTwitchPubSub()->moderation.raidCanceled,
[this](const auto &action) {
auto chan = this->getChannelOrEmptyByID(action.roomID);
if (chan->isEmpty())
{
return;
}
auto msg = MessageBuilder(action).release();
postToThread([chan, msg] {
chan->addMessage(msg, MessageContext::Original);
});
});
this->connections_.managedConnect(
getApp()->getTwitchPubSub()->pointReward.redeemed, [this](auto &data) {
QString channelId = data.value("channel_id").toString();