refactor: add Channel::addSystemMessage function (#5500)

This commit is contained in:
pajlada 2024-07-07 22:03:05 +02:00 committed by GitHub
parent 4535823ca8
commit 354079c74c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 443 additions and 588 deletions

View file

@ -36,6 +36,7 @@
- Dev: Refactor `TwitchIrcServer`, making it abstracted. (#5421, #5435)
- Dev: Reduced the amount of scale events. (#5404, #5406)
- Dev: Removed unused timegate settings. (#5361)
- Dev: Add `Channel::addSystemMessage` helper function, allowing us to avoid the common `channel->addMessage(makeSystemMessage(...));` pattern. (#5500)
- Dev: Unsingletonize `Resources2`. (#5460)
- Dev: All Lua globals now show in the `c2` global in the LuaLS metadata. (#5385)
- Dev: Images are now loaded in worker threads. (#5431)

View file

@ -1,6 +1,7 @@
#include "Application.hpp"
#include "common/Args.hpp"
#include "common/Channel.hpp"
#include "common/QLogging.hpp"
#include "common/Version.hpp"
#include "controllers/accounts/AccountController.hpp"
@ -233,10 +234,10 @@ void Application::initialize(Settings &settings, const Paths &paths)
{
if (auto channel = split->getChannel(); !channel->isEmpty())
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
"Chatterino unexpectedly crashed and restarted. "
"You can disable automatic restarts in the "
"settings."));
"settings.");
}
}
}
@ -584,9 +585,8 @@ void Application::initPubSub()
QString text =
QString("%1 cleared the chat.").arg(action.source.login);
auto msg = makeSystemMessage(text);
postToThread([chan, msg] {
chan->addMessage(msg);
postToThread([chan, text] {
chan->addSystemMessage(text);
});
});
@ -610,9 +610,8 @@ void Application::initPubSub()
text += QString(" (%1 seconds)").arg(action.duration);
}
auto msg = makeSystemMessage(text);
postToThread([chan, msg] {
chan->addMessage(msg);
postToThread([chan, text] {
chan->addSystemMessage(text);
});
});
@ -631,9 +630,8 @@ void Application::initPubSub()
(action.modded ? "modded" : "unmodded"),
action.target.login);
auto msg = makeSystemMessage(text);
postToThread([chan, msg] {
chan->addMessage(msg);
postToThread([chan, text] {
chan->addSystemMessage(text);
});
});

View file

@ -585,8 +585,6 @@ set(SOURCE_FILES
widgets/dialogs/LastRunCrashDialog.hpp
widgets/dialogs/LoginDialog.cpp
widgets/dialogs/LoginDialog.hpp
widgets/dialogs/NotificationPopup.cpp
widgets/dialogs/NotificationPopup.hpp
widgets/dialogs/QualityPopup.cpp
widgets/dialogs/QualityPopup.hpp
widgets/dialogs/ReplyThreadPopup.cpp

View file

@ -120,6 +120,12 @@ void Channel::addMessage(MessagePtr message,
this->messageAppended.invoke(message, overridingFlags);
}
void Channel::addSystemMessage(const QString &contents)
{
auto msg = makeSystemMessage(contents);
this->addMessage(msg);
}
void Channel::addOrReplaceTimeout(MessagePtr message)
{
addOrReplaceChannelTimeout(

View file

@ -83,6 +83,8 @@ public:
std::optional<MessageFlags> overridingFlags = std::nullopt);
void addMessagesAtStart(const std::vector<MessagePtr> &messages_);
void addSystemMessage(const QString &contents);
/// Inserts the given messages in order by Message::serverReceivedTime.
void fillInMissingMessages(const std::vector<MessagePtr> &messages);

View file

@ -554,8 +554,7 @@ QString CommandController::execCommand(const QString &textNoEmoji,
if (!dryRun && channel->getType() == Channel::Type::TwitchWhispers)
{
channel->addMessage(
makeSystemMessage("Use /w <username> <message> to whisper"));
channel->addSystemMessage("Use /w <username> <message> to whisper");
return "";
}

View file

@ -5,7 +5,6 @@
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandContext.hpp"
#include "controllers/userdata/UserDataController.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
@ -39,10 +38,10 @@ QString follow(const CommandContext &ctx)
{
return "";
}
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Twitch has removed the ability to follow users through "
"third-party applications. For more information, see "
"https://github.com/Chatterino/chatterino2/issues/3076"));
"https://github.com/Chatterino/chatterino2/issues/3076");
return "";
}
@ -52,10 +51,10 @@ QString unfollow(const CommandContext &ctx)
{
return "";
}
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Twitch has removed the ability to unfollow users through "
"third-party applications. For more information, see "
"https://github.com/Chatterino/chatterino2/issues/3076"));
"https://github.com/Chatterino/chatterino2/issues/3076");
return "";
}
@ -68,8 +67,8 @@ QString uptime(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /uptime command only works in Twitch Channels."));
ctx.channel->addSystemMessage(
"The /uptime command only works in Twitch Channels.");
return "";
}
@ -78,7 +77,7 @@ QString uptime(const CommandContext &ctx)
QString messageText =
streamStatus->live ? streamStatus->uptime : "Channel is not live.";
ctx.channel->addMessage(makeSystemMessage(messageText));
ctx.channel->addSystemMessage(messageText);
return "";
}
@ -92,8 +91,7 @@ QString user(const CommandContext &ctx)
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(
makeSystemMessage("Usage: /user <user> [channel]"));
ctx.channel->addSystemMessage("Usage: /user <user> [channel]");
return "";
}
QString userName = ctx.words[1];
@ -129,11 +127,11 @@ QString requests(const CommandContext &ctx)
}
else
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: /requests [channel]. You can also use the command "
"without arguments in any Twitch channel to open its "
"channel points requests queue. Only the broadcaster and "
"moderators have permission to view the queue."));
"moderators have permission to view the queue.");
return "";
}
}
@ -163,11 +161,11 @@ QString lowtrust(const CommandContext &ctx)
}
else
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: /lowtrust [channel]. You can also use the command "
"without arguments in any Twitch channel to open its "
"suspicious user activity feed. Only the broadcaster and "
"moderators have permission to view this feed."));
"moderators have permission to view this feed.");
return "";
}
}
@ -190,15 +188,15 @@ QString clip(const CommandContext &ctx)
if (const auto type = ctx.channel->getType();
type != Channel::Type::Twitch && type != Channel::Type::TwitchWatching)
{
ctx.channel->addMessage(makeSystemMessage(
"The /clip command only works in Twitch Channels."));
ctx.channel->addSystemMessage(
"The /clip command only works in Twitch Channels.");
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /clip command only works in Twitch Channels."));
ctx.channel->addSystemMessage(
"The /clip command only works in Twitch Channels.");
return "";
}
@ -216,25 +214,25 @@ QString marker(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /marker command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /marker command only works in Twitch channels.");
return "";
}
// Avoid Helix calls without Client ID and/or OAuth Token
if (getIApp()->getAccounts()->twitch.getCurrent()->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
"You need to be logged in to create stream markers!"));
ctx.channel->addSystemMessage(
"You need to be logged in to create stream markers!");
return "";
}
// Exact same message as in webchat
if (!ctx.twitchChannel->isLive())
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"You can only add stream markers during live streams. Try "
"again when the channel is live streaming."));
"again when the channel is live streaming.");
return "";
}
@ -247,13 +245,13 @@ QString marker(const CommandContext &ctx)
ctx.twitchChannel->roomId(), arguments.join(" ").left(140),
[channel{ctx.channel},
arguments](const HelixStreamMarker &streamMarker) {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Successfully added a stream marker at %1%2")
.arg(formatTime(streamMarker.positionSeconds))
.arg(streamMarker.description.isEmpty()
? ""
: QString(": \"%1\"")
.arg(streamMarker.description))));
.arg(streamMarker.description)));
},
[channel{ctx.channel}](auto error) {
QString errorMessage("Failed to create stream marker - ");
@ -279,7 +277,7 @@ QString marker(const CommandContext &ctx)
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return "";
@ -303,10 +301,10 @@ QString streamlink(const CommandContext &ctx)
}
else
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"/streamlink [channel]. Open specified Twitch channel in "
"streamlink. If no channel argument is specified, open the "
"current Twitch channel instead."));
"current Twitch channel instead.");
return "";
}
}
@ -335,10 +333,10 @@ QString popout(const CommandContext &ctx)
}
else
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: /popout <channel>. You can also use the command "
"without arguments in any Twitch channel to open its "
"popout chat."));
"popout chat.");
return "";
}
}
@ -385,7 +383,7 @@ QString popup(const CommandContext &ctx)
}
}
ctx.channel->addMessage(makeSystemMessage(usageMessage));
ctx.channel->addSystemMessage(usageMessage);
return "";
}
@ -469,8 +467,8 @@ QString openURL(const CommandContext &ctx)
const auto &positionalArguments = parser.positionalArguments();
if (positionalArguments.isEmpty())
{
ctx.channel->addMessage(makeSystemMessage(
"Usage: /openurl <URL> [--incognito/--no-incognito]"));
ctx.channel->addSystemMessage(
"Usage: /openurl <URL> [--incognito/--no-incognito]");
return "";
}
auto urlString = parser.positionalArguments().join(' ');
@ -478,7 +476,7 @@ QString openURL(const CommandContext &ctx)
QUrl url = QUrl::fromUserInput(urlString);
if (!url.isValid())
{
ctx.channel->addMessage(makeSystemMessage("Invalid URL specified."));
ctx.channel->addSystemMessage("Invalid URL specified.");
return "";
}
@ -488,9 +486,9 @@ QString openURL(const CommandContext &ctx)
if (forcePrivateMode && forceNonPrivateMode)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Error: /openurl may only be called with --incognito or "
"--no-incognito, not both at the same time."));
"--no-incognito, not both at the same time.");
return "";
}
@ -518,7 +516,7 @@ QString openURL(const CommandContext &ctx)
if (!res)
{
ctx.channel->addMessage(makeSystemMessage("Could not open URL."));
ctx.channel->addSystemMessage("Could not open URL.");
}
return "";
@ -553,16 +551,16 @@ QString injectFakeMessage(const CommandContext &ctx)
if (!ctx.channel->isTwitchChannel())
{
ctx.channel->addMessage(makeSystemMessage(
"The /fakemsg command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /fakemsg command only works in Twitch channels.");
return "";
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: /fakemsg (raw irc text) - injects raw irc text as "
"if it was a message received from TMI"));
"if it was a message received from TMI");
return "";
}
@ -583,9 +581,9 @@ QString injectStreamUpdateNoStream(const CommandContext &ctx)
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(
makeSystemMessage("The /debug-update-to-no-stream command only "
"works in Twitch channels"));
ctx.channel->addSystemMessage(
"The /debug-update-to-no-stream command only "
"works in Twitch channels");
return "";
}
@ -602,9 +600,8 @@ QString copyToClipboard(const CommandContext &ctx)
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(
makeSystemMessage("Usage: /copy <text> - copies provided "
"text to clipboard."));
ctx.channel->addSystemMessage("Usage: /copy <text> - copies provided "
"text to clipboard.");
return "";
}
@ -621,15 +618,15 @@ QString unstableSetUserClientSideColor(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(
makeSystemMessage("The /unstable-set-user-color command only "
"works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /unstable-set-user-color command only "
"works in Twitch channels.");
return "";
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
QString("Usage: %1 <TwitchUserID> [color]").arg(ctx.words.at(0))));
ctx.channel->addSystemMessage(
QString("Usage: %1 <TwitchUserID> [color]").arg(ctx.words.at(0)));
return "";
}
@ -653,9 +650,8 @@ QString openUsercard(const CommandContext &ctx)
if (ctx.words.size() < 2)
{
channel->addMessage(
makeSystemMessage("Usage: /usercard <username> [channel] or "
"/usercard id:<id> [channel]"));
channel->addSystemMessage("Usage: /usercard <username> [channel] or "
"/usercard id:<id> [channel]");
return "";
}
@ -672,9 +668,9 @@ QString openUsercard(const CommandContext &ctx)
if (channelTemp->isEmpty())
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
"A usercard can only be displayed for a channel that is "
"currently opened in Chatterino."));
"currently opened in Chatterino.");
return "";
}

View file

@ -22,12 +22,12 @@ QString setLoggingRules(const CommandContext &ctx)
{
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: /c2-set-logging-rules <rules...>. To enable debug logging "
"for all categories from chatterino, use "
"'chatterino.*.debug=true'. For the format on the rules, see "
"https://doc.qt.io/qt-6/"
"qloggingcategory.html#configuring-categories"));
"qloggingcategory.html#configuring-categories");
return {};
}
@ -47,7 +47,7 @@ QString setLoggingRules(const CommandContext &ctx)
"https://doc.qt.io/qt-6/qloggingcategory.html#setFilterRules");
}
ctx.channel->addMessage(makeSystemMessage(message));
ctx.channel->addSystemMessage(message);
return {};
}
@ -56,15 +56,13 @@ QString toggleThemeReload(const CommandContext &ctx)
if (getTheme()->isAutoReloading())
{
getTheme()->setAutoReload(false);
ctx.channel->addMessage(
makeSystemMessage(u"Disabled theme auto reloading."_s));
ctx.channel->addSystemMessage(u"Disabled theme auto reloading."_s);
return {};
}
getTheme()->setAutoReload(true);
ctx.channel->addMessage(
makeSystemMessage(u"Auto reloading theme every %1 ms."_s.arg(
Theme::AUTO_RELOAD_INTERVAL_MS)));
ctx.channel->addSystemMessage(u"Auto reloading theme every %1 ms."_s.arg(
Theme::AUTO_RELOAD_INTERVAL_MS));
return {};
}
@ -107,7 +105,7 @@ QString listArgs(const CommandContext &ctx)
QString msg = QApplication::instance()->arguments().join(' ');
channel->addMessage(makeSystemMessage(msg));
channel->addSystemMessage(msg);
return "";
}

View file

@ -1,10 +1,8 @@
#include "controllers/commands/builtin/twitch/AddModerator.hpp"
#include "Application.hpp"
#include "common/Channel.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"
@ -22,23 +20,22 @@ QString addModerator(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /mod command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /mod command only works in Twitch channels.");
return "";
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: \"/mod <username>\" - Grant moderator status to a "
"user. Use \"/mods\" to list the moderators of this channel."));
"user. Use \"/mods\" to list the moderators of this channel.");
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to mod someone!"));
ctx.channel->addSystemMessage("You must be logged in to mod someone!");
return "";
}
@ -52,10 +49,10 @@ QString addModerator(const CommandContext &ctx)
getHelix()->addChannelModerator(
twitchChannel->roomId(), targetUser.id,
[channel, targetUser] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("You have added %1 as a moderator of this "
"channel.")
.arg(targetUser.displayName)));
.arg(targetUser.displayName));
},
[channel, targetUser](auto error, auto message) {
QString errorMessage =
@ -116,13 +113,13 @@ QString addModerator(const CommandContext &ctx)
}
break;
}
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 "";

View file

@ -1,10 +1,8 @@
#include "controllers/commands/builtin/twitch/AddVIP.hpp"
#include "Application.hpp"
#include "common/Channel.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"
@ -22,23 +20,22 @@ QString addVIP(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /vip command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /vip command only works in Twitch channels.");
return "";
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: \"/vip <username>\" - Grant VIP status to a user. Use "
"\"/vips\" to list the VIPs of this channel."));
"\"/vips\" to list the VIPs of this channel.");
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to VIP someone!"));
ctx.channel->addSystemMessage("You must be logged in to VIP someone!");
return "";
}
@ -52,9 +49,9 @@ QString addVIP(const CommandContext &ctx)
getHelix()->addChannelVIP(
twitchChannel->roomId(), targetUser.id,
[channel, targetUser] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("You have added %1 as a VIP of this channel.")
.arg(targetUser.displayName)));
.arg(targetUser.displayName));
},
[channel, targetUser](auto error, auto message) {
QString errorMessage = QString("Failed to add VIP - ");
@ -97,13 +94,13 @@ QString addVIP(const CommandContext &ctx)
}
break;
}
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 "";

View file

@ -1,10 +1,8 @@
#include "controllers/commands/builtin/twitch/Announce.hpp"
#include "Application.hpp"
#include "common/Channel.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"
@ -22,8 +20,8 @@ QString sendAnnouncementColor(const CommandContext &ctx,
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"This command can only be used in Twitch channels."));
ctx.channel->addSystemMessage(
"This command can only be used in Twitch channels.");
return "";
}
@ -48,16 +46,16 @@ QString sendAnnouncementColor(const CommandContext &ctx,
"message with a %1 highlight.")
.arg(colorStr);
}
ctx.channel->addMessage(makeSystemMessage(usageMsg));
ctx.channel->addSystemMessage(usageMsg);
return "";
}
auto user = getIApp()->getAccounts()->twitch.getCurrent();
if (user->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
QString("You must be logged in to use the /announce%1 command.")
.arg(colorStr)));
.arg(colorStr));
return "";
}
@ -93,7 +91,7 @@ QString sendAnnouncementColor(const CommandContext &ctx,
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return "";
}

View file

@ -5,7 +5,6 @@
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandContext.hpp"
#include "controllers/commands/common/ChannelAction.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
@ -93,7 +92,7 @@ void banUserByID(const ChannelPtr &channel, const QString &channelID,
[channel, displayName](auto error, auto message) {
auto errorMessage =
formatBanTimeoutError("ban", error, message, displayName);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
}
@ -110,7 +109,7 @@ void timeoutUserByID(const ChannelPtr &channel, const QString &channelID,
[channel, displayName](auto error, auto message) {
auto errorMessage =
formatBanTimeoutError("timeout", error, message, displayName);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
}
@ -129,7 +128,7 @@ QString sendBan(const CommandContext &ctx)
{
if (ctx.channel != nullptr)
{
ctx.channel->addMessage(makeSystemMessage(actions.error()));
ctx.channel->addSystemMessage(actions.error());
}
else
{
@ -145,8 +144,7 @@ QString sendBan(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to ban someone!"));
ctx.channel->addSystemMessage("You must be logged in to ban someone!");
return "";
}
@ -192,16 +190,16 @@ QString sendBan(const CommandContext &ctx)
userLoginsToFetch](const auto &users) mutable {
if (!actionChannel.hydrateFrom(users))
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to ban, bad channel name: %1")
.arg(actionChannel.login)));
.arg(actionChannel.login));
return;
}
if (!actionTarget.hydrateFrom(users))
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to ban, bad target name: %1")
.arg(actionTarget.login)));
.arg(actionTarget.login));
return;
}
@ -210,9 +208,9 @@ QString sendBan(const CommandContext &ctx)
reason, actionTarget.displayName);
},
[channel{ctx.channel}, userLoginsToFetch] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to ban, bad username(s): %1")
.arg(userLoginsToFetch.join(", "))));
.arg(userLoginsToFetch.join(", ")));
});
}
else
@ -239,8 +237,8 @@ QString sendBanById(const CommandContext &ctx)
}
if (twitchChannel == nullptr)
{
channel->addMessage(makeSystemMessage(
QString("The /banid command only works in Twitch channels.")));
channel->addSystemMessage(
"The /banid command only works in Twitch channels.");
return "";
}
@ -250,15 +248,14 @@ QString sendBanById(const CommandContext &ctx)
"shown to the target user and other moderators.";
if (words.size() < 2)
{
channel->addMessage(makeSystemMessage(usageStr));
channel->addSystemMessage(usageStr);
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
channel->addMessage(
makeSystemMessage("You must be logged in to ban someone!"));
channel->addSystemMessage("You must be logged in to ban someone!");
return "";
}
@ -282,7 +279,7 @@ QString sendTimeout(const CommandContext &ctx)
{
if (ctx.channel != nullptr)
{
ctx.channel->addMessage(makeSystemMessage(actions.error()));
ctx.channel->addSystemMessage(actions.error());
}
else
{
@ -298,8 +295,8 @@ QString sendTimeout(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to timeout someone!"));
ctx.channel->addSystemMessage(
"You must be logged in to timeout someone!");
return "";
}
@ -346,16 +343,16 @@ QString sendTimeout(const CommandContext &ctx)
userLoginsToFetch](const auto &users) mutable {
if (!actionChannel.hydrateFrom(users))
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to timeout, bad channel name: %1")
.arg(actionChannel.login)));
.arg(actionChannel.login));
return;
}
if (!actionTarget.hydrateFrom(users))
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to timeout, bad target name: %1")
.arg(actionTarget.login)));
.arg(actionTarget.login));
return;
}
@ -364,9 +361,9 @@ QString sendTimeout(const CommandContext &ctx)
duration, reason, actionTarget.displayName);
},
[channel{ctx.channel}, userLoginsToFetch] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to timeout, bad username(s): %1")
.arg(userLoginsToFetch.join(", "))));
.arg(userLoginsToFetch.join(", ")));
});
}
else

View file

@ -4,7 +4,6 @@
#include "common/Channel.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 "util/Twitch.hpp"
@ -26,14 +25,14 @@ QString blockUser(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /block command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /block command only works in Twitch channels.");
return "";
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage("Usage: /block <user>"));
ctx.channel->addSystemMessage("Usage: /block <user>");
return "";
}
@ -41,8 +40,8 @@ QString blockUser(const CommandContext &ctx)
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to block someone!"));
ctx.channel->addSystemMessage(
"You must be logged in to block someone!");
return "";
}
@ -56,22 +55,21 @@ QString blockUser(const CommandContext &ctx)
getIApp()->getAccounts()->twitch.getCurrent()->blockUser(
targetUser.id, nullptr,
[channel, target, targetUser] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("You successfully blocked user %1")
.arg(target)));
.arg(target));
},
[channel, target] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("User %1 couldn't be blocked, an unknown "
"error occurred!")
.arg(target)));
.arg(target));
});
},
[channel{ctx.channel}, target] {
channel->addMessage(
makeSystemMessage(QString("User %1 couldn't be blocked, no "
"user with that name found!")
.arg(target)));
channel->addSystemMessage(QString("User %1 couldn't be blocked, no "
"user with that name found!")
.arg(target));
});
return "";
@ -84,9 +82,9 @@ QString ignoreUser(const CommandContext &ctx)
return "";
}
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Ignore command has been renamed to /block, please use it from "
"now on as /ignore is going to be removed soon."));
"now on as /ignore is going to be removed soon.");
return blockUser(ctx);
}
@ -100,14 +98,14 @@ QString unblockUser(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /unblock command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /unblock command only works in Twitch channels.");
return "";
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage("Usage: /unblock <user>"));
ctx.channel->addSystemMessage("Usage: /unblock <user>");
return "";
}
@ -115,8 +113,8 @@ QString unblockUser(const CommandContext &ctx)
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to unblock someone!"));
ctx.channel->addSystemMessage(
"You must be logged in to unblock someone!");
return "";
}
@ -129,22 +127,21 @@ QString unblockUser(const CommandContext &ctx)
getIApp()->getAccounts()->twitch.getCurrent()->unblockUser(
targetUser.id, nullptr,
[channel, target, targetUser] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("You successfully unblocked user %1")
.arg(target)));
.arg(target));
},
[channel, target] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("User %1 couldn't be unblocked, an unknown "
"error occurred!")
.arg(target)));
.arg(target));
});
},
[channel{ctx.channel}, target] {
channel->addMessage(
makeSystemMessage(QString("User %1 couldn't be unblocked, "
"no user with that name found!")
.arg(target)));
channel->addSystemMessage(QString("User %1 couldn't be unblocked, "
"no user with that name found!")
.arg(target));
});
return "";
@ -157,9 +154,9 @@ QString unignoreUser(const CommandContext &ctx)
return "";
}
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Unignore command has been renamed to /unblock, please use it "
"from now on as /unignore is going to be removed soon."));
"from now on as /unignore is going to be removed soon.");
return unblockUser(ctx);
}

View file

@ -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"
@ -87,8 +86,8 @@ auto successCallback = [](auto result) {};
auto failureCallback = [](ChannelPtr channel, int durationUnitMultiplier = 1) {
return [channel, durationUnitMultiplier](const auto &error,
const QString &message) {
channel->addMessage(makeSystemMessage(
formatError(error, message, durationUnitMultiplier)));
channel->addSystemMessage(
formatError(error, message, durationUnitMultiplier));
};
};
@ -104,21 +103,21 @@ QString emoteOnly(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /emoteonly command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /emoteonly command only works in Twitch channels.");
return "";
}
if (ctx.twitchChannel->accessRoomModes()->emoteOnly)
{
ctx.channel->addMessage(
makeSystemMessage("This room is already in emote-only mode."));
ctx.channel->addSystemMessage(
"This room is already in emote-only mode.");
return "";
}
@ -134,20 +133,19 @@ QString emoteOnlyOff(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /emoteonlyoff command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /emoteonlyoff command only works in Twitch channels.");
return "";
}
if (!ctx.twitchChannel->accessRoomModes()->emoteOnly)
{
ctx.channel->addMessage(
makeSystemMessage("This room is not in emote-only mode."));
ctx.channel->addSystemMessage("This room is not in emote-only mode.");
return "";
}
@ -163,21 +161,21 @@ QString subscribers(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /subscribers command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /subscribers command only works in Twitch channels.");
return "";
}
if (ctx.twitchChannel->accessRoomModes()->submode)
{
ctx.channel->addMessage(makeSystemMessage(
"This room is already in subscribers-only mode."));
ctx.channel->addSystemMessage(
"This room is already in subscribers-only mode.");
return "";
}
@ -193,21 +191,21 @@ QString subscribersOff(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /subscribersoff command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /subscribersoff command only works in Twitch channels.");
return "";
}
if (!ctx.twitchChannel->accessRoomModes()->submode)
{
ctx.channel->addMessage(
makeSystemMessage("This room is not in subscribers-only mode."));
ctx.channel->addSystemMessage(
"This room is not in subscribers-only mode.");
return "";
}
@ -223,14 +221,14 @@ QString slow(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /slow command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /slow command only works in Twitch channels.");
return "";
}
@ -241,20 +239,20 @@ QString slow(const CommandContext &ctx)
duration = ctx.words.at(1).toInt(&ok);
if (!ok || duration <= 0)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: \"/slow [duration]\" - Enables slow mode (limit how "
"often users may send messages). Duration (optional, "
"default=30) must be a positive number of seconds. Use "
"\"slowoff\" to disable."));
"\"slowoff\" to disable.");
return "";
}
}
if (ctx.twitchChannel->accessRoomModes()->slowMode == duration)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
QString("This room is already in %1-second slow mode.")
.arg(duration)));
.arg(duration));
return "";
}
@ -270,21 +268,20 @@ QString slowOff(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /slowoff command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /slowoff command only works in Twitch channels.");
return "";
}
if (ctx.twitchChannel->accessRoomModes()->slowMode <= 0)
{
ctx.channel->addMessage(
makeSystemMessage("This room is not in slow mode."));
ctx.channel->addSystemMessage("This room is not in slow mode.");
return "";
}
@ -300,14 +297,14 @@ QString followers(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /followers command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /followers command only works in Twitch channels.");
return "";
}
@ -319,20 +316,20 @@ QString followers(const CommandContext &ctx)
// -1 / 60 == 0 => use parsed
if (parsed < 0)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: \"/followers [duration]\" - Enables followers-only "
"mode (only users who have followed for 'duration' may chat). "
"Examples: \"30m\", \"1 week\", \"5 days 12 hours\". Must be "
"less than 3 months."));
"less than 3 months.");
return "";
}
}
if (ctx.twitchChannel->accessRoomModes()->followerOnly == duration)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
QString("This room is already in %1 followers-only mode.")
.arg(formatTime(duration * 60))));
.arg(formatTime(duration * 60)));
return "";
}
@ -348,21 +345,21 @@ QString followersOff(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /followersoff command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /followersoff command only works in Twitch channels.");
return "";
}
if (ctx.twitchChannel->accessRoomModes()->followerOnly < 0)
{
ctx.channel->addMessage(
makeSystemMessage("This room is not in followers-only mode. "));
ctx.channel->addSystemMessage(
"This room is not in followers-only mode. ");
return "";
}
@ -378,21 +375,21 @@ QString uniqueChat(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /uniquechat command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /uniquechat command only works in Twitch channels.");
return "";
}
if (ctx.twitchChannel->accessRoomModes()->r9k)
{
ctx.channel->addMessage(
makeSystemMessage("This room is already in unique-chat mode."));
ctx.channel->addSystemMessage(
"This room is already in unique-chat mode.");
return "";
}
@ -408,21 +405,20 @@ QString uniqueChatOff(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(P_NOT_LOGGED_IN));
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /uniquechatoff command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /uniquechatoff command only works in Twitch channels.");
return "";
}
if (!ctx.twitchChannel->accessRoomModes()->r9k)
{
ctx.channel->addMessage(
makeSystemMessage("This room is not in unique-chat mode."));
ctx.channel->addSystemMessage("This room is not in unique-chat mode.");
return "";
}

View file

@ -69,8 +69,8 @@ QString chatters(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /chatters command only works in Twitch Channels."));
ctx.channel->addSystemMessage(
"The /chatters command only works in Twitch Channels.");
return "";
}
@ -79,13 +79,12 @@ QString chatters(const CommandContext &ctx)
ctx.twitchChannel->roomId(),
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), 1,
[channel{ctx.channel}](auto result) {
channel->addMessage(
makeSystemMessage(QString("Chatter count: %1.")
.arg(localizeNumbers(result.total))));
channel->addSystemMessage(QString("Chatter count: %1.")
.arg(localizeNumbers(result.total)));
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage = formatChattersError(error, message);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return "";
@ -100,8 +99,8 @@ QString testChatters(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /test-chatters command only works in Twitch Channels."));
ctx.channel->addSystemMessage(
"The /test-chatters command only works in Twitch Channels.");
return "";
}
@ -134,7 +133,7 @@ QString testChatters(const CommandContext &ctx)
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage = formatChattersError(error, message);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return "";

View file

@ -26,9 +26,9 @@ QString deleteMessages(TwitchChannel *twitchChannel, const QString &messageID)
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
{
twitchChannel->addMessage(makeSystemMessage(
twitchChannel->addSystemMessage(
QString("You must be logged in to use the %1 command.")
.arg(commandName)));
.arg(commandName));
return "";
}
@ -82,7 +82,7 @@ QString deleteMessages(TwitchChannel *twitchChannel, const QString &messageID)
break;
}
twitchChannel->addMessage(makeSystemMessage(errorMessage));
twitchChannel->addSystemMessage(errorMessage);
});
return "";
@ -101,8 +101,8 @@ QString deleteAllMessages(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /clear command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /clear command only works in Twitch channels.");
return "";
}
@ -120,16 +120,15 @@ QString deleteOneMessage(const CommandContext &ctx)
// We use this to ensure the user gets better error messages for missing or malformed arguments
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /delete command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /delete command only works in Twitch channels.");
return "";
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(
makeSystemMessage("Usage: /delete <msg-id> - Deletes the "
"specified message."));
ctx.channel->addSystemMessage("Usage: /delete <msg-id> - Deletes the "
"specified message.");
return "";
}
@ -138,8 +137,8 @@ QString deleteOneMessage(const CommandContext &ctx)
if (uuid.isNull())
{
// The message id must be a valid UUID
ctx.channel->addMessage(makeSystemMessage(
QString("Invalid msg-id: \"%1\"").arg(messageID)));
ctx.channel->addSystemMessage(
QString("Invalid msg-id: \"%1\"").arg(messageID));
return "";
}
@ -149,9 +148,9 @@ QString deleteOneMessage(const CommandContext &ctx)
if (msg->loginName == ctx.channel->getName() &&
!ctx.channel->isBroadcaster())
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"You cannot delete the broadcaster's messages unless "
"you are the broadcaster."));
"you are the broadcaster.");
return "";
}
}

View file

@ -60,8 +60,8 @@ QString getModerators(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /mods command only works in Twitch Channels."));
ctx.channel->addSystemMessage(
"The /mods command only works in Twitch Channels.");
return "";
}
@ -70,8 +70,8 @@ QString getModerators(const CommandContext &ctx)
[channel{ctx.channel}, twitchChannel{ctx.twitchChannel}](auto result) {
if (result.empty())
{
channel->addMessage(makeSystemMessage(
"This channel does not have any moderators."));
channel->addSystemMessage(
"This channel does not have any moderators.");
return;
}
@ -85,7 +85,7 @@ QString getModerators(const CommandContext &ctx)
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage = formatModsError(error, message);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return "";

View file

@ -8,7 +8,6 @@
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "util/Twitch.hpp"
namespace {
@ -77,19 +76,19 @@ QString getVIPs(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /vips command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /vips command only works in Twitch channels.");
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Due to Twitch restrictions, " //
"this command can only be used by the broadcaster. "
"To see the list of VIPs you must use the "
"Twitch website."));
"Twitch website.");
return "";
}
@ -99,8 +98,8 @@ QString getVIPs(const CommandContext &ctx)
const std::vector<HelixVip> &vipList) {
if (vipList.empty())
{
channel->addMessage(
makeSystemMessage("This channel does not have any VIPs."));
channel->addSystemMessage(
"This channel does not have any VIPs.");
return;
}
@ -115,7 +114,7 @@ QString getVIPs(const CommandContext &ctx)
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage = formatGetVIPsError(error, message);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return "";

View file

@ -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 "";

View file

@ -1,10 +1,8 @@
#include "controllers/commands/builtin/twitch/RemoveModerator.hpp"
#include "Application.hpp"
#include "common/Channel.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"
@ -22,23 +20,23 @@ QString removeModerator(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /unmod command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /unmod command only works in Twitch channels.");
return "";
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: \"/unmod <username>\" - Revoke moderator status from a "
"user. Use \"/mods\" to list the moderators of this channel."));
"user. Use \"/mods\" to list the moderators of this channel.");
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to unmod someone!"));
ctx.channel->addSystemMessage(
"You must be logged in to unmod someone!");
return "";
}
@ -52,10 +50,10 @@ QString removeModerator(const CommandContext &ctx)
getHelix()->removeChannelModerator(
twitchChannel->roomId(), targetUser.id,
[channel, targetUser] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("You have removed %1 as a moderator of "
"this channel.")
.arg(targetUser.displayName)));
.arg(targetUser.displayName));
},
[channel, targetUser](auto error, auto message) {
QString errorMessage =
@ -107,13 +105,13 @@ QString removeModerator(const CommandContext &ctx)
}
break;
}
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 "";

View file

@ -22,23 +22,23 @@ QString removeVIP(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /unvip command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /unvip command only works in Twitch channels.");
return "";
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
"Usage: \"/unvip <username>\" - Revoke VIP status from a user. "
"Use \"/vips\" to list the VIPs of this channel."));
"Use \"/vips\" to list the VIPs of this channel.");
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to UnVIP someone!"));
ctx.channel->addSystemMessage(
"You must be logged in to UnVIP someone!");
return "";
}
@ -52,9 +52,9 @@ QString removeVIP(const CommandContext &ctx)
getHelix()->removeChannelVIP(
twitchChannel->roomId(), targetUser.id,
[channel, targetUser] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("You have removed %1 as a VIP of this channel.")
.arg(targetUser.displayName)));
.arg(targetUser.displayName));
},
[channel, targetUser](auto error, auto message) {
QString errorMessage = QString("Failed to remove VIP - ");
@ -97,13 +97,13 @@ QString removeVIP(const CommandContext &ctx)
}
break;
}
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 "";

View file

@ -1,9 +1,7 @@
#include "controllers/commands/builtin/twitch/SendReply.hpp"
#include "common/Channel.hpp"
#include "controllers/commands/CommandContext.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "messages/MessageThread.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "util/Twitch.hpp"
@ -19,15 +17,14 @@ QString sendReply(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /reply command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /reply command only works in Twitch channels.");
return "";
}
if (ctx.words.size() < 3)
{
ctx.channel->addMessage(
makeSystemMessage("Usage: /reply <username> <message>"));
ctx.channel->addSystemMessage("Usage: /reply <username> <message>");
return "";
}
@ -54,8 +51,7 @@ QString sendReply(const CommandContext &ctx)
}
}
ctx.channel->addMessage(
makeSystemMessage("A message from that user wasn't found."));
ctx.channel->addSystemMessage("A message from that user wasn't found.");
return "";
}

View file

@ -208,16 +208,15 @@ QString sendWhisper(const CommandContext &ctx)
if (ctx.words.size() < 3)
{
ctx.channel->addMessage(
makeSystemMessage("Usage: /w <username> <message>"));
ctx.channel->addSystemMessage("Usage: /w <username> <message>");
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to send a whisper!"));
ctx.channel->addSystemMessage(
"You must be logged in to send a whisper!");
return "";
}
auto target = ctx.words.at(1);
@ -236,12 +235,11 @@ QString sendWhisper(const CommandContext &ctx)
},
[channel, target, targetUser](auto error, auto message) {
auto errorMessage = formatWhisperError(error, message);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
},
[channel{ctx.channel}] {
channel->addMessage(
makeSystemMessage("No user matching that username."));
channel->addSystemMessage("No user matching that username.");
});
return "";
}

View file

@ -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"
@ -17,9 +16,9 @@ QString toggleShieldMode(const CommandContext &ctx, bool isActivating)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
QStringLiteral("The %1 command only works in Twitch channels.")
.arg(command)));
.arg(command));
return {};
}
@ -28,9 +27,9 @@ QString toggleShieldMode(const CommandContext &ctx, bool isActivating)
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
QStringLiteral("You must be logged in to use the %1 command.")
.arg(command)));
.arg(command));
return {};
}
@ -39,13 +38,11 @@ QString toggleShieldMode(const CommandContext &ctx, bool isActivating)
[channel = ctx.channel](const auto &res) {
if (!res.isActive)
{
channel->addMessage(
makeSystemMessage("Shield mode was deactivated."));
channel->addSystemMessage("Shield mode was deactivated.");
return;
}
channel->addMessage(
makeSystemMessage("Shield mode was activated."));
channel->addSystemMessage("Shield mode was activated.");
},
[channel = ctx.channel](const auto error, const auto &message) {
using Error = HelixUpdateShieldModeError;
@ -78,7 +75,7 @@ QString toggleShieldMode(const CommandContext &ctx, bool isActivating)
}
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return {};

View file

@ -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"
@ -19,24 +18,22 @@ QString sendShoutout(const CommandContext &ctx)
if (twitchChannel == nullptr)
{
channel->addMessage(makeSystemMessage(
"The /shoutout command only works in Twitch channels."));
channel->addSystemMessage(
"The /shoutout command only works in Twitch channels.");
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
channel->addMessage(
makeSystemMessage("You must be logged in to send shoutout."));
channel->addSystemMessage("You must be logged in to send shoutout.");
return "";
}
if (words->size() < 2)
{
channel->addMessage(
makeSystemMessage("Usage: \"/shoutout <username>\" - Sends a "
"shoutout to the specified twitch user"));
channel->addSystemMessage("Usage: \"/shoutout <username>\" - Sends a "
"shoutout to the specified twitch user");
return "";
}
@ -52,8 +49,8 @@ QString sendShoutout(const CommandContext &ctx)
twitchChannel->roomId(), targetUser.id,
currentUser->getUserId(),
[channel, targetUser]() {
channel->addMessage(makeSystemMessage(
QString("Sent shoutout to %1").arg(targetUser.login)));
channel->addSystemMessage(
QString("Sent shoutout to %1").arg(targetUser.login));
},
[channel](auto error, auto message) {
QString errorMessage = "Failed to send shoutout - ";
@ -99,13 +96,13 @@ QString sendShoutout(const CommandContext &ctx)
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
},
[channel, target] {
// Equivalent error from IRC
channel->addMessage(
makeSystemMessage(QString("Invalid username: %1").arg(target)));
channel->addSystemMessage(
QString("Invalid username: %1").arg(target));
});
return "";

View file

@ -1,10 +1,8 @@
#include "controllers/commands/builtin/twitch/StartCommercial.hpp"
#include "Application.hpp"
#include "common/Channel.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"
@ -83,8 +81,8 @@ QString startCommercial(const CommandContext &ctx)
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(makeSystemMessage(
"The /commercial command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /commercial command only works in Twitch channels.");
return "";
}
@ -96,7 +94,7 @@ QString startCommercial(const CommandContext &ctx)
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(usageStr));
ctx.channel->addSystemMessage(usageStr);
return "";
}
@ -105,8 +103,8 @@ QString startCommercial(const CommandContext &ctx)
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
"You must be logged in to use the /commercial command."));
ctx.channel->addSystemMessage(
"You must be logged in to use the /commercial command.");
return "";
}
@ -116,18 +114,18 @@ QString startCommercial(const CommandContext &ctx)
getHelix()->startCommercial(
broadcasterID, length,
[channel{ctx.channel}](auto response) {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Starting %1 second long commercial break. "
"Keep in mind you are still "
"live and not all viewers will receive a "
"commercial. "
"You may run another commercial in %2 seconds.")
.arg(response.length)
.arg(response.retryAfter)));
.arg(response.retryAfter));
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage = formatStartCommercialError(error, message);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return "";

View file

@ -6,7 +6,6 @@
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandContext.hpp"
#include "controllers/commands/common/ChannelAction.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
@ -76,7 +75,7 @@ void unbanUserByID(const ChannelPtr &channel, const QString &channelID,
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
}
@ -96,7 +95,7 @@ QString unbanUser(const CommandContext &ctx)
{
if (ctx.channel != nullptr)
{
ctx.channel->addMessage(makeSystemMessage(actions.error()));
ctx.channel->addSystemMessage(actions.error());
}
else
{
@ -112,8 +111,8 @@ QString unbanUser(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to unban someone!"));
ctx.channel->addSystemMessage(
"You must be logged in to unban someone!");
return "";
}
@ -159,16 +158,16 @@ QString unbanUser(const CommandContext &ctx)
userLoginsToFetch](const auto &users) mutable {
if (!actionChannel.hydrateFrom(users))
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to timeout, bad channel name: %1")
.arg(actionChannel.login)));
.arg(actionChannel.login));
return;
}
if (!actionTarget.hydrateFrom(users))
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to timeout, bad target name: %1")
.arg(actionTarget.login)));
.arg(actionTarget.login));
return;
}
@ -177,9 +176,9 @@ QString unbanUser(const CommandContext &ctx)
actionTarget.displayName);
},
[channel{ctx.channel}, userLoginsToFetch] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to timeout, bad username(s): %1")
.arg(userLoginsToFetch.join(", "))));
.arg(userLoginsToFetch.join(", ")));
});
}
else

View file

@ -1,9 +1,7 @@
#include "controllers/commands/builtin/twitch/UpdateChannel.hpp"
#include "common/Channel.hpp"
#include "common/network/NetworkResult.hpp"
#include "controllers/commands/CommandContext.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchChannel.hpp"
@ -70,15 +68,14 @@ QString setTitle(const CommandContext &ctx)
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(
makeSystemMessage("Usage: /settitle <stream title>"));
ctx.channel->addSystemMessage("Usage: /settitle <stream title>");
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(
makeSystemMessage("Unable to set title of non-Twitch channel."));
ctx.channel->addSystemMessage(
"Unable to set title of non-Twitch channel.");
return "";
}
@ -89,13 +86,13 @@ QString setTitle(const CommandContext &ctx)
[channel{ctx.channel}, title](const auto &result) {
(void)result;
channel->addMessage(
makeSystemMessage(QString("Updated title to %1").arg(title)));
channel->addSystemMessage(
QString("Updated title to %1").arg(title));
},
[channel{ctx.channel}](auto error, auto message) {
auto errorMessage =
formatUpdateChannelError("title", error, message);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return "";
@ -110,15 +107,14 @@ QString setGame(const CommandContext &ctx)
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(
makeSystemMessage("Usage: /setgame <stream game>"));
ctx.channel->addSystemMessage("Usage: /setgame <stream game>");
return "";
}
if (ctx.twitchChannel == nullptr)
{
ctx.channel->addMessage(
makeSystemMessage("Unable to set game of non-Twitch channel."));
ctx.channel->addSystemMessage(
"Unable to set game of non-Twitch channel.");
return "";
}
@ -130,7 +126,7 @@ QString setGame(const CommandContext &ctx)
gameName](const std::vector<HelixGame> &games) {
if (games.empty())
{
channel->addMessage(makeSystemMessage("Game not found."));
channel->addSystemMessage("Game not found.");
return;
}
@ -154,17 +150,17 @@ QString setGame(const CommandContext &ctx)
getHelix()->updateChannel(
twitchChannel->roomId(), matchedGame.id, "", "",
[channel, games, matchedGame](const NetworkResult &) {
channel->addMessage(makeSystemMessage(
QString("Updated game to %1").arg(matchedGame.name)));
channel->addSystemMessage(
QString("Updated game to %1").arg(matchedGame.name));
},
[channel](auto error, auto message) {
auto errorMessage =
formatUpdateChannelError("game", error, message);
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
},
[channel{ctx.channel}] {
channel->addMessage(makeSystemMessage("Failed to look up game."));
channel->addSystemMessage("Failed to look up game.");
});
return "";

View file

@ -21,8 +21,8 @@ QString updateUserColor(const CommandContext &ctx)
if (!ctx.channel->isTwitchChannel())
{
ctx.channel->addMessage(makeSystemMessage(
"The /color command only works in Twitch channels."));
ctx.channel->addSystemMessage(
"The /color command only works in Twitch channels.");
return "";
}
auto user = getIApp()->getAccounts()->twitch.getCurrent();
@ -30,8 +30,8 @@ QString updateUserColor(const CommandContext &ctx)
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
"You must be logged in to use the /color command."));
ctx.channel->addSystemMessage(
"You must be logged in to use the /color command.");
return "";
}
@ -39,11 +39,11 @@ QString updateUserColor(const CommandContext &ctx)
if (colorString.isEmpty())
{
ctx.channel->addMessage(makeSystemMessage(
ctx.channel->addSystemMessage(
QString("Usage: /color <color> - Color must be one of Twitch's "
"supported colors (%1) or a hex code (#000000) if you "
"have Turbo or Prime.")
.arg(VALID_HELIX_COLORS.join(", "))));
.arg(VALID_HELIX_COLORS.join(", ")));
return "";
}
@ -54,7 +54,7 @@ QString updateUserColor(const CommandContext &ctx)
[colorString, channel{ctx.channel}] {
QString successMessage =
QString("Your color has been changed to %1.").arg(colorString);
channel->addMessage(makeSystemMessage(successMessage));
channel->addSystemMessage(successMessage);
},
[colorString, channel{ctx.channel}](auto error, auto message) {
QString errorMessage =
@ -90,7 +90,7 @@ QString updateUserColor(const CommandContext &ctx)
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
return "";

View file

@ -1,14 +1,13 @@
#include "controllers/commands/builtin/twitch/Warn.hpp"
#include "Application.hpp"
#include "common/Channel.hpp"
#include "common/QLogging.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandContext.hpp"
#include "controllers/commands/common/ChannelAction.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
namespace {
@ -73,7 +72,7 @@ void warnUserByID(const ChannelPtr &channel, const QString &channelID,
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
}
@ -92,7 +91,7 @@ QString sendWarn(const CommandContext &ctx)
{
if (ctx.channel != nullptr)
{
ctx.channel->addMessage(makeSystemMessage(actions.error()));
ctx.channel->addSystemMessage(actions.error());
}
else
{
@ -108,8 +107,7 @@ QString sendWarn(const CommandContext &ctx)
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addMessage(
makeSystemMessage("You must be logged in to warn someone!"));
ctx.channel->addSystemMessage("You must be logged in to warn someone!");
return "";
}
@ -118,8 +116,8 @@ QString sendWarn(const CommandContext &ctx)
const auto &reason = action.reason;
if (reason.isEmpty())
{
ctx.channel->addMessage(
makeSystemMessage("Failed to warn, you must specify a reason"));
ctx.channel->addSystemMessage(
"Failed to warn, you must specify a reason");
break;
}
@ -161,16 +159,16 @@ QString sendWarn(const CommandContext &ctx)
userLoginsToFetch](const auto &users) mutable {
if (!actionChannel.hydrateFrom(users))
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to warn, bad channel name: %1")
.arg(actionChannel.login)));
.arg(actionChannel.login));
return;
}
if (!actionTarget.hydrateFrom(users))
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to warn, bad target name: %1")
.arg(actionTarget.login)));
.arg(actionTarget.login));
return;
}
@ -179,9 +177,9 @@ QString sendWarn(const CommandContext &ctx)
reason, actionTarget.displayName);
},
[channel{ctx.channel}, userLoginsToFetch] {
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString("Failed to warn, bad username(s): %1")
.arg(userLoginsToFetch.join(", "))));
.arg(userLoginsToFetch.join(", ")));
});
}
else

View file

@ -248,13 +248,12 @@ void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
{
if (hasEmotes)
{
shared->addMessage(makeSystemMessage(
"BetterTTV channel emotes reloaded."));
shared->addSystemMessage(
"BetterTTV channel emotes reloaded.");
}
else
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
})
@ -270,8 +269,7 @@ void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
// User does not have any BTTV emotes
if (manualRefresh)
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
else
@ -281,10 +279,10 @@ void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
qCWarning(chatterinoBttv)
<< "Error fetching BTTV emotes for channel" << channelId
<< ", error" << errorString;
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral("Failed to fetch BetterTTV channel "
"emotes. (Error: %1)")
.arg(errorString)));
.arg(errorString));
}
})
.execute();

View file

@ -287,13 +287,12 @@ void FfzEmotes::loadChannel(
{
if (hasEmotes)
{
shared->addMessage(makeSystemMessage(
"FrankerFaceZ channel emotes reloaded."));
shared->addSystemMessage(
"FrankerFaceZ channel emotes reloaded.");
}
else
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
})
@ -309,8 +308,7 @@ void FfzEmotes::loadChannel(
// User does not have any FFZ emotes
if (manualRefresh)
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
else
@ -319,10 +317,10 @@ void FfzEmotes::loadChannel(
auto errorString = result.formatError();
qCWarning(LOG) << "Error fetching FFZ emotes for channel"
<< channelID << ", error" << errorString;
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral("Failed to fetch FrankerFaceZ channel "
"emotes. (Error: %1)")
.arg(errorString)));
.arg(errorString));
}
})
.execute();

View file

@ -1,5 +1,6 @@
#include "IrcChannel2.hpp"
#include "common/Channel.hpp"
#include "debug/AssertInGuiThread.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
@ -28,7 +29,7 @@ void IrcChannel::sendMessage(const QString &message)
if (message.startsWith("/"))
{
int index = message.indexOf(' ', 1);
auto index = message.indexOf(' ', 1);
QString command = message.mid(1, index - 1);
QString params = index == -1 ? "" : message.mid(index + 1);
@ -73,7 +74,7 @@ void IrcChannel::sendMessage(const QString &message)
}
else
{
this->addMessage(makeSystemMessage("You are not connected."));
this->addSystemMessage("You are not connected.");
}
}
}

View file

@ -27,7 +27,7 @@ Outcome invokeIrcCommand(const QString &commandName, const QString &allParams,
if (auto it = staticMessages.find(cmd); it != staticMessages.end())
{
channel.addMessage(makeSystemMessage(it->second));
channel.addSystemMessage(it->second);
return Success;
}
@ -57,8 +57,8 @@ Outcome invokeIrcCommand(const QString &commandName, const QString &allParams,
{
if (params.size() < 2)
{
channel.addMessage(
makeSystemMessage("Usage: /kick <channel> <client> [message]"));
channel.addSystemMessage(
"Usage: /kick <channel> <client> [message]");
return Failure;
}
const auto &channelParam = params[0];

View file

@ -84,10 +84,10 @@ void IrcServer::initializeConnectionSignals(IrcConnection *connection,
{
if (auto shared = weak.lock())
{
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral("Socket error: ") +
QAbstractSocket::staticMetaObject.enumerator(index)
.valueToKey(error)));
.valueToKey(error));
}
}
});
@ -270,7 +270,7 @@ void IrcServer::readConnectionMessageReceived(Communi::IrcMessage *message)
{
if (message->nick() == this->data_->nick)
{
shared->addMessage(makeSystemMessage("joined"));
shared->addSystemMessage("joined");
}
else
{
@ -295,7 +295,7 @@ void IrcServer::readConnectionMessageReceived(Communi::IrcMessage *message)
{
if (message->nick() == this->data_->nick)
{
shared->addMessage(makeSystemMessage("parted"));
shared->addSystemMessage("parted");
}
else
{

View file

@ -68,9 +68,9 @@ void load(
if (errorCode == "channel_not_joined" &&
!messages.empty())
{
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
"Message history service recovering, there may "
"be gaps in the message history."));
"be gaps in the message history.");
}
}
@ -87,10 +87,10 @@ void load(
qCDebug(LOG) << "Failed to load recent messages for"
<< shared->getName();
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral(
"Message history service unavailable (Error: %1)")
.arg(result.formatError())));
.arg(result.formatError()));
onError();
})

View file

@ -289,13 +289,11 @@ void SeventvEmotes::loadChannelEmotes(
{
if (hasEmotes)
{
shared->addMessage(
makeSystemMessage("7TV channel emotes reloaded."));
shared->addSystemMessage("7TV channel emotes reloaded.");
}
else
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
},
@ -312,8 +310,7 @@ void SeventvEmotes::loadChannelEmotes(
<< result.parseJson();
if (manualRefresh)
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
else
@ -323,10 +320,10 @@ void SeventvEmotes::loadChannelEmotes(
qCWarning(chatterinoSeventv)
<< "Error fetching 7TV emotes for channel" << channelId
<< ", error" << errorString;
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral("Failed to fetch 7TV channel "
"emotes. (Error: %1)")
.arg(errorString)));
.arg(errorString));
}
});
}

View file

@ -1,6 +1,7 @@
#include "providers/twitch/IrcMessageHandler.hpp"
#include "Application.hpp"
#include "common/Channel.hpp"
#include "common/Common.hpp"
#include "common/Literals.hpp"
#include "common/QLogging.hpp"
@ -1136,15 +1137,15 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
QString tags = message->tags().value("msg-id").toString();
if (tags == "usage_delete")
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
"Usage: /delete <msg-id> - Deletes the specified message. "
"Can't take more than one argument."));
"Can't take more than one argument.");
}
else if (tags == "bad_delete_message_error")
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
"There was a problem deleting the message. "
"It might be from another channel or too old to delete."));
"It might be from another channel or too old to delete.");
}
else if (tags == "host_on" || tags == "host_target_went_offline")
{
@ -1218,7 +1219,7 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
if (message->nick() ==
getIApp()->getAccounts()->twitch.getCurrent()->getUserName())
{
twitchChannel->addMessage(makeSystemMessage("joined channel"));
twitchChannel->addSystemMessage("joined channel");
twitchChannel->joined.invoke();
}
else if (getSettings()->showJoins.getValue())

View file

@ -362,8 +362,8 @@ void TwitchAccount::loadUserstateEmotes(std::weak_ptr<Channel> weakChannel)
if (auto channel = weakChannel.lock(); channel != nullptr)
{
channel->addMessage(makeSystemMessage(
"Twitch subscriber emotes reloaded."));
channel->addSystemMessage(
"Twitch subscriber emotes reloaded.");
}
},
[] {
@ -427,7 +427,7 @@ void TwitchAccount::autoModAllow(const QString msgID, ChannelPtr channel)
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
}
@ -473,7 +473,7 @@ void TwitchAccount::autoModDeny(const QString msgID, ChannelPtr channel)
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
}

View file

@ -2,7 +2,6 @@
#include "Application.hpp"
#include "common/Common.hpp"
#include "common/Env.hpp"
#include "common/network/NetworkRequest.hpp"
#include "common/network/NetworkResult.hpp"
#include "common/QLogging.hpp"
@ -217,7 +216,7 @@ TwitchChannel::TwitchChannel(const QString &name)
// debugging
#if 0
for (int i = 0; i < 1000; i++) {
this->addMessage(makeSystemMessage("asef"));
this->addSystemMessage("asef");
}
#endif
}
@ -1012,9 +1011,9 @@ void TwitchChannel::updateSeventvUser(
if (auto shared = weak.lock())
{
this->seventvEmotes_.set(EMPTY_EMOTE_MAP);
this->addMessage(makeSystemMessage(
this->addSystemMessage(
QString("Failed updating 7TV emote set (%1).")
.arg(reason)));
.arg(reason));
}
});
});
@ -1512,7 +1511,7 @@ void TwitchChannel::refreshBadges()
break;
}
this->addMessage(makeSystemMessage(errorMessage));
this->addSystemMessage(errorMessage);
});
}
@ -1600,8 +1599,8 @@ void TwitchChannel::createClip()
{
if (!this->isLive())
{
this->addMessage(makeSystemMessage(
"Cannot create clip while the channel is offline!"));
this->addSystemMessage(
"Cannot create clip while the channel is offline!");
return;
}
@ -1616,7 +1615,7 @@ void TwitchChannel::createClip()
return;
}
this->addMessage(makeSystemMessage("Creating clip..."));
this->addSystemMessage("Creating clip...");
this->isClipCreationInProgress = true;
getHelix()->createClip(

View file

@ -42,8 +42,8 @@ void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
auto broadcasterID = channel->roomId();
if (broadcasterID.isEmpty())
{
channel->addMessage(makeSystemMessage(
"Sending messages in this channel isn't possible."));
channel->addSystemMessage(
"Sending messages in this channel isn't possible.");
return;
}
@ -67,14 +67,14 @@ void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
return;
}
auto errorMessage = [&] {
if (res.dropReason)
{
return makeSystemMessage(res.dropReason->message);
}
return makeSystemMessage("Your message was not sent.");
}();
chan->addMessage(errorMessage);
if (res.dropReason)
{
chan->addSystemMessage(res.dropReason->message);
}
else
{
chan->addSystemMessage("Your message was not sent.");
}
},
[weak = std::weak_ptr(channel)](auto error, auto message) {
auto chan = weak.lock();
@ -112,7 +112,7 @@ void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
return "Unknown error: " + message;
}
}();
chan->addMessage(makeSystemMessage(errorMessage));
chan->addSystemMessage(errorMessage);
});
}
@ -390,14 +390,13 @@ std::shared_ptr<Channel> TwitchIrcServer::getCustomChannel(
{
for (auto i = 0; i < 1000; i++)
{
channel->addMessage(makeSystemMessage(QString::number(i + 1)));
channel->addSystemMessage(QString::number(i + 1));
}
}
auto *timer = new QTimer;
QObject::connect(timer, &QTimer::timeout, [channel] {
channel->addMessage(
makeSystemMessage(QTime::currentTime().toString()));
channel->addSystemMessage(QTime::currentTime().toString());
});
timer->start(msBetweenMessages);
return timer;
@ -562,10 +561,7 @@ bool TwitchIrcServer::prepareToSend(
{
if (this->lastErrorTimeSpeed_ + 30s < now)
{
auto errorMessage =
makeSystemMessage("You are sending messages too quickly.");
channel->addMessage(errorMessage);
channel->addSystemMessage("You are sending messages too quickly.");
this->lastErrorTimeSpeed_ = now;
}
@ -583,10 +579,7 @@ bool TwitchIrcServer::prepareToSend(
{
if (this->lastErrorTimeAmount_ + 30s < now)
{
auto errorMessage =
makeSystemMessage("You are sending too many messages.");
channel->addMessage(errorMessage);
channel->addSystemMessage("You are sending too many messages.");
this->lastErrorTimeAmount_ = now;
}

View file

@ -64,8 +64,8 @@ void ImageUploader::logToFile(const QString &originalFilePath,
logReadFile.open(QIODevice::ReadWrite | QIODevice::Text);
if (!isLogFileOkay)
{
channel->addMessage(makeSystemMessage(
QString("Failed to open log file with links at ") + logFileName));
channel->addSystemMessage(
QString("Failed to open log file with links at ") + logFileName);
return;
}
auto logs = logReadFile.readAll();
@ -197,7 +197,7 @@ void ImageUploader::handleFailedUpload(const NetworkResult &result,
}
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
// NOTE: We abort any future uploads on failure. Should this be handled differently?
while (!this->uploadQueue_.empty())
{
@ -376,8 +376,7 @@ void ImageUploader::upload(std::queue<RawImageData> images, ChannelPtr channel,
BenchmarkGuard benchmarkGuard("upload");
if (!this->uploadMutex_.tryLock())
{
channel->addMessage(makeSystemMessage(
QString("Please wait until the upload finishes.")));
channel->addSystemMessage("Please wait until the upload finishes.");
return;
}
@ -386,7 +385,7 @@ void ImageUploader::upload(std::queue<RawImageData> images, ChannelPtr channel,
std::swap(this->uploadQueue_, images);
channel->addMessage(makeSystemMessage("Started upload..."));
channel->addSystemMessage("Started upload...");
this->sendImageUploadRequest(this->uploadQueue_.front(), std::move(channel),
std::move(outputTextEdit));

View file

@ -194,8 +194,8 @@ void openStreamlinkForChannel(const QString &channel)
auto *currentSplit = currentPage->getSelectedSplit();
if (currentSplit != nullptr)
{
currentSplit->getChannel()->addMessage(
makeSystemMessage(INFO_TEMPLATE.arg(channel)));
currentSplit->getChannel()->addSystemMessage(
INFO_TEMPLATE.arg(channel));
}
}

View file

@ -1,52 +0,0 @@
#include "NotificationPopup.hpp"
#include "common/Channel.hpp"
#include "messages/Message.hpp"
#include "widgets/helper/ChannelView.hpp"
#include <QApplication>
#include <QScreen>
#include <QVBoxLayout>
namespace chatterino {
NotificationPopup::NotificationPopup()
: BaseWindow({BaseWindow::Frameless, BaseWindow::DisableLayoutSave})
, channel_(std::make_shared<Channel>("notifications", Channel::Type::None))
{
this->channelView_ = new ChannelView(this);
auto *layout = new QVBoxLayout(this);
this->setLayout(layout);
layout->addWidget(this->channelView_);
this->channelView_->setChannel(this->channel_);
this->setScaleIndependantSize(300, 150);
}
void NotificationPopup::updatePosition()
{
Location location = BottomRight;
const QRect rect = QGuiApplication::primaryScreen()->availableGeometry();
switch (location)
{
case BottomRight: {
this->move(rect.right() - this->width(),
rect.bottom() - this->height());
}
break;
}
}
void NotificationPopup::addMessage(MessagePtr msg)
{
this->channel_->addMessage(std::move(msg));
// QTimer::singleShot(5000, this, [this, msg] { this->channel->remove });
}
} // namespace chatterino

View file

@ -1,29 +0,0 @@
#pragma once
#include "widgets/BaseWindow.hpp"
namespace chatterino {
class ChannelView;
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
struct Message;
using MessagePtr = std::shared_ptr<const Message>;
class NotificationPopup : public BaseWindow
{
public:
enum Location { TopLeft, TopRight, BottomLeft, BottomRight };
NotificationPopup();
void addMessage(MessagePtr msg);
void updatePosition();
private:
ChannelView *channelView_;
ChannelPtr channel_;
};
} // namespace chatterino

View file

@ -620,17 +620,17 @@ void UserInfoPopup::installEvents()
getIApp()->getAccounts()->twitch.getCurrent()->unblockUser(
this->userId_, this,
[this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage(
this->channel_->addSystemMessage(
QString("You successfully unblocked user %1")
.arg(this->userName_)));
.arg(this->userName_));
reenableBlockCheckbox();
},
[this, reenableBlockCheckbox] {
this->channel_->addMessage(makeSystemMessage(
this->channel_->addSystemMessage(
QString(
"User %1 couldn't be unblocked, an unknown "
"error occurred!")
.arg(this->userName_)));
.arg(this->userName_));
reenableBlockCheckbox();
});
}
@ -647,17 +647,17 @@ void UserInfoPopup::installEvents()
getIApp()->getAccounts()->twitch.getCurrent()->blockUser(
this->userId_, this,
[this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage(
this->channel_->addSystemMessage(
QString("You successfully blocked user %1")
.arg(this->userName_)));
.arg(this->userName_));
reenableBlockCheckbox();
},
[this, reenableBlockCheckbox] {
this->channel_->addMessage(makeSystemMessage(
this->channel_->addSystemMessage(
QString(
"User %1 couldn't be blocked, an unknown "
"error occurred!")
.arg(this->userName_)));
.arg(this->userName_));
reenableBlockCheckbox();
});
}

View file

@ -393,10 +393,10 @@ Split::Split(QWidget *parent)
imageUploader->getImages(original);
if (images.empty())
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
QString(
"An error occurred trying to process your image: %1")
.arg(imageProcessError)));
.arg(imageProcessError));
return;
}