diff --git a/src/Commands/CallbackqueryCommand.php b/src/Commands/CallbackqueryCommand.php new file mode 100644 index 0000000..f8fcb79 --- /dev/null +++ b/src/Commands/CallbackqueryCommand.php @@ -0,0 +1,25 @@ +getUpdate()->getCallbackQuery(); + $originalSenderId = json_decode($callbackQuery->getData(), true)['sender_id']; + if ($originalSenderId === $callbackQuery->getFrom()?->getId()) { + return Request::deleteMessage([ + 'chat_id' => $callbackQuery->getMessage()->getChat()->getId(), + 'message_id' => $callbackQuery->getMessage()->getMessageId(), + ]); + } + } catch (\Exception $e) { + } + return Request::emptyResponse(); + } +} \ No newline at end of file diff --git a/src/Commands/DiagCommand.php b/src/Commands/DiagCommand.php new file mode 100644 index 0000000..54235bb --- /dev/null +++ b/src/Commands/DiagCommand.php @@ -0,0 +1,35 @@ +getMessage()?->getFrom()?->getId() ?? 'null'; + $chatId = $this->getMessage()?->getChat()?->getId() ?? 'null'; + return $this->replyToChat( + << 'markdown', + 'disable_web_page_preview' => true, + ]); + } +} \ No newline at end of file diff --git a/src/Commands/GenericmessageCommand.php b/src/Commands/GenericmessageCommand.php index d784461..0a86c76 100755 --- a/src/Commands/GenericmessageCommand.php +++ b/src/Commands/GenericmessageCommand.php @@ -3,8 +3,11 @@ namespace Longman\TelegramBot\Commands\SystemCommands; use Longman\TelegramBot\Commands\SystemCommand; +use Longman\TelegramBot\Entities\InlineKeyboard; +use Longman\TelegramBot\Entities\InlineKeyboardButton; use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Request; + // This class name is magic class GenericmessageCommand extends SystemCommand { @@ -20,9 +23,9 @@ class GenericmessageCommand extends SystemCommand global $allowed_chat_ids; $message = $this->getMessage(); - $chat_id = $message->getChat()->getId(); - if(count($allowed_chat_ids) > 0 && !in_array($chat_id, $allowed_chat_ids)) { - return $this->replyToChat("Chat ID $chat_id not allowed"); + $chatId = $message->getChat()->getId(); + if(count($allowed_chat_ids) > 0 && !in_array($chatId, $allowed_chat_ids)) { + return $this->replyToChat("Chat ID $chatId not allowed"); } $text = $message->getText(true); @@ -44,12 +47,20 @@ class GenericmessageCommand extends SystemCommand } } - return $this->replyToChat( - "https://fxtwitter.com/$author/status/$tweetId$photoNo", - [ - 'reply_to_message_id' => $message->getMessageId(), - 'disable_notification' => true, - ] - ); + $data = [ + 'reply_to_message_id' => $message->getMessageId(), + 'disable_notification' => true, + ]; + if ($message->getFrom() !== null) { + $deleteButton = new InlineKeyboardButton([ + 'text' => '❌ Delete (original sender only)', + 'callback_data' => json_encode([ + 'sender_id' => $message->getFrom()?->getId(), + ]), + ]); + $data['reply_markup'] = new InlineKeyboard([$deleteButton]); + } + + return $this->replyToChat("https://vxtwitter.com/$author/status/$tweetId$photoNo", $data); } } \ No newline at end of file diff --git a/src/Commands/HelpCommand.php b/src/Commands/HelpCommand.php index 010c0e9..a17bf57 100644 --- a/src/Commands/HelpCommand.php +++ b/src/Commands/HelpCommand.php @@ -19,6 +19,8 @@ class HelpCommand extends UserCommand /** @var string */ protected $version = '1.0.0'; + protected $private_only = true; + public function execute(): ServerResponse { return $this->replyToChat(