From a68980878e06be175b49750a0c045bf0ded97f85 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sat, 13 Nov 2021 12:34:04 +0000 Subject: [PATCH] Make `/delete` errors a bit more verbose (#3350) Co-authored-by: Rasmus Karlsson --- CHANGELOG.md | 1 + .../commands/CommandController.cpp | 37 +++++++++++++++++++ src/providers/twitch/IrcMessageHandler.cpp | 11 +++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6f8a4f65..8f7184795 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Minor: Clean up chat messages of special line characters prior to sending. (#3312) - Minor: IRC now parses/displays links like Twitch chat. (#3334) - Minor: Added button & label for copying login name of user instead of display name in the user info popout. (#3335) +- Minor: Make `/delete` errors a bit more verbose (#3350) - Bugfix: Fixed colored usernames sometimes not working. (#3170) - Bugfix: Restored ability to send duplicate `/me` messages. (#3166) - Bugfix: Notifications for moderators about other moderators deleting messages can now be disabled. (#3121) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 769c9efbb..32771933c 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -866,6 +866,43 @@ void CommandController::initialize(Settings &, Paths &paths) return ""; }); + this->registerCommand( + "/delete", [](const QStringList &words, ChannelPtr channel) -> QString { + // This is a wrapper over the standard Twitch /delete command + // We use this to ensure the user gets better error messages for missing or malformed arguments + if (words.size() < 2) + { + channel->addMessage( + makeSystemMessage("Usage: /delete - Deletes the " + "specified message.")); + return ""; + } + + auto messageID = words.at(1); + auto uuid = QUuid(messageID); + if (uuid.isNull()) + { + // The message id must be a valid UUID + channel->addMessage(makeSystemMessage( + QString("Invalid msg-id: \"%1\"").arg(messageID))); + return ""; + } + + auto msg = channel->findMessage(messageID); + if (msg != nullptr) + { + if (msg->loginName == channel->getName() && + !channel->isBroadcaster()) + { + channel->addMessage(makeSystemMessage( + "You cannot delete the broadcaster's messages unless " + "you are the broadcaster.")); + return ""; + } + } + + return QString("/delete ") + messageID; + }); this->registerCommand("/raw", [](const QStringList &words, ChannelPtr) { getApp()->twitch2->sendRawMessage(words.mid(1).join(" ")); diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 04a54aad5..253aa22fc 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -807,10 +807,17 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) } QString tags = message->tags().value("msg-id").toString(); - if (tags == "bad_delete_message_error" || tags == "usage_delete") + if (tags == "usage_delete") { channel->addMessage(makeSystemMessage( - "Usage: /delete . Can't take more than one argument")); + "Usage: /delete - Deletes the specified message. " + "Can't take more than one argument.")); + } + else if (tags == "bad_delete_message_error") + { + channel->addMessage(makeSystemMessage( + "There was a problem deleting the message. " + "It might be from another channel or too old to delete.")); } else if (tags == "host_on" || tags == "host_target_went_offline") {