Commit 193aa44c authored by MBoretto's avatar MBoretto

Merge branch 'develop' of https://github.com/akalongman/php-telegram-bot into develop

parents 7147b12f 2bdd0d12
......@@ -21,3 +21,8 @@ N: Armando Lüscher
E: armando@noplanman.ch
W: http://noplanman.ch
D: Maintainer and Collaborator
N: Jack'lul (alias)
E: jacklul@jacklul.com
W: http://jacklul.com
D: Maintainer and Collaborator
......@@ -31,8 +31,6 @@ class SendtoallCommand extends AdminCommand
/**
* Execute command
*
* @todo Don't use empty, as a string of '0' is regarded to be empty
*
* @return boolean
*/
public function execute()
......@@ -42,7 +40,7 @@ class SendtoallCommand extends AdminCommand
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
if (empty($text)) {
if ($text === '') {
$text = 'Write the message to send: /sendtoall <message>';
} else {
$results = Request::sendToActiveChats(
......
......@@ -67,7 +67,7 @@ class SendtochannelCommand extends AdminCommand
switch ($state) {
case -1:
// getConfig has not been configured asking for channel to administer
if ($type != 'Message' || empty($text)) {
if ($type != 'Message' || $text === '') {
$this->conversation->notes['state'] = -1;
$this->conversation->update();
......@@ -116,7 +116,7 @@ class SendtochannelCommand extends AdminCommand
// no break
case 1:
insert:
if ($this->conversation->notes['last_message_id'] == $message->getMessageId() || ($type == 'Message' && empty($text))) {
if ($this->conversation->notes['last_message_id'] == $message->getMessageId() || ($type == 'Message' && $text === '')) {
$this->conversation->notes['state'] = 1;
$this->conversation->update();
......@@ -245,7 +245,7 @@ class SendtochannelCommand extends AdminCommand
$data = [];
$data['chat_id'] = $chat_id;
if (empty($text)) {
if ($text === '') {
$data['text'] = 'Usage: /sendtochannel <text>';
} else {
$channels = (array) $this->getConfig('your_channel');
......
......@@ -21,10 +21,8 @@ class Audio extends Entity
protected $mime_type;
protected $file_size;
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
......@@ -40,7 +38,6 @@ class Audio extends Entity
$this->title = isset($data['title']) ? $data['title'] : null;
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
}
public function getFileId()
......@@ -57,10 +54,12 @@ class Audio extends Entity
{
return $this->performer;
}
public function getTitle()
{
return $this->title;
}
public function getMimeType()
{
return $this->mime_type;
......
......@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class Chat extends Entity
{
protected $id;
protected $type;
protected $title;
......@@ -81,37 +80,31 @@ class Chat extends Entity
public function getId()
{
return $this->id;
}
public function getType()
{
return $this->type;
}
public function getTitle()
{
return $this->title;
}
public function getFirstName()
{
return $this->first_name;
}
public function getLastName()
{
return $this->last_name;
}
public function getUsername()
{
return $this->username;
}
......
......@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class ChosenInlineResult extends Entity
{
protected $result_id;
protected $from;
protected $location;
......@@ -23,7 +22,6 @@ class ChosenInlineResult extends Entity
public function __construct(array $data)
{
$this->result_id = isset($data['result_id']) ? $data['result_id'] : null;
if (empty($this->result_id)) {
throw new TelegramException('result_id is empty!');
......
......@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class Contact extends Entity
{
protected $phone_number;
protected $first_name;
protected $last_name;
......@@ -22,7 +21,6 @@ class Contact extends Entity
public function __construct(array $data)
{
$this->phone_number = isset($data['phone_number']) ? $data['phone_number'] : null;
if (empty($this->phone_number)) {
throw new TelegramException('phone_number is empty!');
......
......@@ -22,7 +22,6 @@ class Document extends Entity
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
......@@ -36,7 +35,6 @@ class Document extends Entity
$this->file_name = isset($data['file_name']) ? $data['file_name'] : null;
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
}
public function getFileId()
......@@ -46,21 +44,21 @@ class Document extends Entity
public function getThumb()
{
return $this->thumb;
return $this->thumb;
}
public function getFileName()
{
return $this->file_name;
return $this->file_name;
}
public function getMimeType()
{
return $this->mime_type;
return $this->mime_type;
}
public function getFileSize()
{
return $this->file_size;
return $this->file_size;
}
}
......@@ -14,10 +14,8 @@ class Entity
{
protected $bot_name;
public function getBotName()
{
return $this->bot_name;
}
......
......@@ -20,7 +20,6 @@ class File extends Entity
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
if (empty($this->file_id)) {
throw new TelegramException('file_id is empty!');
......@@ -29,7 +28,6 @@ class File extends Entity
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
$this->file_path = isset($data['file_path']) ? $data['file_path'] : null;
}
public function getFileId()
......@@ -39,11 +37,11 @@ class File extends Entity
public function getFileSize()
{
return $this->file_size;
return $this->file_size;
}
public function getFilePath()
{
return $this->file_path;
return $this->file_path;
}
}
......@@ -19,6 +19,9 @@ class InlineKeyboardButton extends Entity
protected $callback_data;
protected $switch_inline_query;
/**
* @todo check if only one of 'url, callback_data, switch_inline_query' fields is set, documentation states that only one of these can be used
*/
public function __construct($data = array())
{
$this->text = isset($data['text']) ? $data['text'] : null;
......@@ -30,12 +33,8 @@ class InlineKeyboardButton extends Entity
$this->callback_data = isset($data['callback_data']) ? $data['callback_data'] : null;
$this->switch_inline_query = isset($data['switch_inline_query']) ? $data['switch_inline_query'] : null;
if (empty($this->url) && empty($this->callback_data) && empty($this->switch_inline_query)) {
if ($this->url === '' && $this->callback_data === '' && $this->switch_inline_query === '') {
throw new TelegramException('You must use at least one of these fields: url, callback_data, switch_inline_query!');
}
/*
* @todo check if only one of 'url, callback_data, switch_inline_query' fields is set, documentation states that only one of these can be used
*/
}
}
......@@ -16,7 +16,7 @@ class InlineKeyboardMarkup extends Entity
{
protected $inline_keyboard;
/*
/**
* @todo check for InlineKeyboardButton elements
*/
public function __construct($data = array())
......
......@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class InlineQuery extends Entity
{
protected $id;
protected $from;
protected $location;
......@@ -23,7 +22,6 @@ class InlineQuery extends Entity
public function __construct(array $data)
{
$this->id = isset($data['id']) ? $data['id'] : null;
if (empty($this->id)) {
throw new TelegramException('id is empty!');
......@@ -48,18 +46,22 @@ class InlineQuery extends Entity
{
return $this->id;
}
public function getFrom()
{
return $this->from;
}
public function getLocation()
{
return $this->location;
}
public function getQuery()
{
return $this->query;
}
public function getOffset()
{
return $this->offset;
......
......@@ -35,8 +35,19 @@ class InlineQueryResult extends Entity
{
return $this->type;
}
public function getId()
{
return $this->id;
}
public function getInputMessageContent()
{
return $this->input_message_content;
}
public function getReplyMarkup()
{
return $this->reply_markup;
}
}
......@@ -45,7 +45,6 @@ class InlineQueryResultArticle extends InlineQueryResult
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
}
public function getTitle()
......
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedAudio extends InlineQueryResult
{
protected $audio_file_id;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'audio';
$this->audio_file_id = isset($data['audio_file_id']) ? $data['audio_file_id'] : null;
if (empty($this->audio_file_id)) {
throw new TelegramException('audio_file_id is empty!');
}
}
public function getAudioFileId()
{
return $this->audio_file_id;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedDocument extends InlineQueryResult
{
protected $document_file_id;
protected $title;
protected $description;
protected $caption;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'document';
$this->document_file_id = isset($data['document_file_id']) ? $data['document_file_id'] : null;
if (empty($this->document_file_id)) {
throw new TelegramException('document_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
public function getDocumentFileId()
{
return $this->document_file_id;
}
public function getTitle()
{
return $this->title;
}
public function getDescription()
{
return $this->description;
}
public function getCaption()
{
return $this->caption;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedGif extends InlineQueryResult
{
protected $gif_file_id;
protected $title;
protected $description;
protected $caption;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'gif';
$this->gif_file_id = isset($data['gif_file_id']) ? $data['gif_file_id'] : null;
if (empty($this->gif_file_id)) {
throw new TelegramException('gif_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
public function getGifFileId()
{
return $this->gif_file_id;
}
public function getTitle()
{
return $this->title;
}
public function getCaption()
{
return $this->caption;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedMpeg4Gif extends InlineQueryResult
{
protected $mpeg4_file_id;
protected $title;
protected $caption;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'mpeg4_gif';
$this->mpeg4_file_id = isset($data['mpeg4_file_id']) ? $data['mpeg4_file_id'] : null;
if (empty($this->mpeg4_file_id)) {
throw new TelegramException('mpeg4_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
public function getMpeg4FileId()
{
return $this->mpeg4_file_id;
}
public function getTitle()
{
return $this->title;
}
public function getCaption()
{
return $this->caption;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedPhoto extends InlineQueryResult
{
protected $photo_file_id;
protected $title;
protected $description;
protected $caption;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'photo';
$this->photo_file_id = isset($data['photo_file_id']) ? $data['photo_file_id'] : null;
if (empty($this->photo_file_id)) {
throw new TelegramException('photo_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
public function getPhotoFileId()
{
return $this->photo_file_id;
}
public function getTitle()
{
return $this->title;
}
public function getDescription()
{
return $this->description;
}
public function getCaption()
{
return $this->caption;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedSticker extends InlineQueryResult
{
protected $sticker_file_id;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'sticker';
$this->photo_file_id = isset($data['sticker_file_id']) ? $data['sticker_file_id'] : null;
if (empty($this->sticker_file_id)) {
throw new TelegramException('sticker_file_id is empty!');
}
}
public function getStickerFileId()
{
return $this->sticker_file_id;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedVideo extends InlineQueryResult
{
protected $video_file_id;
protected $title;
protected $description;
protected $caption;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'photo';
$this->video_file_id = isset($data['video_file_id']) ? $data['video_file_id'] : null;
if (empty($this->video_file_id)) {
throw new TelegramException('video_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
public function getVideoFileId()
{
return $this->video_file_id;
}
public function getTitle()
{
return $this->title;
}
public function getDescription()
{
return $this->description;
}
public function getCaption()
{
return $this->caption;
}
}
<?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\Entities;
use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultCachedVoice extends InlineQueryResult
{
protected $voice_file_id;
protected $title;
protected $description;
protected $caption;
public function __construct(array $data)
{
parent::__construct($data);
$this->type = 'voice';
$this->voice_file_id = isset($data['voice_file_id']) ? $data['voice_file_id'] : null;
if (empty($this->voice_file_id)) {
throw new TelegramException('voice_file_id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
public function getVoiceFileId()
{
return $this->voice_file_id;
}
public function getTitle()
{
return $this->title;
}
public function getDescription()
{
return $this->description;
}
public function getCaption()
{
return $this->caption;
}
}
......@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultGif extends InlineQueryResult
{
protected $gif_url;
protected $gif_width;
protected $gif_height;
......@@ -43,29 +42,33 @@ class InlineQueryResultGif extends InlineQueryResult
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
public function getGifUrl()
{
return $this->gif_url;
}
public function getGifWidth()
{
return $this->gif_width;
}
public function getGifHeight()
{
return $this->gif_height;
}
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getTitle()
{
return $this->title;
}
public function getCaption()
{
return $this->caption;
......
......@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultMpeg4Gif extends InlineQueryResult
{
protected $mpeg4_url;
protected $mpeg4_width;
protected $mpeg4_height;
......@@ -43,29 +42,33 @@ class InlineQueryResultMpeg4Gif extends InlineQueryResult
$this->title = isset($data['title']) ? $data['title'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
public function getMpeg4Url()
{
return $this->mpeg4_url;
}
public function getMpeg4Width()
{
return $this->mpeg4_width;
}
public function getMpeg4Height()
{
return $this->mpeg4_height;
}
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getTitle()
{
return $this->title;
}
public function getCaption()
{
return $this->caption;
......
......@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultPhoto extends InlineQueryResult
{
protected $photo_url;
protected $photo_width;
protected $photo_height;
......@@ -45,33 +44,38 @@ class InlineQueryResultPhoto extends InlineQueryResult
$this->title = isset($data['title']) ? $data['title'] : null;
$this->description = isset($data['description']) ? $data['description'] : null;
$this->caption = isset($data['caption']) ? $data['caption'] : null;
}
public function getPhotoUrl()
{
return $this->photo_url;
}
public function getPhotoWidth()
{
return $this->photo_width;
}
public function getPhotoHeight()
{
return $this->photo_height;
}
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getTitle()
{
return $this->title;
}
public function getDescription()
{
return $this->description;
}
public function getCaption()
{
return $this->caption;
......
......@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class InlineQueryResultVideo extends InlineQueryResult
{
protected $video_url;
protected $mime_type;
protected $thumb_url;
......@@ -56,34 +55,42 @@ class InlineQueryResultVideo extends InlineQueryResult
{
return $this->video_url;
}
public function getMimeType()
{
return $this->mime_type;
}
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getTitle()
{
return $this->title;
}
public function getCaption()
{
return $this->caption;
}
public function getVideoWidth()
{
return $this->video_width;
}
public function getVideoHeight()
{
return $this->video_height;
}
public function getVideoDuration()
{
return $this->video_duration;
}
public function getDescription()
{
return $this->description;
......
......@@ -20,8 +20,6 @@ class InputContactMessageContent extends InputMessageContent
public function __construct(array $data)
{
//parent::__construct($data);
$this->phone_number isset($data['phone_number']) ? $data['phone_number'] : null;
if (empty($this->phone_number)) {
throw new TelegramException('phone_number is empty!');
......
......@@ -19,8 +19,6 @@ class InputLocationMessageContent extends InputMessageContent
public function __construct(array $data)
{
//parent::__construct($data);
$this->latitude isset($data['latitude']) ? $data['latitude'] : null;
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
......
......@@ -20,8 +20,6 @@ class InputTextMessageContent extends InputMessageContent
public function __construct(array $data)
{
//parent::__construct($data);
$this->message_text isset($data['message_text']) ? $data['message_text'] : null;
if (empty($this->message_text)) {
throw new TelegramException('message_text is empty!');
......
......@@ -22,8 +22,6 @@ class InputVenueMessageContent extends InputMessageContent
public function __construct(array $data)
{
//parent::__construct($data);
$this->latitude isset($data['latitude']) ? $data['latitude'] : null;
if (empty($this->latitude)) {
throw new TelegramException('latitude is empty!');
......
......@@ -122,7 +122,6 @@ class Message extends Entity
$this->forward_from = isset($data['forward_from']) ? $data['forward_from'] : null;
if (!empty($this->forward_from)) {
$this->forward_from = new User($this->forward_from);
}
$this->forward_from_chat = isset($data['forward_from_chat']) ? $data['forward_from_chat'] : null;
......
......@@ -17,20 +17,23 @@ class MessageEntity extends Entity
protected $length;
protected $url;
/**
* @todo check for type value from this list: https://core.telegram.org/bots/api#messageentity
*/
public function __construct(array $data)
{
$this->type = isset($data['type']) ? $data['type'] : null;
if (empty($this->type)) { // @todo check for value from this list: https://core.telegram.org/bots/api#messageentity
if (empty($this->type)) {
throw new TelegramException('type is empty!');
}
$this->offset = isset($data['offset']) ? $data['offset'] : null;
if (empty($this->offset) && $this->offset != 0) { // @todo this is not an ideal solution?
if ($this->offset === '') {
throw new TelegramException('offset is empty!');
}
$this->length = isset($data['length']) ? $data['length'] : null;
if (empty($this->length) && $this->offset != 0) { // @todo this is not an ideal solution?
if ($this->length === '') {
throw new TelegramException('length is empty!');
}
......
......@@ -21,7 +21,7 @@ class ReplyKeyboardMarkup extends Entity
protected $one_time_keyboard;
protected $selective;
/*
/**
* @todo check for KeyboardButton elements
*/
public function __construct($data = array())
......
......@@ -568,6 +568,12 @@ class Telegram
if ($user_id === null && $this->update !== null) {
if (($message = $this->update->getMessage()) && ($from = $message->getFrom())) {
$user_id = $from->getId();
} elseif (($inline_query = $this->update->getInlineQuery()) && ($from = $inline_query->getFrom())) {
$user_id = $from->getId();
} elseif (($callback_query = $this->update->getCallbackQuery()) && ($from = $callback_query->getFrom())) {
$user_id = $from->getId();
} elseif (($chosen_inline_result = $this->update->getChosenInlineResult()) && ($from = $chosen_inline_result->getFrom())) {
$user_id = $from->getId();
}
}
......
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