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: Refactor `TwitchIrcServer`, making it abstracted. (#5421, #5435)
- Dev: Reduced the amount of scale events. (#5404, #5406) - Dev: Reduced the amount of scale events. (#5404, #5406)
- Dev: Removed unused timegate settings. (#5361) - 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: Unsingletonize `Resources2`. (#5460)
- Dev: All Lua globals now show in the `c2` global in the LuaLS metadata. (#5385) - Dev: All Lua globals now show in the `c2` global in the LuaLS metadata. (#5385)
- Dev: Images are now loaded in worker threads. (#5431) - Dev: Images are now loaded in worker threads. (#5431)

View file

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

View file

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

View file

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

View file

@ -83,6 +83,8 @@ public:
std::optional<MessageFlags> overridingFlags = std::nullopt); std::optional<MessageFlags> overridingFlags = std::nullopt);
void addMessagesAtStart(const std::vector<MessagePtr> &messages_); void addMessagesAtStart(const std::vector<MessagePtr> &messages_);
void addSystemMessage(const QString &contents);
/// Inserts the given messages in order by Message::serverReceivedTime. /// Inserts the given messages in order by Message::serverReceivedTime.
void fillInMissingMessages(const std::vector<MessagePtr> &messages); 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) if (!dryRun && channel->getType() == Channel::Type::TwitchWhispers)
{ {
channel->addMessage( channel->addSystemMessage("Use /w <username> <message> to whisper");
makeSystemMessage("Use /w <username> <message> to whisper"));
return ""; return "";
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
#include "IrcChannel2.hpp" #include "IrcChannel2.hpp"
#include "common/Channel.hpp"
#include "debug/AssertInGuiThread.hpp" #include "debug/AssertInGuiThread.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp" #include "messages/MessageBuilder.hpp"
@ -28,7 +29,7 @@ void IrcChannel::sendMessage(const QString &message)
if (message.startsWith("/")) if (message.startsWith("/"))
{ {
int index = message.indexOf(' ', 1); auto index = message.indexOf(' ', 1);
QString command = message.mid(1, index - 1); QString command = message.mid(1, index - 1);
QString params = index == -1 ? "" : message.mid(index + 1); QString params = index == -1 ? "" : message.mid(index + 1);
@ -73,7 +74,7 @@ void IrcChannel::sendMessage(const QString &message)
} }
else 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()) if (auto it = staticMessages.find(cmd); it != staticMessages.end())
{ {
channel.addMessage(makeSystemMessage(it->second)); channel.addSystemMessage(it->second);
return Success; return Success;
} }
@ -57,8 +57,8 @@ Outcome invokeIrcCommand(const QString &commandName, const QString &allParams,
{ {
if (params.size() < 2) if (params.size() < 2)
{ {
channel.addMessage( channel.addSystemMessage(
makeSystemMessage("Usage: /kick <channel> <client> [message]")); "Usage: /kick <channel> <client> [message]");
return Failure; return Failure;
} }
const auto &channelParam = params[0]; const auto &channelParam = params[0];

View file

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

View file

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

View file

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

View file

@ -1,6 +1,7 @@
#include "providers/twitch/IrcMessageHandler.hpp" #include "providers/twitch/IrcMessageHandler.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Channel.hpp"
#include "common/Common.hpp" #include "common/Common.hpp"
#include "common/Literals.hpp" #include "common/Literals.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
@ -1136,15 +1137,15 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
QString tags = message->tags().value("msg-id").toString(); QString tags = message->tags().value("msg-id").toString();
if (tags == "usage_delete") if (tags == "usage_delete")
{ {
channel->addMessage(makeSystemMessage( channel->addSystemMessage(
"Usage: /delete <msg-id> - Deletes the specified message. " "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") else if (tags == "bad_delete_message_error")
{ {
channel->addMessage(makeSystemMessage( channel->addSystemMessage(
"There was a problem deleting the message. " "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") else if (tags == "host_on" || tags == "host_target_went_offline")
{ {
@ -1218,7 +1219,7 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
if (message->nick() == if (message->nick() ==
getIApp()->getAccounts()->twitch.getCurrent()->getUserName()) getIApp()->getAccounts()->twitch.getCurrent()->getUserName())
{ {
twitchChannel->addMessage(makeSystemMessage("joined channel")); twitchChannel->addSystemMessage("joined channel");
twitchChannel->joined.invoke(); twitchChannel->joined.invoke();
} }
else if (getSettings()->showJoins.getValue()) 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) if (auto channel = weakChannel.lock(); channel != nullptr)
{ {
channel->addMessage(makeSystemMessage( channel->addSystemMessage(
"Twitch subscriber emotes reloaded.")); "Twitch subscriber emotes reloaded.");
} }
}, },
[] { [] {
@ -427,7 +427,7 @@ void TwitchAccount::autoModAllow(const QString msgID, ChannelPtr channel)
break; break;
} }
channel->addMessage(makeSystemMessage(errorMessage)); channel->addSystemMessage(errorMessage);
}); });
} }
@ -473,7 +473,7 @@ void TwitchAccount::autoModDeny(const QString msgID, ChannelPtr channel)
break; break;
} }
channel->addMessage(makeSystemMessage(errorMessage)); channel->addSystemMessage(errorMessage);
}); });
} }

View file

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

View file

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

View file

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

View file

@ -194,8 +194,8 @@ void openStreamlinkForChannel(const QString &channel)
auto *currentSplit = currentPage->getSelectedSplit(); auto *currentSplit = currentPage->getSelectedSplit();
if (currentSplit != nullptr) if (currentSplit != nullptr)
{ {
currentSplit->getChannel()->addMessage( currentSplit->getChannel()->addSystemMessage(
makeSystemMessage(INFO_TEMPLATE.arg(channel))); 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( getIApp()->getAccounts()->twitch.getCurrent()->unblockUser(
this->userId_, this, this->userId_, this,
[this, reenableBlockCheckbox, currentUser] { [this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage( this->channel_->addSystemMessage(
QString("You successfully unblocked user %1") QString("You successfully unblocked user %1")
.arg(this->userName_))); .arg(this->userName_));
reenableBlockCheckbox(); reenableBlockCheckbox();
}, },
[this, reenableBlockCheckbox] { [this, reenableBlockCheckbox] {
this->channel_->addMessage(makeSystemMessage( this->channel_->addSystemMessage(
QString( QString(
"User %1 couldn't be unblocked, an unknown " "User %1 couldn't be unblocked, an unknown "
"error occurred!") "error occurred!")
.arg(this->userName_))); .arg(this->userName_));
reenableBlockCheckbox(); reenableBlockCheckbox();
}); });
} }
@ -647,17 +647,17 @@ void UserInfoPopup::installEvents()
getIApp()->getAccounts()->twitch.getCurrent()->blockUser( getIApp()->getAccounts()->twitch.getCurrent()->blockUser(
this->userId_, this, this->userId_, this,
[this, reenableBlockCheckbox, currentUser] { [this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage( this->channel_->addSystemMessage(
QString("You successfully blocked user %1") QString("You successfully blocked user %1")
.arg(this->userName_))); .arg(this->userName_));
reenableBlockCheckbox(); reenableBlockCheckbox();
}, },
[this, reenableBlockCheckbox] { [this, reenableBlockCheckbox] {
this->channel_->addMessage(makeSystemMessage( this->channel_->addSystemMessage(
QString( QString(
"User %1 couldn't be blocked, an unknown " "User %1 couldn't be blocked, an unknown "
"error occurred!") "error occurred!")
.arg(this->userName_))); .arg(this->userName_));
reenableBlockCheckbox(); reenableBlockCheckbox();
}); });
} }

View file

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