feat: add /announce[color] commands (#5250)

This commit is contained in:
Arne 2024-03-14 20:36:58 +01:00 committed by GitHub
parent e7508332ff
commit fc61e8d64d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 77 additions and 7 deletions

View file

@ -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)

View file

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

View file

@ -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<HelixAnnouncementColor>(color)})
.toLower();
}
if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
"Usage: /announce <message> - Call attention to your "
"message with a highlight."));
QString usageMsg;
if (color == HelixAnnouncementColor::Primary)
{
usageMsg = "Usage: /announce <message> - Call attention to your "
"message with a highlight.";
}
else
{
usageMsg =
QString("Usage: /announce%1 <message> - 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

View file

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