Fix and improve Admin commands.

parent 68874bb7
......@@ -35,7 +35,7 @@ class ChatsCommand extends AdminCommand
/**
* @var string
*/
protected $version = '1.0.2';
protected $version = '1.1.0';
/**
* @var bool
......@@ -46,6 +46,7 @@ class ChatsCommand extends AdminCommand
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
......@@ -61,7 +62,7 @@ class ChatsCommand extends AdminCommand
null, //'yyyy-mm-dd hh:mm:ss' date range from
null, //'yyyy-mm-dd hh:mm:ss' date range to
null, //Specific chat_id to select
($text === '' || $text == '*') ? null : $text //Text to search in user/group name
($text === '' || $text === '*') ? null : $text //Text to search in user/group name
);
$user_chats = 0;
......@@ -70,54 +71,56 @@ class ChatsCommand extends AdminCommand
if ($text === '') {
$text_back = '';
} elseif ($text == '*') {
$text_back = 'List of all bot chats:' . "\n";
} elseif ($text === '*') {
$text_back = 'List of all bot chats:' . PHP_EOL;
} else {
$text_back = 'Chat search results:' . "\n";
$text_back = 'Chat search results:' . PHP_EOL;
}
foreach ($results as $result) {
//Initialize a chat object
$result['id'] = $result['chat_id'];
$chat = new Chat($result);
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 . ']' . "\n";
$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());
}
++$user_chats;
} elseif ($chat->isSuperGroup()) {
if ($text != '') {
$text_back .= '- S ' . $chat->getTitle() . ' [' . $whois . ']' . "\n";
}
if ($chat->isPrivateChat()) {
if ($text !== '') {
$text_back .= '- P ' . $chat->tryMention() . ' [' . $whois . ']' . PHP_EOL;
}
++$super_group_chats;
} elseif ($chat->isGroupChat()) {
if ($text != '') {
$text_back .= '- G ' . $chat->getTitle() . ' [' . $whois . ']' . "\n";
}
++$user_chats;
} elseif ($chat->isSuperGroup()) {
if ($text !== '') {
$text_back .= '- S ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
}
++$super_group_chats;
} elseif ($chat->isGroupChat()) {
if ($text !== '') {
$text_back .= '- G ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
}
++$group_chats;
++$group_chats;
}
}
}
if (($user_chats + $group_chats + $super_group_chats) === 0) {
$text_back = 'No chats found..';
} else {
$text_back .= "\n" . 'Private Chats: ' . $user_chats;
$text_back .= "\n" . 'Group: ' . $group_chats;
$text_back .= "\n" . 'Super Group: ' . $super_group_chats;
$text_back .= "\n" . 'Total: ' . ($user_chats + $group_chats + $super_group_chats);
$text_back .= PHP_EOL . 'Private Chats: ' . $user_chats;
$text_back .= PHP_EOL . 'Groups: ' . $group_chats;
$text_back .= PHP_EOL . 'Super Groups: ' . $super_group_chats;
$text_back .= PHP_EOL . 'Total: ' . ($user_chats + $group_chats + $super_group_chats);
if ($text === '') {
$text_back .= "\n\n" . 'List all chats: /' . $this->name . ' *' . "\n" . 'Search for chats: /' . $this->name . ' <search string>';
$text_back .= PHP_EOL . PHP_EOL . 'List all chats: /' . $this->name . ' *' . PHP_EOL . 'Search for chats: /' . $this->name . ' <search string>';
}
}
......
......@@ -11,6 +11,8 @@
namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Request;
/**
......@@ -36,7 +38,7 @@ class SendtoallCommand extends AdminCommand
/**
* @var string
*/
protected $version = '1.2.1';
protected $version = '1.3.0';
/**
* @var bool
......@@ -47,6 +49,7 @@ class SendtoallCommand extends AdminCommand
* Execute command
*
* @return boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
......@@ -68,18 +71,21 @@ class SendtoallCommand extends AdminCommand
null //'yyyy-mm-dd hh:mm:ss' date range to
);
$tot = 0;
$fail = 0;
$total = 0;
$failed = 0;
$text = 'Message sent to:' . "\n";
/** @var ServerResponse $result */
foreach ($results as $result) {
$status = '';
$type = '';
$name = '';
$type = '';
if ($result->isOk()) {
$status = '✔️';
$ServerResponse = $result->getResult();
$chat = $ServerResponse->getChat();
/** @var Message $message */
$message = $result->getResult();
$chat = $message->getChat();
if ($chat->isPrivateChat()) {
$name = $chat->getFirstName();
$type = 'user';
......@@ -89,15 +95,15 @@ class SendtoallCommand extends AdminCommand
}
} else {
$status = '✖️';
++$fail;
++$failed;
}
++$tot;
++$total;
$text .= $tot . ') ' . $status . ' ' . $type . ' ' . $name . "\n";
$text .= $total . ') ' . $status . ' ' . $type . ' ' . $name . "\n";
}
$text .= 'Delivered: ' . ($tot - $fail) . '/' . $tot . "\n";
$text .= 'Delivered: ' . ($total - $failed) . '/' . $total . "\n";
if ($tot === 0) {
if ($total === 0) {
$text = 'No users or chats found..';
}
}
......
......@@ -38,7 +38,7 @@ class SendtochannelCommand extends AdminCommand
/**
* @var string
*/
protected $version = '0.1.4';
protected $version = '0.2.0';
/**
* @var bool
......@@ -56,36 +56,43 @@ class SendtochannelCommand extends AdminCommand
* Command execute method
*
* @return \Longman\TelegramBot\Entities\ServerResponse|mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$user_id = $message->getFrom()->getId();
$type = $message->getType();
// 'Cast' the command type into message this protect the machine state
// if the commmad is recolled when the conversation is already started
$type = ($type == 'command') ? 'Message' : $type;
$text = trim($message->getText(true));
$data = [];
$data['chat_id'] = $chat_id;
$type = $message->getType();
// 'Cast' the command type into message to protect the machine state
// if the commmad is recalled when the conversation is already started
$type = ($type === 'command') ? 'Message' : $type;
$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;
$channels = (array)$this->getConfig('your_channel');
if (!isset($this->conversation->notes['state'])) {
$state = (count($channels) == 0) ? -1 : 0;
$this->conversation->notes['last_message_id'] = $message->getMessageId();
if (isset($notes['state'])) {
$state = $notes['state'];
} else {
$state = $this->conversation->notes['state'];
$state = (count($channels) === 0) ? -1 : 0;
$notes['last_message_id'] = $message->getMessageId();
}
switch ($state) {
case -1:
// getConfig has not been configured asking for channel to administer
if ($type != 'Message' || $text === '') {
$this->conversation->notes['state'] = -1;
if ($type !== 'Message' || $text === '') {
$notes['state'] = -1;
$this->conversation->update();
$data['text'] = 'Insert the channel name: (@yourchannel)';
......@@ -94,8 +101,8 @@ class SendtochannelCommand extends AdminCommand
break;
}
$this->conversation->notes['channel'] = $text;
$this->conversation->notes['last_message_id'] = $message->getMessageId();
$notes['channel'] = $text;
$notes['last_message_id'] = $message->getMessageId();
// Jump to state 1
goto insert;
......@@ -103,38 +110,35 @@ class SendtochannelCommand extends AdminCommand
default:
case 0:
// getConfig has been configured choose channel
if ($type != 'Message' || !in_array($text, $channels)) {
$this->conversation->notes['state'] = 0;
if ($type !== 'Message' || !in_array($text, $channels, true)) {
$notes['state'] = 0;
$this->conversation->update();
$keyboard = [];
foreach ($channels as $channel) {
$keyboard[] = [$channel];
}
$reply_keyboard_markup = new ReplyKeyboardMarkup(
$data['reply_markup'] = new ReplyKeyboardMarkup(
[
'keyboard' => $keyboard,
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true
'selective' => true,
]
);
$data['reply_markup'] = $reply_keyboard_markup;
$data['text'] = 'Select a channel';
if ($type != 'Message' || !in_array($text, $channels)) {
$data['text'] = 'Select a channel from the keyboard:';
}
$result = Request::sendMessage($data);
$data['text'] = 'Select a channel from the keyboard:';
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['channel'] = $text;
$this->conversation->notes['last_message_id'] = $message->getMessageId();
$notes['channel'] = $text;
$notes['last_message_id'] = $message->getMessageId();
// no break
case 1:
insert:
if ($this->conversation->notes['last_message_id'] == $message->getMessageId() || ($type == 'Message' && $text === '')) {
$this->conversation->notes['state'] = 1;
if (($type === 'Message' && $text === '') || $notes['last_message_id'] === $message->getMessageId()) {
$notes['state'] = 1;
$this->conversation->update();
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
......@@ -142,45 +146,40 @@ class SendtochannelCommand extends AdminCommand
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['last_message_id'] = $message->getMessageId();
$this->conversation->notes['message'] = $message->reflect();
$this->conversation->notes['message_type'] = $type;
$notes['last_message_id'] = $message->getMessageId();
$notes['message'] = $message->reflect();
$notes['message_type'] = $type;
// no break
case 2:
if ($this->conversation->notes['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) {
$this->conversation->notes['state'] = 2;
if (!$text_yes_or_no || $notes['last_message_id'] === $message->getMessageId()) {
$notes['state'] = 2;
$this->conversation->update();
// Execute this just with object that allow caption
if ($this->conversation->notes['message_type'] == 'Video' || $this->conversation->notes['message_type'] == 'Photo') {
$keyboard = [['Yes', 'No']];
$reply_keyboard_markup = new ReplyKeyboardMarkup(
if ($notes['message_type'] === 'Video' || $notes['message_type'] === 'Photo') {
$data['reply_markup'] = new ReplyKeyboardMarkup(
[
'keyboard' => $keyboard,
'keyboard' => [['Yes', 'No']],
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true
'selective' => true,
]
);
$data['reply_markup'] = $reply_keyboard_markup;
$data['text'] = 'Would you insert caption?';
if ($this->conversation->notes['last_message_id'] != $message->getMessageId() && !($text == 'Yes' || $text == 'No')) {
$data['text'] = 'Would you insert a caption?' . "\n" . 'Type Yes or No';
$data['text'] = 'Would you like to insert a caption?';
if (!$text_yes_or_no && $notes['last_message_id'] !== $message->getMessageId()) {
$data['text'] .= PHP_EOL . 'Type Yes or No';
}
$result = Request::sendMessage($data);
break;
}
}
$this->conversation->notes['set_caption'] = false;
if ($text == 'Yes') {
$this->conversation->notes['set_caption'] = true;
}
$this->conversation->notes['last_message_id'] = $message->getMessageId();
$notes['set_caption'] = ($text === 'Yes');
$notes['last_message_id'] = $message->getMessageId();
// no break
case 3:
if (($this->conversation->notes['last_message_id'] == $message->getMessageId() || $type != 'Message') && $this->conversation->notes['set_caption']) {
$this->conversation->notes['state'] = 3;
if ($notes['set_caption'] && ($notes['last_message_id'] === $message->getMessageId() || $type !== 'Message')) {
$notes['state'] = 3;
$this->conversation->update();
$data['text'] = 'Insert caption:';
......@@ -188,56 +187,52 @@ class SendtochannelCommand extends AdminCommand
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['last_message_id'] = $message->getMessageId();
$this->conversation->notes['caption'] = $text;
$notes['last_message_id'] = $message->getMessageId();
$notes['caption'] = $text;
// no break
case 4:
if ($this->conversation->notes['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) {
$this->conversation->notes['state'] = 4;
if (!$text_yes_or_no || $notes['last_message_id'] === $message->getMessageId()) {
$notes['state'] = 4;
$this->conversation->update();
$data['text'] = 'Message will look like this:';
$result = Request::sendMessage($data);
if ($this->conversation->notes['message_type'] != 'command') {
if ($this->conversation->notes['set_caption']) {
$data['caption'] = $this->conversation->notes['caption'];
if ($notes['message_type'] !== 'command') {
if ($notes['set_caption']) {
$data['caption'] = $notes['caption'];
}
$result = $this->sendBack(new Message($this->conversation->notes['message'], 'thisbot'), $data);
$this->sendBack(new Message($notes['message'], $this->telegram->getBotName()), $data);
$data['text'] = 'Would you post it?';
if ($this->conversation->notes['last_message_id'] != $message->getMessageId() && !($text == 'Yes' || $text == 'No')) {
$data['text'] = 'Would you post it?' . "\n" . 'Press Yes or No';
}
$keyboard = [['Yes', 'No']];
$reply_keyboard_markup = new ReplyKeyboardMarkup(
$data['reply_markup'] = new ReplyKeyboardMarkup(
[
'keyboard' => $keyboard,
'keyboard' => [['Yes', 'No']],
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true
'selective' => true,
]
);
$data['reply_markup'] = $reply_keyboard_markup;
$result = Request::sendMessage($data);
$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;
}
$this->conversation->notes['post_message'] = false;
if ($text == 'Yes') {
$this->conversation->notes['post_message'] = true;
}
$this->conversation->notes['last_message_id'] = $message->getMessageId();
$notes['post_message'] = ($text === 'Yes');
$notes['last_message_id'] = $message->getMessageId();
// no break
case 5:
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
if ($this->conversation->notes['post_message']) {
if ($notes['post_message']) {
$data['text'] = $this->publish(
new Message($this->conversation->notes['message'], 'anystring'),
$this->conversation->notes['channel'],
$this->conversation->notes['caption']
new Message($notes['message'], $this->telegram->getBotName()),
$notes['channel'],
$notes['caption']
);
} else {
$data['text'] = 'Abort by user, message not sent..';
......@@ -246,57 +241,8 @@ class SendtochannelCommand extends AdminCommand
$this->conversation->stop();
$result = Request::sendMessage($data);
}
return $result;
}
/**
* Execute without db
*
* @return mixed
*/
public function executeNoDb()
{
$message = $this->getMessage();
$text = trim($message->getText(true));
$chat_id = $message->getChat()->getId();
$data = [];
$data['chat_id'] = $chat_id;
if ($text === '') {
$data['text'] = 'Usage: /sendtochannel <text>';
} else {
$channels = (array)$this->getConfig('your_channel');
$first_channel = $channels[0];
$data['text'] = $this->publish(new Message($message->reflect(), 'anystring'), $first_channel);
}
return Request::sendMessage($data);
}
/**
* Publish a message to a channel and return success or failure message
*
* @param \Longman\TelegramBot\Entities\Message $message
* @param int $channel
* @param string|null $caption
*
* @return string
*/
protected function publish(Message $message, $channel, $caption = null)
{
$data = [
'chat_id' => $channel,
'caption' => $caption,
];
if ($this->sendBack($message, $data)->isOk()) {
$response = 'Message sent successfully to: ' . $channel;
} else {
$response = 'Message not sent to: ' . $channel . "\n" .
'- Does the channel exist?' . "\n" .
'- Is the bot an admin of the channel?';
}
return $response;
return $result;
}
/**
......@@ -307,8 +253,8 @@ class SendtochannelCommand extends AdminCommand
* 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 at an higher level maybe in AdminCommand or Command
* @todo Looking for a more significative name
* @todo This method will be moved to a higher level maybe in AdminCommand or Command
* @todo Looking for a more significant name
*
* @param \Longman\TelegramBot\Entities\Message $message
* @param array $data
......@@ -319,25 +265,25 @@ class SendtochannelCommand extends AdminCommand
protected function sendBack(Message $message, array $data)
{
$type = $message->getType();
$type = ($type == 'command') ? 'Message' : $type;
if ($type == 'Message') {
$type = ($type === 'command') ? 'Message' : $type;
if ($type === 'Message') {
$data['text'] = $message->getText(true);
} elseif ($type == 'Audio') {
} 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') {
} elseif ($type === 'Document') {
$data['document'] = $message->getDocument()->getFileId();
} elseif ($type == 'Photo') {
} elseif ($type === 'Photo') {
$data['photo'] = $message->getPhoto()[0]->getFileId();
} elseif ($type == 'Sticker') {
} elseif ($type === 'Sticker') {
$data['sticker'] = $message->getSticker()->getFileId();
} elseif ($type == 'Video') {
} elseif ($type === 'Video') {
$data['video'] = $message->getVideo()->getFileId();
} elseif ($type == 'Voice') {
} elseif ($type === 'Voice') {
$data['voice'] = $message->getVoice()->getFileId();
} elseif ($type == 'Location') {
} elseif ($type === 'Location') {
$data['latitude'] = $message->getLocation()->getLatitude();
$data['longitude'] = $message->getLocation()->getLongitude();
}
......@@ -349,4 +295,61 @@ class SendtochannelCommand extends AdminCommand
return call_user_func_array($callback_path . '::' . $callback_function, [$data]);
}
/**
* Publish a message to a channel and return success or failure message
*
* @param \Longman\TelegramBot\Entities\Message $message
* @param int $channel
* @param string|null $caption
*
* @return string
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
protected function publish(Message $message, $channel, $caption = null)
{
$data = [
'chat_id' => $channel,
'caption' => $caption,
];
if ($this->sendBack($message, $data)->isOk()) {
$response = 'Message sent successfully to: ' . $channel;
} else {
$response = 'Message not sent to: ' . $channel . 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 \Longman\TelegramBot\Exception\TelegramException
*/
public function executeNoDb()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = trim($message->getText(true));
$data = [
'chat_id' => $chat_id,
'text' => 'Usage: ' . $this->usage,
];
if ($text !== '') {
$channels = (array)$this->getConfig('your_channel');
$first_channel = $channels[0];
$data['text'] = $this->publish(new Message($message->reflect(), $this->telegram->getBotName()),
$first_channel);
}
return Request::sendMessage($data);
}
}
......@@ -15,6 +15,8 @@ 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\UserProfilePhotos;
use Longman\TelegramBot\Request;
/**
......@@ -40,7 +42,7 @@ class WhoisCommand extends AdminCommand
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.2.0';
/**
* @var bool
......@@ -51,6 +53,7 @@ class WhoisCommand extends AdminCommand
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
......@@ -71,7 +74,7 @@ class WhoisCommand extends AdminCommand
$text = substr($command, 5);
//We need that '-' now, bring it back
if ((substr($text, 0, 1) == 'g')) {
if (strpos($text, 'g') === 0) {
$text = str_replace('g', '-', $text);
}
}
......@@ -79,10 +82,14 @@ class WhoisCommand extends AdminCommand
if ($text === '') {
$text = 'Provide the id to lookup: /whois <id>';
} else {
$user_id = $text;
$user_id = $text;
$chat = null;
$created_at = null;
$updated_at = null;
$result = null;
if (is_numeric($text)) {
$result = DB::selectChats(
$results = DB::selectChats(
true, //Select groups (group chat)
true, //Select supergroups (super group chat)
true, //Select users (single chat)
......@@ -91,7 +98,9 @@ class WhoisCommand extends AdminCommand
$user_id //Specific chat_id to select
);
$result = $result[0];
if (!empty($results)) {
$result = reset($results);
}
} else {
$results = DB::selectChats(
true, //Select groups (group chat)
......@@ -103,8 +112,8 @@ class WhoisCommand extends AdminCommand
$text //Text to search in user/group name
);
if (is_array($results) && count($results) == 1) {
$result = $results[0];
if (is_array($results) && count($results) === 1) {
$result = reset($results);
}
}
......@@ -118,50 +127,53 @@ class WhoisCommand extends AdminCommand
$old_id = $result['old_id'];
}
if ($chat != null) {
if ($chat !== null) {
if ($chat->isPrivateChat()) {
$text = 'User ID: ' . $user_id . "\n";
$text .= 'Name: ' . $chat->getFirstName() . ' ' . $chat->getLastName() . "\n";
$text = 'User ID: ' . $user_id . PHP_EOL;
$text .= 'Name: ' . $chat->getFirstName() . ' ' . $chat->getLastName() . PHP_EOL;
if ($chat->getUsername() != '') {
$text .= 'Username: @' . $chat->getUsername() . "\n";
$username = $chat->getUsername();
if ($username !== null && $username !== '') {
$text .= 'Username: @' . $username . PHP_EOL;
}
$text .= 'First time seen: ' . $created_at . "\n";
$text .= 'Last activity: ' . $updated_at . "\n";
$text .= 'First time seen: ' . $created_at . PHP_EOL;
$text .= 'Last activity: ' . $updated_at . PHP_EOL;
//Code from Whoami command
$limit = 10;
$offset = null;
$ServerResponse = Request::getUserProfilePhotos([
'user_id' => $user_id,
'limit' => $limit,
'offset' => $offset,
]);
$ServerResponse = Request::getUserProfilePhotos(
[
'user_id' => $user_id,
'limit' => $limit,
'offset' => $offset,
]
);
if ($ServerResponse->isOk()) {
/** @var UserProfilePhotos $UserProfilePhoto */
$UserProfilePhoto = $ServerResponse->getResult();
$totalcount = $UserProfilePhoto->getTotalCount();
} else {
$totalcount = 0;
}
if ($totalcount > 0) {
$photos = $UserProfilePhoto->getPhotos();
$photo = $photos[0][2];
$file_id = $photo->getFileId();
if ($UserProfilePhoto->getTotalCount() > 0) {
$photos = $UserProfilePhoto->getPhotos();
$data['photo'] = $file_id;
$data['caption'] = $text;
/** @var PhotoSize $photo */
$photo = $photos[0][2];
$file_id = $photo->getFileId();
return Request::sendPhoto($data);
$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 . ')' : '') . "\n";
$text .= 'Type: ' . ucfirst($chat->getType()) . "\n";
$text .= 'Title: ' . $chat->getTitle() . "\n";
$text .= 'First time added to group: ' . $created_at . "\n";
$text .= 'Last activity: ' . $updated_at . "\n";
$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!';
......@@ -171,6 +183,7 @@ class WhoisCommand extends AdminCommand
}
$data['text'] = $text;
return Request::sendMessage($data);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment