mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Migrate /delete command to Helix API (#3999)
This commit is contained in:
parent
6e7b4d8ec7
commit
838e156a04
3 changed files with 47 additions and 39 deletions
|
@ -36,6 +36,7 @@
|
||||||
- Minor: Added link back to original message that was deleted. (#3953)
|
- Minor: Added link back to original message that was deleted. (#3953)
|
||||||
- Minor: Migrate /color command to Helix API. (#3988)
|
- Minor: Migrate /color command to Helix API. (#3988)
|
||||||
- Minor: Migrate /clear command to Helix API. (#3994)
|
- Minor: Migrate /clear command to Helix API. (#3994)
|
||||||
|
- Minor: Migrate /delete command to Helix API. (#3999)
|
||||||
- Bugfix: Fix crash that can occur when closing and quickly reopening a split, then running a command. (#3852)
|
- Bugfix: Fix crash that can occur when closing and quickly reopening a split, then running a command. (#3852)
|
||||||
- Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716)
|
- Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716)
|
||||||
- Bugfix: Fix crash that can occur when changing channels. (#3799)
|
- Bugfix: Fix crash that can occur when changing channels. (#3799)
|
||||||
|
|
|
@ -1074,44 +1074,6 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
return "";
|
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) {
|
this->registerCommand("/raw", [](const QStringList &words, ChannelPtr) {
|
||||||
getApp()->twitch->sendRawMessage(words.mid(1).join(" "));
|
getApp()->twitch->sendRawMessage(words.mid(1).join(" "));
|
||||||
return "";
|
return "";
|
||||||
|
@ -1333,7 +1295,7 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HelixDeleteChatMessagesError::Forwarded: {
|
case HelixDeleteChatMessagesError::Forwarded: {
|
||||||
errorMessage += message + ".";
|
errorMessage += message;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1355,6 +1317,44 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
(void)words; // unused
|
(void)words; // unused
|
||||||
return deleteMessages(channel, QString());
|
return deleteMessages(channel, QString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this->registerCommand("/delete", [deleteMessages](const QStringList &words,
|
||||||
|
auto channel) {
|
||||||
|
// This is a wrapper over the Helix delete messages endpoint
|
||||||
|
// 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 deleteMessages(channel, messageID);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandController::save()
|
void CommandController::save()
|
||||||
|
|
|
@ -887,6 +887,13 @@ void Helix::deleteChatMessages(
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 400: {
|
||||||
|
// These errors are generally well formatted, so we just forward them.
|
||||||
|
// This is currently undocumented behaviour, see: https://github.com/twitchdev/issues/issues/660
|
||||||
|
failureCallback(Error::Forwarded, message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 403: {
|
case 403: {
|
||||||
// 403 endpoint means the user does not have permission to perform this action in that channel
|
// 403 endpoint means the user does not have permission to perform this action in that channel
|
||||||
// Most likely to missing moderator permissions
|
// Most likely to missing moderator permissions
|
||||||
|
|
Loading…
Reference in a new issue