You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Malio/app/Utils/Telegram/Commands/PingCommand.php

91 lines
2.3 KiB
PHTML

7 years ago
<?php
namespace App\Utils\Telegram\Commands;
use App\Utils\Telegram\TelegramTools;
7 years ago
use Telegram\Bot\Actions;
use Telegram\Bot\Commands\Command;
/**
* Class PingCommand.
*/
class PingCommand extends Command
{
/**
* @var string Command Name
*/
protected $name = 'ping';
/**
* @var string Command Description
*/
protected $description = '[群组/私聊] 获取我或者群组的唯一 ID.';
7 years ago
/**
* {@inheritdoc}
*/
public function handle($arguments)
{
$Update = $this->getUpdate();
$Message = $Update->getMessage();
// 消息会话 ID
$ChatID = $Message->getChat()->getId();
if ($ChatID > 0) {
// 私人会话
// 发送 '输入中' 会话状态
$this->replyWithChatAction(['action' => Actions::TYPING]);
$text = [
'Pong!',
'这个群组的 ID 是 ' . $ChatID . '.',
];
// 回送信息
$this->replyWithMessage(
[
'text' => implode(PHP_EOL, $text),
7 years ago
'parse_mode' => 'Markdown',
]
);
} else {
// 群组
if ($_ENV['enable_delete_user_cmd'] === true) {
TelegramTools::DeleteMessage([
'chatid' => $ChatID,
'messageid' => $Message->getMessageId(),
]);
}
7 years ago
if ($_ENV['telegram_group_quiet'] === true) {
7 years ago
// 群组中不回应
return;
}
// 发送 '输入中' 会话状态
$this->replyWithChatAction(['action' => Actions::TYPING]);
$text = [
'Pong!',
'您的 ID 是 ' . $Message->getFrom()->getId() . '.',
7 years ago
'这个群组的 ID 是 ' . $ChatID . '.',
];
// 回送信息
$response = $this->replyWithMessage(
7 years ago
[
'text' => implode(PHP_EOL, $text),
7 years ago
]
);
// 消息删除任务
TelegramTools::DeleteMessage([
'chatid' => $ChatID,
'messageid' => $response->getMessageId(),
]);
7 years ago
}
}
}