Add delete button for original message sender
This commit is contained in:
25
src/Commands/CallbackqueryCommand.php
Normal file
25
src/Commands/CallbackqueryCommand.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Bot\Command\System;
|
||||
|
||||
use Longman\TelegramBot\Commands\SystemCommand;
|
||||
use Longman\TelegramBot\Entities\ServerResponse;
|
||||
use Longman\TelegramBot\Request;
|
||||
|
||||
class CallbackqueryCommand extends SystemCommand
|
||||
{
|
||||
public function execute(): ServerResponse
|
||||
{
|
||||
try {
|
||||
$callbackQuery = $this->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();
|
||||
}
|
||||
}
|
||||
35
src/Commands/DiagCommand.php
Normal file
35
src/Commands/DiagCommand.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Longman\TelegramBot\Commands\UserCommands;
|
||||
|
||||
use Longman\TelegramBot\Commands\UserCommand;
|
||||
use Longman\TelegramBot\Entities\ServerResponse;
|
||||
|
||||
class DiagCommand extends UserCommand
|
||||
{
|
||||
/** @var string */
|
||||
protected $name = 'diag';
|
||||
|
||||
/** @var string */
|
||||
protected $description = 'Show diagnosis information';
|
||||
|
||||
/** @var string */
|
||||
protected $usage = '/diag';
|
||||
|
||||
/** @var string */
|
||||
protected $version = '1.0.0';
|
||||
|
||||
public function execute(): ServerResponse
|
||||
{
|
||||
$fromId = $this->getMessage()?->getFrom()?->getId() ?? 'null';
|
||||
$chatId = $this->getMessage()?->getChat()?->getId() ?? 'null';
|
||||
return $this->replyToChat(
|
||||
<<<END
|
||||
Your user ID is `$fromId`.
|
||||
This chat ID is `$chatId`.
|
||||
END, [
|
||||
'parse_mode' => 'markdown',
|
||||
'disable_web_page_preview' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user