Бот: отправка события печати только при обработке известных команд

This commit is contained in:
2025-06-21 21:13:09 +08:00
parent e42d7d75fe
commit 832be45a7a

View File

@@ -72,7 +72,6 @@ class Bot
*/
public function process(): bool
{
$this->bot->sendChatAction($this->update->getMessage()->getChat()->getId(), 'typing');
$commandText = $this->getBotCommandText();
return match (true) {
str_starts_with($commandText, '/start') => $this->processHelpCommand(),
@@ -90,9 +89,13 @@ class Bot
*
* @return bool
* @throws InvalidArgumentException
* @throws \TelegramBot\Api\Exception
* @throws Exception
*/
protected function processListCommand(): bool
{
$this->bot->sendChatAction($this->update->getMessage()->getChat()->getId(), 'typing');
$playlists = ini()->getPlaylists();
if (empty($playlists)) {
$replyText = 'Плейлистов нет';
@@ -132,9 +135,12 @@ class Bot
*
* @return bool
* @throws InvalidArgumentException
* @throws \TelegramBot\Api\Exception
*/
protected function processInfoCommand(): bool
{
$this->bot->sendChatAction($this->update->getMessage()->getChat()->getId(), 'typing');
$message = $this->update->getMessage();
$text = $message->getText();
$command = $this->getBotCommand();
@@ -225,9 +231,12 @@ class Bot
* Обрабатывает команду /help
*
* @return bool
* @throws \TelegramBot\Api\Exception
*/
protected function processHelpCommand(): bool
{
$this->bot->sendChatAction($this->update->getMessage()->getChat()->getId(), 'typing');
$replyText[] = 'Бот предоставляет короткую сводку о плейлистах, которые видны на сайте ' .
$this->escape(base_url()) . '\.';
$replyText[] = 'Плейлисты проверяются сервером автоматически\.';
@@ -250,9 +259,12 @@ class Bot
* Обрабатывает команду /links
*
* @return bool
* @throws \TelegramBot\Api\Exception
*/
protected function processLinksCommand(): bool
{
$this->bot->sendChatAction($this->update->getMessage()->getChat()->getId(), 'typing');
$replyText[] = '*Ресурсы и страницы*';
$replyText[] = '';
$replyText[] = '🌏 Сайт: ' . $this->escape(base_url());
@@ -275,6 +287,8 @@ class Bot
*/
protected function processStatsCommand(): bool
{
$this->bot->sendChatAction($this->update->getMessage()->getChat()->getId(), 'typing');
$allChannels = [];
foreach (ini()->getPlaylists() as $pls) {
$allChannels = array_merge($allChannels, $pls['channels'] ?? []);