From 178956b85d27f43d9f8b76d6d43fe00a9f950293 Mon Sep 17 00:00:00 2001 From: Arne Date: Wed, 13 Mar 2024 12:32:41 +0100 Subject: [PATCH 1/5] add /announce[color] command variations --- .../commands/CommandController.cpp | 4 +++ .../commands/builtin/twitch/Announce.cpp | 30 +++++++++++++++++-- .../commands/builtin/twitch/Announce.hpp | 12 ++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 35cd4be0108..a5554570a87 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 566c79fe10a..4c4b429985b 100644 --- a/src/controllers/commands/builtin/twitch/Announce.cpp +++ b/src/controllers/commands/builtin/twitch/Announce.cpp @@ -11,7 +11,8 @@ namespace chatterino::commands { -QString sendAnnouncement(const CommandContext &ctx) +QString sendAnnouncementColor(const CommandContext &ctx, + const HelixAnnouncementColor color) { if (ctx.channel == nullptr) { @@ -43,7 +44,7 @@ QString sendAnnouncement(const CommandContext &ctx) getHelix()->sendChatAnnouncement( ctx.twitchChannel->roomId(), user->getUserId(), - ctx.words.mid(1).join(" "), HelixAnnouncementColor::Primary, + ctx.words.mid(1).join(" "), color, []() { // do nothing. }, @@ -78,4 +79,29 @@ QString sendAnnouncement(const CommandContext &ctx) return ""; } +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 3904d1a203c..898ea0e32d9 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 From f415710a4d192887d4e18a51e295eac79ba5b517 Mon Sep 17 00:00:00 2001 From: Arne Date: Wed, 13 Mar 2024 20:50:46 +0100 Subject: [PATCH 2/5] adjust usage and error message for /announce[color] commands --- .../commands/builtin/twitch/Announce.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/controllers/commands/builtin/twitch/Announce.cpp b/src/controllers/commands/builtin/twitch/Announce.cpp index 4c4b429985b..b0eba229f4d 100644 --- a/src/controllers/commands/builtin/twitch/Announce.cpp +++ b/src/controllers/commands/builtin/twitch/Announce.cpp @@ -26,11 +26,23 @@ QString sendAnnouncementColor(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("Usage: /announce%1 - Call attention to your " + "message with a %1%2highlight.") + .arg(colorStr) + .arg(color == HelixAnnouncementColor::Primary ? "" : " "))); return ""; } @@ -38,7 +50,8 @@ QString sendAnnouncementColor(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 ""; } From 56b5c389481fa1c76789ed36f576138c8d913e4a Mon Sep 17 00:00:00 2001 From: Arne Date: Wed, 13 Mar 2024 21:03:16 +0100 Subject: [PATCH 3/5] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90c9d449be7..0498968456a 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) From 17d770c6835df4e45a5009dd6dd2af6fee8d0764 Mon Sep 17 00:00:00 2001 From: Arne Date: Thu, 14 Mar 2024 08:39:24 +0100 Subject: [PATCH 4/5] move sendAnnouncementColor function to an anon namespace --- src/controllers/commands/builtin/twitch/Announce.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/controllers/commands/builtin/twitch/Announce.cpp b/src/controllers/commands/builtin/twitch/Announce.cpp index b0eba229f4d..4ff431a0deb 100644 --- a/src/controllers/commands/builtin/twitch/Announce.cpp +++ b/src/controllers/commands/builtin/twitch/Announce.cpp @@ -9,7 +9,8 @@ #include "providers/twitch/TwitchAccount.hpp" #include "providers/twitch/TwitchChannel.hpp" -namespace chatterino::commands { +namespace { +using namespace chatterino; QString sendAnnouncementColor(const CommandContext &ctx, const HelixAnnouncementColor color) @@ -91,6 +92,9 @@ QString sendAnnouncementColor(const CommandContext &ctx, }); return ""; } +} // namespace + +namespace chatterino::commands { QString sendAnnouncement(const CommandContext &ctx) { From 058560fd3cc74ccda6bf318de805dbbc19315b15 Mon Sep 17 00:00:00 2001 From: Arne Date: Thu, 14 Mar 2024 08:43:36 +0100 Subject: [PATCH 5/5] make usage message logic in sendAnnouncementColor more explicit --- .../commands/builtin/twitch/Announce.cpp | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/controllers/commands/builtin/twitch/Announce.cpp b/src/controllers/commands/builtin/twitch/Announce.cpp index 4ff431a0deb..d14d1f914b3 100644 --- a/src/controllers/commands/builtin/twitch/Announce.cpp +++ b/src/controllers/commands/builtin/twitch/Announce.cpp @@ -39,11 +39,20 @@ QString sendAnnouncementColor(const CommandContext &ctx, if (ctx.words.size() < 2) { - ctx.channel->addMessage(makeSystemMessage( - QString("Usage: /announce%1 - Call attention to your " - "message with a %1%2highlight.") - .arg(colorStr) - .arg(color == HelixAnnouncementColor::Primary ? "" : " "))); + 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 ""; } @@ -92,7 +101,8 @@ QString sendAnnouncementColor(const CommandContext &ctx, }); return ""; } -} // namespace + +} // namespace namespace chatterino::commands {