Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add /announce[color] commands #5250

Merged
merged 5 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
pajlada marked this conversation as resolved.
Show resolved Hide resolved
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
Loading