Skip to content

Commit

Permalink
feat: indicate which mods start and cancel raids (#5563)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy authored Aug 31, 2024
1 parent af309b7 commit 956186d
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions src/controllers/commands/builtin/twitch/Raid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 4 additions & 0 deletions src/messages/MessageBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace chatterino {
struct BanAction;
struct UnbanAction;
struct WarnAction;
struct RaidAction;
struct UnraidAction;
struct AutomodAction;
struct AutomodUserAction;
struct AutomodInfoAction;
Expand Down Expand Up @@ -127,6 +129,8 @@ class MessageBuilder
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,
Expand Down
10 changes: 10 additions & 0 deletions src/providers/twitch/PubSubActions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
29 changes: 29 additions & 0 deletions src/providers/twitch/PubSubManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"] =
Expand Down
5 changes: 5 additions & 0 deletions src/providers/twitch/PubSubManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct PubSubAutoModQueueMessage;
struct AutomodAction;
struct AutomodUserAction;
struct AutomodInfoAction;
struct RaidAction;
struct UnraidAction;
struct WarnAction;
struct PubSubLowTrustUsersMessage;
struct PubSubWhisperMessage;
Expand Down Expand Up @@ -104,6 +106,9 @@ class PubSub
Signal<ModeChangedAction> modeChanged;
Signal<ModerationStateAction> moderationStateChanged;

Signal<RaidAction> raidStarted;
Signal<UnraidAction> raidCanceled;

Signal<BanAction> userBanned;
Signal<UnbanAction> userUnbanned;
Signal<WarnAction> userWarned;
Expand Down
34 changes: 34 additions & 0 deletions src/providers/twitch/TwitchIrcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 956186d

Please sign in to comment.