From c71d3437f47c0c79526dfc6f374915db63a10b73 Mon Sep 17 00:00:00 2001 From: Aiden Date: Sat, 15 Oct 2022 11:36:49 +0100 Subject: [PATCH] Migrate /uniquechat and /uniquechatoff to Helix API (#4057) * Migrate /uniquechat and /uniquechatoff to Helix * Update CHANGELOG.md * Move & squash changelog entries Co-authored-by: Rasmus Karlsson --- CHANGELOG.md | 2 + .../commands/CommandController.cpp | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e28ec8628..30b6908e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,8 @@ - Minor: Migrated /timeout to Helix API. (#4049) - Minor: Migrated /w to Helix API. Chat command will continue to be used until February 11th 2023. (#4052) - Minor: Migrated /vips to Helix API. Chat command will continue to be used until February 11th 2023. (#4053) +- Minor: Migrated /uniquechat and /r9kbeta to Helix API. (#4057) +- Minor: Migrated /uniquechatoff and /r9kbetaoff to Helix API. (#4057) - Minor: Make menus and placeholders display appropriate custom key combos. (#4045) - Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716) - Bugfix: Fixed `Smooth scrolling on new messages` setting sometimes hiding messages. (#4028) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index f8f1cb530..a8ffba1a1 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -3068,6 +3068,67 @@ void CommandController::initialize(Settings &, Paths &paths) return ""; }); + + auto uniqueChatLambda = [formatChatSettingsError](auto words, auto channel, + bool target) { + auto currentUser = getApp()->accounts->twitch.getCurrent(); + if (currentUser->isAnon()) + { + channel->addMessage(makeSystemMessage( + "You must be logged in to update chat settings!")); + return ""; + } + auto *twitchChannel = dynamic_cast(channel.get()); + if (twitchChannel == nullptr) + { + channel->addMessage(makeSystemMessage( + QString("The /%1 command only works in Twitch channels") + .arg(target ? "uniquechat" : "uniquechatoff"))); + return ""; + } + + if (twitchChannel->accessRoomModes()->r9k == target) + { + channel->addMessage(makeSystemMessage( + target ? "This room is already in unique-chat mode." + : "This room is not in unique-chat mode.")); + return ""; + } + + getHelix()->updateUniqueChatMode( + twitchChannel->roomId(), currentUser->getUserId(), target, + [](auto) { + // we'll get a message from irc + }, + [channel, formatChatSettingsError](auto error, auto message) { + channel->addMessage( + makeSystemMessage(formatChatSettingsError(error, message))); + }); + return ""; + }; + + this->registerCommand( + "/uniquechatoff", + [uniqueChatLambda](const QStringList &words, auto channel) { + return uniqueChatLambda(words, channel, false); + }); + + this->registerCommand( + "/r9kbetaoff", + [uniqueChatLambda](const QStringList &words, auto channel) { + return uniqueChatLambda(words, channel, false); + }); + + this->registerCommand( + "/uniquechat", + [uniqueChatLambda](const QStringList &words, auto channel) { + return uniqueChatLambda(words, channel, true); + }); + + this->registerCommand( + "/r9kbeta", [uniqueChatLambda](const QStringList &words, auto channel) { + return uniqueChatLambda(words, channel, true); + }); } void CommandController::save()