Migrate /unban and /untimeout to Helix API (#4026)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Aiden
2022-10-01 16:10:06 +01:00
committed by GitHub
parent adbc4690af
commit a275a1793a
5 changed files with 297 additions and 3 deletions
@@ -1819,6 +1819,147 @@ void CommandController::initialize(Settings &, Paths &paths)
return "";
});
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
auto unbanLambda = [](auto words, auto channel) {
auto commandName = words.at(0).toLower();
if (words.size() < 2)
{
channel->addMessage(makeSystemMessage(
QString("Usage: \"%1 <username>\" - Removes a ban on a user.")
.arg(commandName)));
return "";
}
auto currentUser = getApp()->accounts->twitch.getCurrent();
if (currentUser->isAnon())
{
channel->addMessage(
makeSystemMessage("You must be logged in to unban someone!"));
return "";
}
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel == nullptr)
{
channel->addMessage(makeSystemMessage(
QString("The %1 command only works in Twitch channels")
.arg(commandName)));
return "";
}
auto target = words.at(1);
stripChannelName(target);
getHelix()->getUserByName(
target,
[channel, currentUser, twitchChannel,
target](const auto &targetUser) {
getHelix()->unbanUser(
twitchChannel->roomId(), currentUser->getUserId(),
targetUser.id,
[] {
// No response for unbans, they're emitted over pubsub/IRC instead
},
[channel, target, targetUser](auto error, auto message) {
using Error = HelixUnbanUserError;
QString errorMessage =
QString("Failed to unban user - ");
switch (error)
{
case Error::ConflictingOperation: {
errorMessage +=
"There was a conflicting ban operation on "
"this user. Please try again.";
}
break;
case Error::Forwarded: {
errorMessage += message;
}
break;
case Error::Ratelimited: {
errorMessage +=
"You are being ratelimited by Twitch. Try "
"again in a few seconds.";
}
break;
case Error::TargetNotBanned: {
// Equivalent IRC error
errorMessage =
QString(
"%1 is not banned from this channel.")
.arg(targetUser.displayName);
}
break;
case Error::UserMissingScope: {
// TODO(pajlada): Phrase MISSING_REQUIRED_SCOPE
errorMessage += "Missing required scope. "
"Re-login with your "
"account and try again.";
}
break;
case Error::UserNotAuthorized: {
// TODO(pajlada): Phrase MISSING_PERMISSION
errorMessage += "You don't have permission to "
"perform that action.";
}
break;
case Error::Unknown: {
errorMessage +=
"An unknown error has occurred.";
}
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
});
},
[channel, target] {
// Equivalent error from IRC
channel->addMessage(makeSystemMessage(
QString("Invalid username: %1").arg(target)));
});
return "";
}; // These changes are from the helix-command-migration/unban-untimeout branch
this->registerCommand("/unban", [unbanLambda](const QStringList &words,
auto channel) {
return unbanLambda(words, channel);
}); // These changes are from the helix-command-migration/unban-untimeout branch
this->registerCommand("/untimeout", [unbanLambda](const QStringList &words,
auto channel) {
return unbanLambda(words, channel);
}); // These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
}
void CommandController::save()