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(" "));
|
||||
|
||||
Reference in New Issue
Block a user