Make /delete errors a bit more verbose (#3350)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -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 <msg-id> - 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(" "));
|
||||
|
||||
@@ -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 <msg-id>. Can't take more than one argument"));
|
||||
"Usage: /delete <msg-id> - 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")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user