Skip to content

Commit

Permalink
feat: add /announce[color] commands (#5250)
Browse files Browse the repository at this point in the history
  • Loading branch information
4rneee authored Mar 14, 2024
1 parent e750833 commit fc61e8d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
67 changes: 60 additions & 7 deletions src/controllers/commands/builtin/twitch/Announce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -25,25 +27,47 @@ 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 "";
}

auto user = getIApp()->getAccounts()->twitch.getCurrent();
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.
},
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions src/controllers/commands/builtin/twitch/Announce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fc61e8d

Please sign in to comment.