From cc302e54312dfad238baed0f08d969c9bdbfdf88 Mon Sep 17 00:00:00 2001 From: TangMo Date: Wed, 19 Apr 2023 19:34:08 +0000 Subject: [PATCH] Shorter Delete button --- src/Commands/CallbackqueryCommand.php | 12 ++++++++++-- src/Commands/GenericmessageCommand.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Commands/CallbackqueryCommand.php b/src/Commands/CallbackqueryCommand.php index f8fcb79..a779385 100644 --- a/src/Commands/CallbackqueryCommand.php +++ b/src/Commands/CallbackqueryCommand.php @@ -12,11 +12,19 @@ class CallbackqueryCommand extends SystemCommand try { $callbackQuery = $this->getUpdate()->getCallbackQuery(); $originalSenderId = json_decode($callbackQuery->getData(), true)['sender_id']; - if ($originalSenderId === $callbackQuery->getFrom()?->getId()) { + $callbackSenderId = $callbackQuery->getFrom()?->getId(); + if ($originalSenderId === $callbackSenderId) { return Request::deleteMessage([ - 'chat_id' => $callbackQuery->getMessage()->getChat()->getId(), + 'chat_id' => $callbackQuery->getMessage()->getChat()->getId(), '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) { } diff --git a/src/Commands/GenericmessageCommand.php b/src/Commands/GenericmessageCommand.php index 0a86c76..d3590bc 100755 --- a/src/Commands/GenericmessageCommand.php +++ b/src/Commands/GenericmessageCommand.php @@ -53,7 +53,7 @@ class GenericmessageCommand extends SystemCommand ]; if ($message->getFrom() !== null) { $deleteButton = new InlineKeyboardButton([ - 'text' => '❌ Delete (original sender only)', + 'text' => '❌ Delete', 'callback_data' => json_encode([ 'sender_id' => $message->getFrom()?->getId(), ]),