Shorter Delete button

This commit is contained in:
2023-04-19 19:34:08 +00:00
parent 71302338b8
commit cc302e5431
2 changed files with 11 additions and 3 deletions

View File

@@ -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) {
} }

View File

@@ -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(),
]), ]),