Shorter Delete button
This commit is contained in:
@@ -12,11 +12,19 @@ class CallbackqueryCommand extends SystemCommand
|
|||||||
try {
|
try {
|
||||||
$callbackQuery = $this->getUpdate()->getCallbackQuery();
|
$callbackQuery = $this->getUpdate()->getCallbackQuery();
|
||||||
$originalSenderId = json_decode($callbackQuery->getData(), true)['sender_id'];
|
$originalSenderId = json_decode($callbackQuery->getData(), true)['sender_id'];
|
||||||
if ($originalSenderId === $callbackQuery->getFrom()?->getId()) {
|
$callbackSenderId = $callbackQuery->getFrom()?->getId();
|
||||||
|
if ($originalSenderId === $callbackSenderId) {
|
||||||
return Request::deleteMessage([
|
return Request::deleteMessage([
|
||||||
'chat_id' => $callbackQuery->getMessage()->getChat()->getId(),
|
'chat_id' => $callbackQuery->getMessage()->getChat()->getId(),
|
||||||
'message_id' => $callbackQuery->getMessage()->getMessageId(),
|
'message_id' => $callbackQuery->getMessage()->getMessageId(),
|
||||||
]);
|
]);
|
||||||
|
} else {
|
||||||
|
// Only possible if the user already has an DM channel open with the bot
|
||||||
|
// but better than nothing
|
||||||
|
return Request::sendMessage([
|
||||||
|
'chat_id' => $callbackSenderId,
|
||||||
|
'text' => 'Only the person sending the original message can delete the reply.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class GenericmessageCommand extends SystemCommand
|
|||||||
];
|
];
|
||||||
if ($message->getFrom() !== null) {
|
if ($message->getFrom() !== null) {
|
||||||
$deleteButton = new InlineKeyboardButton([
|
$deleteButton = new InlineKeyboardButton([
|
||||||
'text' => '❌ Delete (original sender only)',
|
'text' => '❌ Delete',
|
||||||
'callback_data' => json_encode([
|
'callback_data' => json_encode([
|
||||||
'sender_id' => $message->getFrom()?->getId(),
|
'sender_id' => $message->getFrom()?->getId(),
|
||||||
]),
|
]),
|
||||||
|
|||||||
Reference in New Issue
Block a user