diff --git a/CHANGELOG.md b/CHANGELOG.md index 90c9d449b..049896845 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ - Minor: 7TV emotes now have a 4x image rather than a 3x image. (#5209) - Minor: Add wrappers for Lua `io` library for experimental plugins feature. (#5231) - Minor: Add permissions to experimental plugins feature. (#5231) +- Minor: Add support to send /announce[color] commands. (#5250) - Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840) - Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848) - Bugfix: Trimmed custom streamlink paths on all platforms making sure you don't accidentally add spaces at the beginning or end of its path. (#4834) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 35cd4be01..a5554570a 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -401,6 +401,10 @@ void CommandController::initialize(Settings &, const Paths &paths) this->registerCommand("/unmod", &commands::removeModerator); this->registerCommand("/announce", &commands::sendAnnouncement); + this->registerCommand("/announceblue", &commands::sendAnnouncementBlue); + this->registerCommand("/announcegreen", &commands::sendAnnouncementGreen); + this->registerCommand("/announceorange", &commands::sendAnnouncementOrange); + this->registerCommand("/announcepurple", &commands::sendAnnouncementPurple); this->registerCommand("/vip", &commands::addVIP); diff --git a/src/controllers/commands/builtin/twitch/Announce.cpp b/src/controllers/commands/builtin/twitch/Announce.cpp index 566c79fe1..d14d1f914 100644 --- a/src/controllers/commands/builtin/twitch/Announce.cpp +++ b/src/controllers/commands/builtin/twitch/Announce.cpp @@ -9,9 +9,11 @@ #include "providers/twitch/TwitchAccount.hpp" #include "providers/twitch/TwitchChannel.hpp" -namespace chatterino::commands { +namespace { +using namespace chatterino; -QString sendAnnouncement(const CommandContext &ctx) +QString sendAnnouncementColor(const CommandContext &ctx, + const HelixAnnouncementColor color) { if (ctx.channel == nullptr) { @@ -25,11 +27,32 @@ QString sendAnnouncement(const CommandContext &ctx) return ""; } + QString colorStr = ""; + if (color != HelixAnnouncementColor::Primary) + { + colorStr = + QString::fromStdString( + std::string{ + magic_enum::enum_name(color)}) + .toLower(); + } + if (ctx.words.size() < 2) { - ctx.channel->addMessage(makeSystemMessage( - "Usage: /announce - Call attention to your " - "message with a highlight.")); + QString usageMsg; + if (color == HelixAnnouncementColor::Primary) + { + usageMsg = "Usage: /announce - Call attention to your " + "message with a highlight."; + } + else + { + usageMsg = + QString("Usage: /announce%1 - Call attention to your " + "message with a %1 highlight.") + .arg(colorStr); + } + ctx.channel->addMessage(makeSystemMessage(usageMsg)); return ""; } @@ -37,13 +60,14 @@ QString sendAnnouncement(const CommandContext &ctx) if (user->isAnon()) { ctx.channel->addMessage(makeSystemMessage( - "You must be logged in to use the /announce command.")); + QString("You must be logged in to use the /announce%1 command.") + .arg(colorStr))); return ""; } getHelix()->sendChatAnnouncement( ctx.twitchChannel->roomId(), user->getUserId(), - ctx.words.mid(1).join(" "), HelixAnnouncementColor::Primary, + ctx.words.mid(1).join(" "), color, []() { // do nothing. }, @@ -78,4 +102,33 @@ QString sendAnnouncement(const CommandContext &ctx) return ""; } +} // namespace + +namespace chatterino::commands { + +QString sendAnnouncement(const CommandContext &ctx) +{ + return sendAnnouncementColor(ctx, HelixAnnouncementColor::Primary); +} + +QString sendAnnouncementBlue(const CommandContext &ctx) +{ + return sendAnnouncementColor(ctx, HelixAnnouncementColor::Blue); +} + +QString sendAnnouncementGreen(const CommandContext &ctx) +{ + return sendAnnouncementColor(ctx, HelixAnnouncementColor::Green); +} + +QString sendAnnouncementOrange(const CommandContext &ctx) +{ + return sendAnnouncementColor(ctx, HelixAnnouncementColor::Orange); +} + +QString sendAnnouncementPurple(const CommandContext &ctx) +{ + return sendAnnouncementColor(ctx, HelixAnnouncementColor::Purple); +} + } // namespace chatterino::commands diff --git a/src/controllers/commands/builtin/twitch/Announce.hpp b/src/controllers/commands/builtin/twitch/Announce.hpp index 3904d1a20..898ea0e32 100644 --- a/src/controllers/commands/builtin/twitch/Announce.hpp +++ b/src/controllers/commands/builtin/twitch/Announce.hpp @@ -13,4 +13,16 @@ namespace chatterino::commands { /// /announce QString sendAnnouncement(const CommandContext &ctx); +/// /announceblue +QString sendAnnouncementBlue(const CommandContext &ctx); + +/// /announcegreen +QString sendAnnouncementGreen(const CommandContext &ctx); + +/// /announceorange +QString sendAnnouncementOrange(const CommandContext &ctx); + +/// /announcepurple +QString sendAnnouncementPurple(const CommandContext &ctx); + } // namespace chatterino::commands