Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
63 KB
Referenced Files
None
Subscribers
None
diff --git a/src/Commands/AdminCommands/ChatsCommand.php b/src/Commands/AdminCommands/ChatsCommand.php
index 42c545c..d3d818a 100644
--- a/src/Commands/AdminCommands/ChatsCommand.php
+++ b/src/Commands/AdminCommands/ChatsCommand.php
@@ -1,143 +1,143 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
class ChatsCommand extends AdminCommand
{
/**
* @var string
*/
protected $name = 'chats';
/**
* @var string
*/
protected $description = 'List or search all chats stored by the bot';
/**
* @var string
*/
protected $usage = '/chats, /chats * or /chats <search string>';
/**
* @var string
*/
protected $version = '1.2.0';
/**
* @var bool
*/
protected $need_mysql = true;
/**
* Command execute method
*
* @return ServerResponse
* @throws TelegramException
*/
public function execute(): ServerResponse
{
- $message = $this->getMessage();
+ $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
$chat_id = $message->getChat()->getId();
$text = trim($message->getText(true));
$results = DB::selectChats([
'groups' => true,
'supergroups' => true,
'channels' => true,
'users' => true,
'text' => ($text === '' || $text === '*') ? null : $text //Text to search in user/group name
]);
$user_chats = 0;
$group_chats = 0;
$supergroup_chats = 0;
$channel_chats = 0;
if ($text === '') {
$text_back = '';
} elseif ($text === '*') {
$text_back = 'List of all bot chats:' . PHP_EOL;
} else {
$text_back = 'Chat search results:' . PHP_EOL;
}
if (is_array($results)) {
foreach ($results as $result) {
//Initialize a chat object
$result['id'] = $result['chat_id'];
$chat = new Chat($result);
$whois = $chat->getId();
if ($this->telegram->getCommandObject('whois')) {
// We can't use '-' in command because part of it will become unclickable
$whois = '/whois' . str_replace('-', 'g', $chat->getId());
}
if ($chat->isPrivateChat()) {
if ($text !== '') {
$text_back .= '- P ' . $chat->tryMention() . ' [' . $whois . ']' . PHP_EOL;
}
++$user_chats;
} elseif ($chat->isSuperGroup()) {
if ($text !== '') {
$text_back .= '- S ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
}
++$supergroup_chats;
} elseif ($chat->isGroupChat()) {
if ($text !== '') {
$text_back .= '- G ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
}
++$group_chats;
} elseif ($chat->isChannel()) {
if ($text !== '') {
$text_back .= '- C ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
}
++$channel_chats;
}
}
}
if (($user_chats + $group_chats + $supergroup_chats) === 0) {
$text_back = 'No chats found..';
} else {
$text_back .= PHP_EOL . 'Private Chats: ' . $user_chats;
$text_back .= PHP_EOL . 'Groups: ' . $group_chats;
$text_back .= PHP_EOL . 'Super Groups: ' . $supergroup_chats;
$text_back .= PHP_EOL . 'Channels: ' . $channel_chats;
$text_back .= PHP_EOL . 'Total: ' . ($user_chats + $group_chats + $supergroup_chats);
if ($text === '') {
$text_back .= PHP_EOL . PHP_EOL . 'List all chats: /' . $this->name . ' *' . PHP_EOL . 'Search for chats: /' . $this->name . ' <search string>';
}
}
$data = [
'chat_id' => $chat_id,
'text' => $text_back,
];
return Request::sendMessage($data);
}
}
diff --git a/src/Commands/AdminCommands/CleanupCommand.php b/src/Commands/AdminCommands/CleanupCommand.php
index 5be4975..221ed93 100644
--- a/src/Commands/AdminCommands/CleanupCommand.php
+++ b/src/Commands/AdminCommands/CleanupCommand.php
@@ -1,435 +1,435 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\TelegramLog;
use PDOException;
/**
* User "/cleanup" command
*
* Configuration options:
*
* $telegram->setCommandConfig('cleanup', [
* // Define which tables should be cleaned.
* 'tables_to_clean' => [
* 'message',
* 'edited_message',
* ],
* // Define how old cleaned entries should be.
* 'clean_older_than' => [
* 'message' => '7 days',
* 'edited_message' => '30 days',
* ]
* );
*/
class CleanupCommand extends AdminCommand
{
/**
* @var string
*/
protected $name = 'cleanup';
/**
* @var string
*/
protected $description = 'Clean up the database from old records';
/**
* @var string
*/
protected $usage = '/cleanup [dry] <days> or /cleanup [dry] <count> <unit> (e.g. 3 weeks)';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* @var bool
*/
protected $need_mysql = true;
/**
* Default tables to clean, cleaning 'chat', 'user' and 'user_chat' by default is bad practice!
*
* @var array
*/
protected static $default_tables_to_clean = [
'callback_query',
'chosen_inline_result',
'conversation',
'edited_message',
'inline_query',
'message',
'request_limiter',
'telegram_update',
];
/**
* By default, remove records older than X days/hours/anything from these tables.
*
* @var array
*/
protected static $default_clean_older_than = [
'callback_query' => '30 days',
'chat' => '365 days',
'chosen_inline_result' => '30 days',
'conversation' => '90 days',
'edited_message' => '30 days',
'inline_query' => '30 days',
'message' => '30 days',
'poll' => '90 days',
'request_limiter' => '1 minute',
'shipping_query' => '90 days',
'telegram_update' => '30 days',
'user' => '365 days',
'user_chat' => '365 days',
];
/**
* Set command config
*
* @param string $custom_time
*
* @return array
*/
private function getSettings($custom_time = ''): array
{
$tables_to_clean = self::$default_tables_to_clean;
$user_tables_to_clean = $this->getConfig('tables_to_clean');
if (is_array($user_tables_to_clean)) {
$tables_to_clean = $user_tables_to_clean;
}
$clean_older_than = self::$default_clean_older_than;
$user_clean_older_than = $this->getConfig('clean_older_than');
if (is_array($user_clean_older_than)) {
$clean_older_than = array_merge($clean_older_than, $user_clean_older_than);
}
// Convert numeric-only values to days.
array_walk($clean_older_than, function (&$time) use ($custom_time) {
if (!empty($custom_time)) {
$time = $custom_time;
}
if (is_numeric($time)) {
$time .= ' days';
}
});
return compact('tables_to_clean', 'clean_older_than');
}
/**
* Get SQL queries array based on settings provided
*
* @param $settings
*
* @return array
* @throws TelegramException
*/
private function getQueries($settings): array
{
if (empty($settings) || !is_array($settings)) {
throw new TelegramException('Settings variable is not an array or is empty!');
}
// Convert all clean_older_than times to correct format.
$clean_older_than = $settings['clean_older_than'];
foreach ($clean_older_than as $table => $time) {
$clean_older_than[$table] = date('Y-m-d H:i:s', strtotime('-' . $time));
}
$tables_to_clean = $settings['tables_to_clean'];
$queries = [];
if (in_array('telegram_update', $tables_to_clean, true)) {
$queries[] = sprintf(
'DELETE FROM `%3$s`
WHERE id IN (
SELECT id FROM (
SELECT id FROM `%3$s`
WHERE `id` != \'%1$s\'
AND `chat_id` NOT IN (
SELECT `id`
FROM `%4$s`
WHERE `%3$s`.`chat_id` = `id`
AND `updated_at` < \'%2$s\'
)
AND (
`message_id` IS NOT NULL
AND `message_id` IN (
SELECT `id`
FROM `%5$s`
WHERE `date` < \'%2$s\'
)
)
OR (
`edited_message_id` IS NOT NULL
AND `edited_message_id` IN (
SELECT `id`
FROM `%6$s`
WHERE `edit_date` < \'%2$s\'
)
)
OR (
`inline_query_id` IS NOT NULL
AND `inline_query_id` IN (
SELECT `id`
FROM `%7$s`
WHERE `created_at` < \'%2$s\'
)
)
OR (
`chosen_inline_result_id` IS NOT NULL
AND `chosen_inline_result_id` IN (
SELECT `id`
FROM `%8$s`
WHERE `created_at` < \'%2$s\'
)
)
OR (
`callback_query_id` IS NOT NULL
AND `callback_query_id` IN (
SELECT `id`
FROM `%9$s`
WHERE `created_at` < \'%2$s\'
)
)
) a
)
',
$this->getUpdate()->getUpdateId(),
$clean_older_than['telegram_update'],
TB_TELEGRAM_UPDATE,
TB_CHAT,
TB_MESSAGE,
TB_EDITED_MESSAGE,
TB_INLINE_QUERY,
TB_CHOSEN_INLINE_RESULT,
TB_CALLBACK_QUERY
);
}
if (in_array('user_chat', $tables_to_clean, true)) {
$queries[] = sprintf(
'DELETE FROM `%1$s`
WHERE `user_id` IN (
SELECT `id`
FROM `%2$s`
WHERE `updated_at` < \'%3$s\'
)
',
TB_USER_CHAT,
TB_USER,
$clean_older_than['chat']
);
}
// Simple.
$simple_tables = [
'user' => ['table' => TB_USER, 'field' => 'updated_at'],
'chat' => ['table' => TB_CHAT, 'field' => 'updated_at'],
'conversation' => ['table' => TB_CONVERSATION, 'field' => 'updated_at'],
'poll' => ['table' => TB_POLL, 'field' => 'created_at'],
'request_limiter' => ['table' => TB_REQUEST_LIMITER, 'field' => 'created_at'],
'shipping_query' => ['table' => TB_SHIPPING_QUERY, 'field' => 'created_at'],
];
foreach (array_intersect(array_keys($simple_tables), $tables_to_clean) as $table_to_clean) {
$queries[] = sprintf(
'DELETE FROM `%1$s`
WHERE `%2$s` < \'%3$s\'
',
$simple_tables[$table_to_clean]['table'],
$simple_tables[$table_to_clean]['field'],
$clean_older_than[$table_to_clean]
);
}
// Queries.
$query_tables = [
'inline_query' => ['table' => TB_INLINE_QUERY, 'field' => 'created_at'],
'chosen_inline_result' => ['table' => TB_CHOSEN_INLINE_RESULT, 'field' => 'created_at'],
'callback_query' => ['table' => TB_CALLBACK_QUERY, 'field' => 'created_at'],
];
foreach (array_intersect(array_keys($query_tables), $tables_to_clean) as $table_to_clean) {
$queries[] = sprintf(
'DELETE FROM `%1$s`
WHERE `%2$s` < \'%3$s\'
AND `id` NOT IN (
SELECT `%4$s`
FROM `%5$s`
WHERE `%4$s` = `%1$s`.`id`
)
',
$query_tables[$table_to_clean]['table'],
$query_tables[$table_to_clean]['field'],
$clean_older_than[$table_to_clean],
$table_to_clean . '_id',
TB_TELEGRAM_UPDATE
);
}
// Messages
if (in_array('edited_message', $tables_to_clean, true)) {
$queries[] = sprintf(
'DELETE FROM `%1$s`
WHERE `edit_date` < \'%2$s\'
AND `id` NOT IN (
SELECT `message_id`
FROM `%3$s`
WHERE `edited_message_id` = `%1$s`.`id`
)
',
TB_EDITED_MESSAGE,
$clean_older_than['edited_message'],
TB_TELEGRAM_UPDATE
);
}
if (in_array('message', $tables_to_clean, true)) {
$queries[] = sprintf(
'DELETE FROM `%1$s`
WHERE id IN (
SELECT id
FROM (
SELECT id
FROM `%1$s`
WHERE `date` < \'%2$s\'
AND `id` NOT IN (
SELECT `message_id`
FROM `%3$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT `message_id`
FROM `%4$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT `message_id`
FROM `%5$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT a.`reply_to_message` FROM `%1$s` a
INNER JOIN `%1$s` b ON b.`id` = a.`reply_to_message` AND b.`chat_id` = a.`reply_to_chat`
)
ORDER BY `id` DESC
) a
)
',
TB_MESSAGE,
$clean_older_than['message'],
TB_EDITED_MESSAGE,
TB_TELEGRAM_UPDATE,
TB_CALLBACK_QUERY
);
}
return $queries;
}
/**
* Execution if MySQL is required but not available
*
* @return ServerResponse
* @throws TelegramException
*/
public function executeNoDb(): ServerResponse
{
return $this->replyToChat('*No database connection!*', ['parse_mode' => 'Markdown']);
}
/**
* Command execute method
*
* @return ServerResponse
* @throws TelegramException
*/
public function execute(): ServerResponse
{
- $message = $this->getMessage();
+ $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
$text = $message->getText(true);
// Dry run?
$dry_run = strpos($text, 'dry') !== false;
$text = trim(str_replace('dry', '', $text));
$settings = $this->getSettings($text);
$queries = $this->getQueries($settings);
if ($dry_run) {
return $this->replyToUser('Queries:' . PHP_EOL . implode(PHP_EOL, $queries));
}
$infos = [];
foreach ($settings['tables_to_clean'] as $table) {
$info = "*{$table}*";
if (isset($settings['clean_older_than'][$table])) {
$info .= " ({$settings['clean_older_than'][$table]})";
}
$infos[] = $info;
}
$data = [
'chat_id' => $message->getFrom()->getId(),
'parse_mode' => 'Markdown',
];
$data['text'] = 'Cleaning up tables:' . PHP_EOL . implode(PHP_EOL, $infos);
Request::sendMessage($data);
$rows = 0;
$pdo = DB::getPdo();
try {
$pdo->beginTransaction();
foreach ($queries as $query) {
// Delete in chunks to not block / improve speed on big tables.
$query .= ' LIMIT 10000';
while ($dbq = $pdo->query($query)) {
if ($dbq->rowCount() === 0) {
continue 2;
}
$rows += $dbq->rowCount();
}
TelegramLog::error('Error while executing query: ' . $query);
}
// commit changes to the database and end transaction
$pdo->commit();
$data['text'] = "*Database cleanup done!* _(removed {$rows} rows)_";
} catch (PDOException $e) {
$data['text'] = '*Database cleanup failed!* _(check your error logs)_';
// rollback changes on exception
// useful if you want to track down error you can't replicate it when some of the data is already deleted
$pdo->rollBack();
TelegramLog::error($e->getMessage());
}
return Request::sendMessage($data);
}
}
diff --git a/src/Commands/AdminCommands/DebugCommand.php b/src/Commands/AdminCommands/DebugCommand.php
index 7c358b1..8a2fe80 100644
--- a/src/Commands/AdminCommands/DebugCommand.php
+++ b/src/Commands/AdminCommands/DebugCommand.php
@@ -1,127 +1,127 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\AdminCommands;
use Exception;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
/**
* Admin "/debug" command
*/
class DebugCommand extends AdminCommand
{
/**
* @var string
*/
protected $name = 'debug';
/**
* @var string
*/
protected $description = 'Debug command to help find issues';
/**
* @var string
*/
protected $usage = '/debug';
/**
* @var string
*/
protected $version = '1.1.0';
/**
* Command execute method
*
* @return mixed
* @throws TelegramException
*/
public function execute(): ServerResponse
{
$pdo = DB::getPdo();
- $message = $this->getMessage();
+ $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
$chat = $message->getChat();
$text = strtolower($message->getText(true));
$data = ['chat_id' => $chat->getId()];
if ($text !== 'glasnost' && !$chat->isPrivateChat()) {
$data['text'] = 'Only available in a private chat.';
return Request::sendMessage($data);
}
$debug_info = [];
$debug_info[] = sprintf('*TelegramBot version:* `%s`', $this->telegram->getVersion());
$debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath() ?: '`_Not set_`');
$debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath() ?: '`_Not set_`');
// Commands paths.
$debug_info[] = '*Commands paths:*';
$debug_info[] = sprintf(
'```' . PHP_EOL . '%s```',
json_encode($this->telegram->getCommandsPaths(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
$php_bit = '';
PHP_INT_SIZE === 4 && $php_bit = ' (32bit)';
PHP_INT_SIZE === 8 && $php_bit = ' (64bit)';
$debug_info[] = sprintf('*PHP version:* `%1$s%2$s; %3$s; %4$s`', PHP_VERSION, $php_bit, PHP_SAPI, PHP_OS);
$debug_info[] = sprintf('*Maximum PHP script execution time:* `%d seconds`', ini_get('max_execution_time'));
$mysql_version = $pdo ? $pdo->query('SELECT VERSION() AS version')->fetchColumn() : null;
$debug_info[] = sprintf('*MySQL version:* `%s`', $mysql_version ?: 'disabled');
$debug_info[] = sprintf('*Operating System:* `%s`', php_uname());
if (isset($_SERVER['SERVER_SOFTWARE'])) {
$debug_info[] = sprintf('*Web Server:* `%s`', $_SERVER['SERVER_SOFTWARE']);
}
if (function_exists('curl_init')) {
$curlversion = curl_version();
$debug_info[] = sprintf('*curl version:* `%1$s; %2$s`', $curlversion['version'], $curlversion['ssl_version']);
}
$webhook_info_title = '*Webhook Info:*';
try {
// Check if we're actually using the Webhook method.
if (Request::getInput() === '') {
$debug_info[] = $webhook_info_title . ' `Using getUpdates method, not Webhook.`';
} else {
$webhook_info_result = json_decode(Request::getWebhookInfo(), true)['result'];
// Add a human-readable error date string if necessary.
if (isset($webhook_info_result['last_error_date'])) {
$webhook_info_result['last_error_date_string'] = date('Y-m-d H:i:s', $webhook_info_result['last_error_date']);
}
$webhook_info_result_str = json_encode($webhook_info_result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$debug_info[] = $webhook_info_title;
$debug_info[] = sprintf(
'```' . PHP_EOL . '%s```',
$webhook_info_result_str
);
}
} catch (Exception $e) {
$debug_info[] = $webhook_info_title . sprintf(' `Failed to get webhook info! (%s)`', $e->getMessage());
}
$data['parse_mode'] = 'Markdown';
$data['text'] = implode(PHP_EOL, $debug_info);
return Request::sendMessage($data);
}
}
diff --git a/src/Commands/AdminCommands/SendtochannelCommand.php b/src/Commands/AdminCommands/SendtochannelCommand.php
index f547046..12fb828 100644
--- a/src/Commands/AdminCommands/SendtochannelCommand.php
+++ b/src/Commands/AdminCommands/SendtochannelCommand.php
@@ -1,379 +1,379 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\Entity;
use Longman\TelegramBot\Entities\Keyboard;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
class SendtochannelCommand extends AdminCommand
{
/**
* @var string
*/
protected $name = 'sendtochannel';
/**
* @var string
*/
protected $description = 'Send message to a channel';
/**
* @var string
*/
protected $usage = '/sendtochannel <message to send>';
/**
* @var string
*/
protected $version = '0.3.0';
/**
* @var bool
*/
protected $need_mysql = true;
/**
* Conversation Object
*
* @var Conversation
*/
protected $conversation;
/**
* Command execute method
*
* @return ServerResponse|mixed
* @throws TelegramException
*/
public function execute(): ServerResponse
{
- $message = $this->getMessage();
+ $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$type = $message->getType();
// 'Cast' the command type to message to protect the machine state
// if the command is recalled when the conversation is already started
in_array($type, ['command', 'text'], true) && $type = 'message';
$text = trim($message->getText(true));
$text_yes_or_no = ($text === 'Yes' || $text === 'No');
$data = [
'chat_id' => $chat_id,
];
// Conversation
$this->conversation = new Conversation($user_id, $chat_id, $this->getName());
$notes = &$this->conversation->notes;
!is_array($notes) && $notes = [];
$channels = (array) $this->getConfig('your_channel');
if (isset($notes['state'])) {
$state = $notes['state'];
} else {
$state = (count($channels) === 0) ? -1 : 0;
$notes['last_message_id'] = $message->getMessageId();
}
$yes_no_keyboard = new Keyboard(
[
'keyboard' => [['Yes', 'No']],
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true,
]
);
switch ($state) {
case -1:
// getConfig has not been configured asking for channel to administer
if ($type !== 'message' || $text === '') {
$notes['state'] = -1;
$this->conversation->update();
$result = $this->replyToChat(
'Insert the channel name or ID (_@yourchannel_ or _-12345_)',
[
'parse_mode' => 'markdown',
'reply_markup' => Keyboard::remove(['selective' => true]),
]
);
break;
}
$notes['channel'] = $text;
$notes['last_message_id'] = $message->getMessageId();
// Jump to state 1
goto insert;
// no break
default:
case 0:
// getConfig has been configured choose channel
if ($type !== 'message' || $text === '') {
$notes['state'] = 0;
$this->conversation->update();
$keyboard = array_map(function ($channel) {
return [$channel];
}, $channels);
$result = $this->replyToChat(
'Choose a channel from the keyboard' . PHP_EOL .
'_or_ insert the channel name or ID (_@yourchannel_ or _-12345_)',
[
'parse_mode' => 'markdown',
'reply_markup' => new Keyboard(
[
'keyboard' => $keyboard,
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true,
]
),
]
);
break;
}
$notes['channel'] = $text;
$notes['last_message_id'] = $message->getMessageId();
// no break
case 1:
insert:
if (($type === 'message' && $text === '') || $notes['last_message_id'] === $message->getMessageId()) {
$notes['state'] = 1;
$this->conversation->update();
$result = $this->replyToChat(
'Insert the content you want to share: text, photo, audio...',
['reply_markup' => Keyboard::remove(['selective' => true])]
);
break;
}
$notes['last_message_id'] = $message->getMessageId();
$notes['message'] = $message->getRawData();
$notes['message_type'] = $type;
// no break
case 2:
if (!$text_yes_or_no || $notes['last_message_id'] === $message->getMessageId()) {
$notes['state'] = 2;
$this->conversation->update();
// Grab any existing caption.
if ($caption = $message->getCaption()) {
$notes['caption'] = $caption;
$text = 'No';
} elseif (in_array($notes['message_type'], ['video', 'photo'], true)) {
$text = 'Would you like to insert a caption?';
if (!$text_yes_or_no && $notes['last_message_id'] !== $message->getMessageId()) {
$text .= PHP_EOL . 'Type Yes or No';
}
$result = $this->replyToChat(
$text,
['reply_markup' => $yes_no_keyboard]
);
break;
}
}
$notes['set_caption'] = ($text === 'Yes');
$notes['last_message_id'] = $message->getMessageId();
// no break
case 3:
if ($notes['set_caption'] && ($notes['last_message_id'] === $message->getMessageId() || $type !== 'message')) {
$notes['state'] = 3;
$this->conversation->update();
$result = $this->replyToChat(
'Insert caption:',
['reply_markup' => Keyboard::remove(['selective' => true])]
);
break;
}
$notes['last_message_id'] = $message->getMessageId();
if (isset($notes['caption'])) {
// If caption has already been send with the file, no need to ask for it.
$notes['set_caption'] = true;
} else {
$notes['caption'] = $text;
}
// no break
case 4:
if (!$text_yes_or_no || $notes['last_message_id'] === $message->getMessageId()) {
$notes['state'] = 4;
$this->conversation->update();
$result = $this->replyToChat('Message will look like this:');
if ($notes['message_type'] !== 'command') {
if ($notes['set_caption']) {
$data['caption'] = $notes['caption'];
}
$this->sendBack(new Message($notes['message'], $this->telegram->getBotUsername()), $data);
$data['reply_markup'] = $yes_no_keyboard;
$data['text'] = 'Would you like to post it?';
if (!$text_yes_or_no && $notes['last_message_id'] !== $message->getMessageId()) {
$data['text'] .= PHP_EOL . 'Type Yes or No';
}
$result = Request::sendMessage($data);
}
break;
}
$notes['post_message'] = ($text === 'Yes');
$notes['last_message_id'] = $message->getMessageId();
// no break
case 5:
$data['reply_markup'] = Keyboard::remove(['selective' => true]);
if ($notes['post_message']) {
$data['parse_mode'] = 'markdown';
$data['text'] = $this->publish(
new Message($notes['message'], $this->telegram->getBotUsername()),
$notes['channel'],
$notes['caption']
);
} else {
$data['text'] = 'Aborted by user, message not sent..';
}
$this->conversation->stop();
$result = Request::sendMessage($data);
}
return $result;
}
/**
* SendBack
*
* Received a message, the bot can send a copy of it to another chat/channel.
* You don't have to care about the type of the message, the function detect it and use the proper
* REQUEST:: function to send it.
* $data include all the var that you need to send the message to the proper chat
*
* @todo This method will be moved to a higher level maybe in AdminCommand or Command
* @todo Looking for a more significant name
*
* @param Message $message
* @param array $data
*
* @return ServerResponse
* @throws TelegramException
*/
protected function sendBack(Message $message, array $data): ServerResponse
{
$type = $message->getType();
in_array($type, ['command', 'text'], true) && $type = 'message';
if ($type === 'message') {
$data['text'] = $message->getText(true);
} elseif ($type === 'audio') {
$data['audio'] = $message->getAudio()->getFileId();
$data['duration'] = $message->getAudio()->getDuration();
$data['performer'] = $message->getAudio()->getPerformer();
$data['title'] = $message->getAudio()->getTitle();
} elseif ($type === 'document') {
$data['document'] = $message->getDocument()->getFileId();
} elseif ($type === 'photo') {
$data['photo'] = $message->getPhoto()[0]->getFileId();
} elseif ($type === 'sticker') {
$data['sticker'] = $message->getSticker()->getFileId();
} elseif ($type === 'video') {
$data['video'] = $message->getVideo()->getFileId();
} elseif ($type === 'voice') {
$data['voice'] = $message->getVoice()->getFileId();
} elseif ($type === 'location') {
$data['latitude'] = $message->getLocation()->getLatitude();
$data['longitude'] = $message->getLocation()->getLongitude();
}
return Request::send('send' . ucfirst($type), $data);
}
/**
* Publish a message to a channel and return success or failure message in markdown format
*
* @param Message $message
* @param string|int $channel_id
* @param string|null $caption
*
* @return string
* @throws TelegramException
*/
protected function publish(Message $message, $channel_id, $caption = null): string
{
$res = $this->sendBack($message, [
'chat_id' => $channel_id,
'caption' => $caption,
]);
if ($res->isOk()) {
/** @var Chat $channel */
$channel = $res->getResult()->getChat();
$escaped_username = $channel->getUsername() ? Entity::escapeMarkdown($channel->getUsername()) : '';
$response = sprintf(
'Message successfully sent to *%s*%s',
filter_var($channel->getTitle(), FILTER_SANITIZE_SPECIAL_CHARS),
$escaped_username ? " (@{$escaped_username})" : ''
);
} else {
$escaped_username = Entity::escapeMarkdown($channel_id);
$response = "Message not sent to *{$escaped_username}*" . PHP_EOL .
'- Does the channel exist?' . PHP_EOL .
'- Is the bot an admin of the channel?';
}
return $response;
}
/**
* Execute without db
*
* @todo Why send just to the first found channel?
*
* @return mixed
* @throws TelegramException
*/
public function executeNoDb(): ServerResponse
{
- $message = $this->getMessage();
+ $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
$text = trim($message->getText(true));
if ($text === '') {
return $this->replyToChat('Usage: ' . $this->getUsage());
}
$channels = array_filter((array) $this->getConfig('your_channel'));
if (empty($channels)) {
return $this->replyToChat('No channels defined in the command config!');
}
return $this->replyToChat($this->publish(
new Message($message->getRawData(), $this->telegram->getBotUsername()),
reset($channels)
), ['parse_mode' => 'markdown']);
}
}
diff --git a/src/Commands/AdminCommands/WhoisCommand.php b/src/Commands/AdminCommands/WhoisCommand.php
index cb47d88..033dbc8 100644
--- a/src/Commands/AdminCommands/WhoisCommand.php
+++ b/src/Commands/AdminCommands/WhoisCommand.php
@@ -1,190 +1,190 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Written by Jack'lul <jacklul@jacklul.com>
*/
namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\PhotoSize;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Entities\UserProfilePhotos;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
/**
* Admin "/whois" command
*/
class WhoisCommand extends AdminCommand
{
/**
* @var string
*/
protected $name = 'whois';
/**
* @var string
*/
protected $description = 'Lookup user or group info';
/**
* @var string
*/
protected $usage = '/whois <id> or /whois <search string>';
/**
* @var string
*/
protected $version = '1.3.0';
/**
* @var bool
*/
protected $need_mysql = true;
/**
* Command execute method
*
* @return ServerResponse
* @throws TelegramException
*/
public function execute(): ServerResponse
{
- $message = $this->getMessage();
+ $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
$chat_id = $message->getChat()->getId();
$command = $message->getCommand();
$text = trim($message->getText(true));
$data = ['chat_id' => $chat_id];
//No point in replying to messages in private chats
if (!$message->getChat()->isPrivateChat()) {
$data['reply_to_message_id'] = $message->getMessageId();
}
if ($command !== 'whois') {
$text = substr($command, 5);
//We need that '-' now, bring it back
if (strpos($text, 'g') === 0) {
$text = str_replace('g', '-', $text);
}
}
if ($text === '') {
$text = 'Provide the id to lookup: /whois <id>';
} else {
$user_id = $text;
$chat = null;
$created_at = null;
$updated_at = null;
$result = null;
if (is_numeric($text)) {
$results = DB::selectChats([
'groups' => true,
'supergroups' => true,
'channels' => true,
'users' => true,
'chat_id' => $user_id, //Specific chat_id to select
]);
if (!empty($results)) {
$result = reset($results);
}
} else {
$results = DB::selectChats([
'groups' => true,
'supergroups' => true,
'channels' => true,
'users' => true,
'text' => $text //Text to search in user/group name
]);
if (is_array($results) && count($results) === 1) {
$result = reset($results);
}
}
if (is_array($result)) {
$result['id'] = $result['chat_id'];
$result['username'] = $result['chat_username'];
$chat = new Chat($result);
$user_id = $result['id'];
$created_at = $result['chat_created_at'];
$updated_at = $result['chat_updated_at'];
$old_id = $result['old_id'];
}
if ($chat !== null) {
if ($chat->isPrivateChat()) {
$text = 'User ID: ' . $user_id . PHP_EOL;
$text .= 'Name: ' . $chat->getFirstName() . ' ' . $chat->getLastName() . PHP_EOL;
$username = $chat->getUsername();
if ($username !== null && $username !== '') {
$text .= 'Username: @' . $username . PHP_EOL;
}
$text .= 'First time seen: ' . $created_at . PHP_EOL;
$text .= 'Last activity: ' . $updated_at . PHP_EOL;
//Code from Whoami command
$limit = 10;
$offset = null;
$response = Request::getUserProfilePhotos(
[
'user_id' => $user_id,
'limit' => $limit,
'offset' => $offset,
]
);
if ($response->isOk()) {
/** @var UserProfilePhotos $user_profile_photos */
$user_profile_photos = $response->getResult();
if ($user_profile_photos->getTotalCount() > 0) {
$photos = $user_profile_photos->getPhotos();
/** @var PhotoSize $photo */
$photo = $photos[0][2];
$file_id = $photo->getFileId();
$data['photo'] = $file_id;
$data['caption'] = $text;
return Request::sendPhoto($data);
}
}
} elseif ($chat->isGroupChat()) {
$text = 'Chat ID: ' . $user_id . (!empty($old_id) ? ' (previously: ' . $old_id . ')' : '') . PHP_EOL;
$text .= 'Type: ' . ucfirst($chat->getType()) . PHP_EOL;
$text .= 'Title: ' . $chat->getTitle() . PHP_EOL;
$text .= 'First time added to group: ' . $created_at . PHP_EOL;
$text .= 'Last activity: ' . $updated_at . PHP_EOL;
}
} elseif (is_array($results) && count($results) > 1) {
$text = 'Multiple chats matched!';
} else {
$text = 'Chat not found!';
}
}
$data['text'] = $text;
return Request::sendMessage($data);
}
}
diff --git a/src/Commands/Command.php b/src/Commands/Command.php
index 2357796..f13905a 100644
--- a/src/Commands/Command.php
+++ b/src/Commands/Command.php
@@ -1,450 +1,450 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\CallbackQuery;
use Longman\TelegramBot\Entities\ChatJoinRequest;
use Longman\TelegramBot\Entities\ChatMemberUpdated;
use Longman\TelegramBot\Entities\ChosenInlineResult;
use Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery;
use Longman\TelegramBot\Entities\Payments\ShippingQuery;
use Longman\TelegramBot\Entities\Poll;
use Longman\TelegramBot\Entities\PollAnswer;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Telegram;
/**
* Class Command
*
* Base class for commands. It includes some helper methods that can fetch data directly from the Update object.
*
* @method Message getMessage() Optional. New incoming message of any kind — text, photo, sticker, etc.
* @method Message getEditedMessage() Optional. New version of a message that is known to the bot and was edited
* @method Message getChannelPost() Optional. New post in the channel, can be any kind — text, photo, sticker, etc.
* @method Message getEditedChannelPost() Optional. New version of a post in the channel that is known to the bot and was edited
* @method InlineQuery getInlineQuery() Optional. New incoming inline query
* @method ChosenInlineResult getChosenInlineResult() Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
* @method CallbackQuery getCallbackQuery() Optional. New incoming callback query
* @method ShippingQuery getShippingQuery() Optional. New incoming shipping query. Only for invoices with flexible price
* @method PreCheckoutQuery getPreCheckoutQuery() Optional. New incoming pre-checkout query. Contains full information about checkout
* @method Poll getPoll() Optional. New poll state. Bots receive only updates about polls, which are sent or stopped by the bot
* @method PollAnswer getPollAnswer() Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.
* @method ChatMemberUpdated getMyChatMember() Optional. The bot's chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.
* @method ChatMemberUpdated getChatMember() Optional. A chat member's status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of allowed_updates to receive these updates.
* @method ChatJoinRequest getChatJoinRequest() Optional. A request to join the chat has been sent. The bot must have the can_invite_users administrator right in the chat to receive these updates.
*/
abstract class Command
{
/**
* Auth level for user commands
*/
public const AUTH_USER = 'User';
/**
* Auth level for system commands
*/
public const AUTH_SYSTEM = 'System';
/**
* Auth level for admin commands
*/
public const AUTH_ADMIN = 'Admin';
/**
* Telegram object
*
* @var Telegram
*/
protected $telegram;
/**
* Update object
*
* @var Update
*/
protected $update;
/**
* Name
*
* @var string
*/
protected $name = '';
/**
* Description
*
* @var string
*/
protected $description = 'Command description';
/**
* Usage
*
* @var string
*/
protected $usage = 'Command usage';
/**
* Show in Help
*
* @var bool
*/
protected $show_in_help = true;
/**
* Version
*
* @var string
*/
protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var bool
*/
protected $enabled = true;
/**
* If this command needs mysql
*
* @var bool
*/
protected $need_mysql = false;
/**
* Make sure this command only executes on a private chat.
*
* @var bool
*/
protected $private_only = false;
/**
* Command config
*
* @var array
*/
protected $config = [];
/**
* Constructor
*
* @param Telegram $telegram
* @param Update|null $update
*/
public function __construct(Telegram $telegram, ?Update $update = null)
{
$this->telegram = $telegram;
if ($update !== null) {
$this->setUpdate($update);
}
$this->config = $telegram->getCommandConfig($this->name);
}
/**
* Set update object
*
* @param Update $update
*
* @return Command
*/
public function setUpdate(Update $update): Command
{
$this->update = $update;
return $this;
}
/**
* Pre-execute command
*
* @return ServerResponse
* @throws TelegramException
*/
public function preExecute(): ServerResponse
{
if ($this->need_mysql && !($this->telegram->isDbEnabled() && DB::isDbConnected())) {
return $this->executeNoDb();
}
if ($this->isPrivateOnly() && $this->removeNonPrivateMessage()) {
- $message = $this->getMessage();
+ $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
if ($user = $message->getFrom()) {
return Request::sendMessage([
'chat_id' => $user->getId(),
'parse_mode' => 'Markdown',
'text' => sprintf(
"/%s command is only available in a private chat.\n(`%s`)",
$this->getName(),
$message->getText()
),
]);
}
return Request::emptyResponse();
}
return $this->execute();
}
/**
* Execute command
*
* @return ServerResponse
* @throws TelegramException
*/
abstract public function execute(): ServerResponse;
/**
* Execution if MySQL is required but not available
*
* @return ServerResponse
* @throws TelegramException
*/
public function executeNoDb(): ServerResponse
{
return $this->replyToChat('Sorry no database connection, unable to execute "' . $this->name . '" command.');
}
/**
* Get update object
*
* @return Update|null
*/
public function getUpdate(): ?Update
{
return $this->update;
}
/**
* Relay any non-existing function calls to Update object.
*
* This is purely a helper method to make requests from within execute() method easier.
*
* @param string $name
* @param array $arguments
*
* @return Command
*/
public function __call(string $name, array $arguments)
{
if ($this->update === null) {
return null;
}
return call_user_func_array([$this->update, $name], $arguments);
}
/**
* Get command config
*
* Look for config $name if found return it, if not return $default.
* If $name is not set return all set config.
*
* @param string|null $name
* @param mixed $default
*
* @return mixed
*/
public function getConfig(?string $name = null, $default = null)
{
if ($name === null) {
return $this->config;
}
return $this->config[$name] ?? $default;
}
/**
* Get telegram object
*
* @return Telegram
*/
public function getTelegram(): Telegram
{
return $this->telegram;
}
/**
* Get usage
*
* @return string
*/
public function getUsage(): string
{
return $this->usage;
}
/**
* Get version
*
* @return string
*/
public function getVersion(): string
{
return $this->version;
}
/**
* Get description
*
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
/**
* Get name
*
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* Get Show in Help
*
* @return bool
*/
public function showInHelp(): bool
{
return $this->show_in_help;
}
/**
* Check if command is enabled
*
* @return bool
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* If this command is intended for private chats only.
*
* @return bool
*/
public function isPrivateOnly(): bool
{
return $this->private_only;
}
/**
* If this is a SystemCommand
*
* @return bool
*/
public function isSystemCommand(): bool
{
return ($this instanceof SystemCommand);
}
/**
* If this is an AdminCommand
*
* @return bool
*/
public function isAdminCommand(): bool
{
return ($this instanceof AdminCommand);
}
/**
* If this is a UserCommand
*
* @return bool
*/
public function isUserCommand(): bool
{
return ($this instanceof UserCommand);
}
/**
* Delete the current message if it has been called in a non-private chat.
*
* @return bool
*/
protected function removeNonPrivateMessage(): bool
{
$message = $this->getMessage() ?: $this->getEditedMessage();
if ($message) {
$chat = $message->getChat();
if (!$chat->isPrivateChat()) {
// Delete the falsely called command message.
Request::deleteMessage([
'chat_id' => $chat->getId(),
'message_id' => $message->getMessageId(),
]);
return true;
}
}
return false;
}
/**
* Helper to reply to a chat directly.
*
* @param string $text
* @param array $data
*
* @return ServerResponse
* @throws TelegramException
*/
public function replyToChat(string $text, array $data = []): ServerResponse
{
if ($message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost()) {
return Request::sendMessage(array_merge([
'chat_id' => $message->getChat()->getId(),
'text' => $text,
], $data));
}
return Request::emptyResponse();
}
/**
* Helper to reply to a user directly.
*
* @param string $text
* @param array $data
*
* @return ServerResponse
* @throws TelegramException
*/
public function replyToUser(string $text, array $data = []): ServerResponse
{
if ($message = $this->getMessage() ?: $this->getEditedMessage()) {
return Request::sendMessage(array_merge([
'chat_id' => $message->getFrom()->getId(),
'text' => $text,
], $data));
}
return Request::emptyResponse();
}
}
diff --git a/src/Commands/SystemCommand.php b/src/Commands/SystemCommand.php
index d4b236a..8bdebf9 100644
--- a/src/Commands/SystemCommand.php
+++ b/src/Commands/SystemCommand.php
@@ -1,124 +1,124 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
abstract class SystemCommand extends Command
{
/**
* @var bool Try to execute any deprecated system command.
*/
public static $execute_deprecated = false;
/**
* @{inheritdoc}
*
* Set to empty string to disallow users calling system commands.
*/
protected $usage = '';
/**
* A system command just executes
*
* Although system commands should just work and return a successful ServerResponse,
* each system command can override this method to add custom functionality.
*
* @return ServerResponse
*/
public function execute(): ServerResponse
{
// System command, return empty ServerResponse by default
return Request::emptyResponse();
}
/**
* Method to execute any active conversation.
*
* @return ServerResponse|null
* @throws TelegramException
* @internal
*/
protected function executeActiveConversation(): ?ServerResponse
{
- $message = $this->getMessage();
+ $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
if ($message === null) {
return null;
}
$user = $message->getFrom();
$chat = $message->getChat();
if ($user === null || $chat === null) {
return null;
}
// If a conversation is busy, execute the conversation command after handling the message.
$conversation = new Conversation($user->getId(), $chat->getId());
// Fetch conversation command if it exists and execute it.
if ($conversation->exists() && ($command = $conversation->getCommand())) {
return $this->getTelegram()->executeCommand($command);
}
return null;
}
/**
* BC helper method to execute deprecated system commands.
*
* @return ServerResponse|null
* @throws TelegramException
* @internal
*/
protected function executeDeprecatedSystemCommand(): ?ServerResponse
{
- $message = $this->getMessage();
+ $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
if ($message === null) {
return null;
}
// List of service messages previously handled internally.
$service_message_getters = [
'newchatmembers' => 'getNewChatMembers',
'leftchatmember' => 'getLeftChatMember',
'newchattitle' => 'getNewChatTitle',
'newchatphoto' => 'getNewChatPhoto',
'deletechatphoto' => 'getDeleteChatPhoto',
'groupchatcreated' => 'getGroupChatCreated',
'supergroupchatcreated' => 'getSupergroupChatCreated',
'channelchatcreated' => 'getChannelChatCreated',
'migratefromchatid' => 'getMigrateFromChatId',
'migratetochatid' => 'getMigrateToChatId',
'pinnedmessage' => 'getPinnedMessage',
'successfulpayment' => 'getSuccessfulPayment',
];
foreach ($service_message_getters as $command => $service_message_getter) {
// Let's check if this message is a service message.
if ($message->$service_message_getter() === null) {
continue;
}
// Make sure the command exists otherwise GenericCommand would be executed.
if ($this->getTelegram()->getCommandObject($command) === null) {
break;
}
return $this->getTelegram()->executeCommand($command);
}
return null;
}
}
diff --git a/src/Commands/UserCommands/StartCommand.php b/src/Commands/UserCommands/StartCommand.php
index 7025bdc..3f3d4b8 100644
--- a/src/Commands/UserCommands/StartCommand.php
+++ b/src/Commands/UserCommands/StartCommand.php
@@ -1,56 +1,56 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Request;
/**
* Start command
*/
class StartCommand extends UserCommand
{
/**
* @var string
*/
protected $name = 'start';
/**
* @var string
*/
protected $description = 'Start command';
/**
* @var string
*/
protected $usage = '/start';
/**
* @var string
*/
protected $version = '1.2.0';
/**
* Command execute method
*
* @return ServerResponse
*/
public function execute(): ServerResponse
{
- //$message = $this->getMessage();
+ //$message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
//$chat_id = $message->getChat()->getId();
//$user_id = $message->getFrom()->getId();
return Request::emptyResponse();
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Nov 15, 5:05 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
150571
Default Alt Text
(63 KB)

Event Timeline