refactor: add Channel::addSystemMessage function (#5500)
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include "Application.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/commands/CommandContext.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
@@ -124,24 +123,23 @@ QString startRaid(const CommandContext &ctx)
|
||||
|
||||
if (ctx.twitchChannel == nullptr)
|
||||
{
|
||||
ctx.channel->addMessage(makeSystemMessage(
|
||||
"The /raid command only works in Twitch channels."));
|
||||
ctx.channel->addSystemMessage(
|
||||
"The /raid command only works in Twitch channels.");
|
||||
return "";
|
||||
}
|
||||
|
||||
if (ctx.words.size() < 2)
|
||||
{
|
||||
ctx.channel->addMessage(
|
||||
makeSystemMessage("Usage: \"/raid <username>\" - Raid a user. "
|
||||
"Only the broadcaster can start a raid."));
|
||||
ctx.channel->addSystemMessage(
|
||||
"Usage: \"/raid <username>\" - Raid a user. "
|
||||
"Only the broadcaster can start a raid.");
|
||||
return "";
|
||||
}
|
||||
|
||||
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
|
||||
if (currentUser->isAnon())
|
||||
{
|
||||
ctx.channel->addMessage(
|
||||
makeSystemMessage("You must be logged in to start a raid!"));
|
||||
ctx.channel->addSystemMessage("You must be logged in to start a raid!");
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -155,19 +153,18 @@ QString startRaid(const CommandContext &ctx)
|
||||
getHelix()->startRaid(
|
||||
twitchChannel->roomId(), targetUser.id,
|
||||
[channel, targetUser] {
|
||||
channel->addMessage(
|
||||
makeSystemMessage(QString("You started to raid %1.")
|
||||
.arg(targetUser.displayName)));
|
||||
channel->addSystemMessage(QString("You started to raid %1.")
|
||||
.arg(targetUser.displayName));
|
||||
},
|
||||
[channel, targetUser](auto error, auto message) {
|
||||
auto errorMessage = formatStartRaidError(error, message);
|
||||
channel->addMessage(makeSystemMessage(errorMessage));
|
||||
channel->addSystemMessage(errorMessage);
|
||||
});
|
||||
},
|
||||
[channel{ctx.channel}, target] {
|
||||
// Equivalent error from IRC
|
||||
channel->addMessage(
|
||||
makeSystemMessage(QString("Invalid username: %1").arg(target)));
|
||||
channel->addSystemMessage(
|
||||
QString("Invalid username: %1").arg(target));
|
||||
});
|
||||
|
||||
return "";
|
||||
@@ -182,36 +179,35 @@ QString cancelRaid(const CommandContext &ctx)
|
||||
|
||||
if (ctx.twitchChannel == nullptr)
|
||||
{
|
||||
ctx.channel->addMessage(makeSystemMessage(
|
||||
"The /unraid command only works in Twitch channels."));
|
||||
ctx.channel->addSystemMessage(
|
||||
"The /unraid command only works in Twitch channels.");
|
||||
return "";
|
||||
}
|
||||
|
||||
if (ctx.words.size() != 1)
|
||||
{
|
||||
ctx.channel->addMessage(
|
||||
makeSystemMessage("Usage: \"/unraid\" - Cancel the current raid. "
|
||||
"Only the broadcaster can cancel the raid."));
|
||||
ctx.channel->addSystemMessage(
|
||||
"Usage: \"/unraid\" - Cancel the current raid. "
|
||||
"Only the broadcaster can cancel the raid.");
|
||||
return "";
|
||||
}
|
||||
|
||||
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
|
||||
if (currentUser->isAnon())
|
||||
{
|
||||
ctx.channel->addMessage(
|
||||
makeSystemMessage("You must be logged in to cancel the raid!"));
|
||||
ctx.channel->addSystemMessage(
|
||||
"You must be logged in to cancel the raid!");
|
||||
return "";
|
||||
}
|
||||
|
||||
getHelix()->cancelRaid(
|
||||
ctx.twitchChannel->roomId(),
|
||||
[channel{ctx.channel}] {
|
||||
channel->addMessage(
|
||||
makeSystemMessage(QString("You cancelled the raid.")));
|
||||
channel->addSystemMessage("You cancelled the raid.");
|
||||
},
|
||||
[channel{ctx.channel}](auto error, auto message) {
|
||||
auto errorMessage = formatCancelRaidError(error, message);
|
||||
channel->addMessage(makeSystemMessage(errorMessage));
|
||||
channel->addSystemMessage(errorMessage);
|
||||
});
|
||||
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user