Commit a8c27913 authored by Avtandil Kikabidze's avatar Avtandil Kikabidze

Improved code and doc-blocks

parent 87e0d1c4
...@@ -40,7 +40,10 @@ class Botan ...@@ -40,7 +40,10 @@ class Botan
public static $command = ''; public static $command = '';
/** /**
* Initilize botan * Initialize Botan
*
* @param $token
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function initializeBotan($token) public static function initializeBotan($token)
{ {
...@@ -71,7 +74,7 @@ class Botan ...@@ -71,7 +74,7 @@ class Botan
* @param string $command * @param string $command
* *
* @return bool|string * @return bool|string
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function track($input, $command = '') public static function track($input, $command = '')
{ {
...@@ -87,7 +90,7 @@ class Botan ...@@ -87,7 +90,7 @@ class Botan
$obj = json_decode($input, true); $obj = json_decode($input, true);
if (isset($obj['message'])) { if (isset($obj['message'])) {
$data = $obj['message']; $data = $obj['message'];
$event_name = 'Message'; $event_name = 'Message';
if (isset($obj['message']['entities']) && is_array($obj['message']['entities'])) { if (isset($obj['message']['entities']) && is_array($obj['message']['entities'])) {
...@@ -107,13 +110,13 @@ class Botan ...@@ -107,13 +110,13 @@ class Botan
} }
} }
} elseif (isset($obj['inline_query'])) { } elseif (isset($obj['inline_query'])) {
$data = $obj['inline_query']; $data = $obj['inline_query'];
$event_name = 'Inline Query'; $event_name = 'Inline Query';
} elseif (isset($obj['chosen_inline_result'])) { } elseif (isset($obj['chosen_inline_result'])) {
$data = $obj['chosen_inline_result']; $data = $obj['chosen_inline_result'];
$event_name = 'Chosen Inline Result'; $event_name = 'Chosen Inline Result';
} elseif (isset($obj['callback_query'])) { } elseif (isset($obj['callback_query'])) {
$data = $obj['callback_query']; $data = $obj['callback_query'];
$event_name = 'Callback Query'; $event_name = 'Callback Query';
} }
...@@ -121,7 +124,7 @@ class Botan ...@@ -121,7 +124,7 @@ class Botan
return false; return false;
} }
$uid = $data['from']['id']; $uid = $data['from']['id'];
$request = str_replace( $request = str_replace(
['#TOKEN', '#UID', '#NAME'], ['#TOKEN', '#UID', '#NAME'],
[self::$token, $uid, urlencode($event_name)], [self::$token, $uid, urlencode($event_name)],
...@@ -130,15 +133,15 @@ class Botan ...@@ -130,15 +133,15 @@ class Botan
$options = [ $options = [
'http' => [ 'http' => [
'header' => 'Content-Type: application/json', 'header' => 'Content-Type: application/json',
'method' => 'POST', 'method' => 'POST',
'content' => json_encode($data), 'content' => json_encode($data),
'ignore_errors' => true 'ignore_errors' => true
] ]
]; ];
$context = stream_context_create($options); $context = stream_context_create($options);
$response = @file_get_contents($request, false, $context); $response = @file_get_contents($request, false, $context);
$responseData = json_decode($response, true); $responseData = json_decode($response, true);
if ($responseData['status'] != 'accepted') { if ($responseData['status'] != 'accepted') {
...@@ -155,7 +158,7 @@ class Botan ...@@ -155,7 +158,7 @@ class Botan
* @param $user_id * @param $user_id
* *
* @return string * @return string
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function shortenUrl($url, $user_id) public static function shortenUrl($url, $user_id)
{ {
...@@ -182,16 +185,17 @@ class Botan ...@@ -182,16 +185,17 @@ class Botan
$options = [ $options = [
'http' => [ 'http' => [
'ignore_errors' => true, 'ignore_errors' => true,
'timeout' => 3 'timeout' => 3
] ]
]; ];
$context = stream_context_create($options); $context = stream_context_create($options);
$response = @file_get_contents($request, false, $context); $response = @file_get_contents($request, false, $context);
if (!filter_var($response, FILTER_VALIDATE_URL) === false) { if (!filter_var($response, FILTER_VALIDATE_URL) === false) {
BotanDB::insertShortUrl($user_id, $url, $response); BotanDB::insertShortUrl($user_id, $url, $response);
} else { } else {
// @FIXME: Add telegram log
error_log('Botan.io API replied with error: ' . $response); error_log('Botan.io API replied with error: ' . $response);
return $url; return $url;
} }
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
namespace Longman\TelegramBot; namespace Longman\TelegramBot;
use Exception;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
use PDO;
/** /**
* Class BotanDB * Class BotanDB
...@@ -33,7 +35,7 @@ class BotanDB extends DB ...@@ -33,7 +35,7 @@ class BotanDB extends DB
* @param $user_id * @param $user_id
* @param $url * @param $url
* *
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
* *
* @return bool|string * @return bool|string
*/ */
...@@ -48,12 +50,12 @@ class BotanDB extends DB ...@@ -48,12 +50,12 @@ class BotanDB extends DB
WHERE `user_id` = :user_id AND `url` = :url WHERE `user_id` = :user_id AND `url` = :url
'); ');
$sth->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':url', $url, \PDO::PARAM_INT); $sth->bindParam(':url', $url, PDO::PARAM_INT);
$sth->execute(); $sth->execute();
$results = $sth->fetchAll(\PDO::FETCH_ASSOC); $results = $sth->fetchAll(PDO::FETCH_ASSOC);
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
...@@ -67,7 +69,7 @@ class BotanDB extends DB ...@@ -67,7 +69,7 @@ class BotanDB extends DB
* @param $url * @param $url
* @param $short_url * @param $short_url
* *
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
* *
* @return bool * @return bool
*/ */
...@@ -95,7 +97,7 @@ class BotanDB extends DB ...@@ -95,7 +97,7 @@ class BotanDB extends DB
$sth->bindParam(':date', $created_at); $sth->bindParam(':date', $created_at);
$status = $sth->execute(); $status = $sth->execute();
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
......
...@@ -87,9 +87,9 @@ class Conversation ...@@ -87,9 +87,9 @@ class Conversation
*/ */
protected function clear() protected function clear()
{ {
$this->conversation = null; $this->conversation = null;
$this->protected_notes = null; $this->protected_notes = null;
$this->notes = null; $this->notes = null;
return true; return true;
} }
...@@ -118,7 +118,7 @@ class Conversation ...@@ -118,7 +118,7 @@ class Conversation
//Load the conversation notes //Load the conversation notes
$this->protected_notes = json_decode($this->conversation['notes'], true); $this->protected_notes = json_decode($this->conversation['notes'], true);
$this->notes = $this->protected_notes; $this->notes = $this->protected_notes;
} }
return $this->exists(); return $this->exists();
...@@ -146,7 +146,8 @@ class Conversation ...@@ -146,7 +146,8 @@ class Conversation
$this->user_id, $this->user_id,
$this->chat_id, $this->chat_id,
$this->command $this->command
)) { )
) {
return $this->load(); return $this->load();
} }
} }
...@@ -188,7 +189,7 @@ class Conversation ...@@ -188,7 +189,7 @@ class Conversation
if ($this->exists()) { if ($this->exists()) {
$fields = ['status' => $status]; $fields = ['status' => $status];
$where = [ $where = [
'id' => $this->conversation['id'], 'id' => $this->conversation['id'],
'status' => 'active', 'status' => 'active',
'user_id' => $this->user_id, 'user_id' => $this->user_id,
'chat_id' => $this->chat_id, 'chat_id' => $this->chat_id,
...@@ -211,7 +212,7 @@ class Conversation ...@@ -211,7 +212,7 @@ class Conversation
if ($this->exists()) { if ($this->exists()) {
$fields = ['notes' => json_encode($this->notes)]; $fields = ['notes' => json_encode($this->notes)];
//I can update a conversation whatever the state is //I can update a conversation whatever the state is
$where = ['id' => $this->conversation['id']]; $where = ['id' => $this->conversation['id']];
if (ConversationDB::updateConversation($fields, $where)) { if (ConversationDB::updateConversation($fields, $where)) {
return true; return true;
} }
......
...@@ -10,11 +10,10 @@ ...@@ -10,11 +10,10 @@
namespace Longman\TelegramBot; namespace Longman\TelegramBot;
use Exception;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
use PDO;
/**
* Class ConversationDB
*/
class ConversationDB extends DB class ConversationDB extends DB
{ {
/** /**
...@@ -35,6 +34,7 @@ class ConversationDB extends DB ...@@ -35,6 +34,7 @@ class ConversationDB extends DB
* @param bool $limit * @param bool $limit
* *
* @return array|bool * @return array|bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function selectConversation($user_id, $chat_id, $limit = null) public static function selectConversation($user_id, $chat_id, $limit = null)
{ {
...@@ -54,14 +54,14 @@ class ConversationDB extends DB ...@@ -54,14 +54,14 @@ class ConversationDB extends DB
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
$active = 'active'; $active = 'active';
$sth->bindParam(':status', $active, \PDO::PARAM_STR); $sth->bindParam(':status', $active, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':limit', $limit, \PDO::PARAM_INT); $sth->bindParam(':limit', $limit, PDO::PARAM_INT);
$sth->execute(); $sth->execute();
$results = $sth->fetchAll(\PDO::FETCH_ASSOC); $results = $sth->fetchAll(PDO::FETCH_ASSOC);
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
return $results; return $results;
...@@ -75,6 +75,7 @@ class ConversationDB extends DB ...@@ -75,6 +75,7 @@ class ConversationDB extends DB
* @param string $command * @param string $command
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertConversation($user_id, $chat_id, $command) public static function insertConversation($user_id, $chat_id, $command)
{ {
...@@ -83,7 +84,7 @@ class ConversationDB extends DB ...@@ -83,7 +84,7 @@ class ConversationDB extends DB
} }
try { try {
$sth = self::$pdo->prepare('INSERT INTO `' . TB_CONVERSATION . '` $sth = self::$pdo->prepare('INSERT INTO `' . TB_CONVERSATION . '`
( (
`status`, `user_id`, `chat_id`, `command`, `notes`, `created_at`, `updated_at` `status`, `user_id`, `chat_id`, `command`, `notes`, `created_at`, `updated_at`
) )
...@@ -93,7 +94,7 @@ class ConversationDB extends DB ...@@ -93,7 +94,7 @@ class ConversationDB extends DB
'); ');
$active = 'active'; $active = 'active';
//$notes = json_encode(''); //$notes = json_encode('');
$notes = '""'; $notes = '""';
$created_at = self::getTimestamp(); $created_at = self::getTimestamp();
$sth->bindParam(':status', $active); $sth->bindParam(':status', $active);
...@@ -104,7 +105,7 @@ class ConversationDB extends DB ...@@ -104,7 +105,7 @@ class ConversationDB extends DB
$sth->bindParam(':date', $created_at); $sth->bindParam(':date', $created_at);
$status = $sth->execute(); $status = $sth->execute();
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
return $status; return $status;
...@@ -133,6 +134,7 @@ class ConversationDB extends DB ...@@ -133,6 +134,7 @@ class ConversationDB extends DB
* @todo This function is generic should be moved in DB.php * @todo This function is generic should be moved in DB.php
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function update($table, array $fields_values, array $where_fields_values) public static function update($table, array $fields_values, array $where_fields_values)
{ {
...@@ -143,10 +145,10 @@ class ConversationDB extends DB ...@@ -143,10 +145,10 @@ class ConversationDB extends DB
$fields_values['updated_at'] = self::getTimestamp(); $fields_values['updated_at'] = self::getTimestamp();
//Values //Values
$update = ''; $update = '';
$tokens = []; $tokens = [];
$tokens_counter = 0; $tokens_counter = 0;
$a = 0; $a = 0;
foreach ($fields_values as $field => $value) { foreach ($fields_values as $field => $value) {
if ($a) { if ($a) {
$update .= ', '; $update .= ', ';
...@@ -158,8 +160,8 @@ class ConversationDB extends DB ...@@ -158,8 +160,8 @@ class ConversationDB extends DB
} }
//Where //Where
$a = 0; $a = 0;
$where = ''; $where = '';
foreach ($where_fields_values as $field => $value) { foreach ($where_fields_values as $field => $value) {
if ($a) { if ($a) {
$where .= ' AND '; $where .= ' AND ';
...@@ -168,15 +170,15 @@ class ConversationDB extends DB ...@@ -168,15 +170,15 @@ class ConversationDB extends DB
$where .= 'WHERE '; $where .= 'WHERE ';
} }
++$tokens_counter; ++$tokens_counter;
$where .= '`' . $field .'`= :' . $tokens_counter; $where .= '`' . $field . '`= :' . $tokens_counter;
$tokens[':' . $tokens_counter] = $value; $tokens[':' . $tokens_counter] = $value;
} }
$query = 'UPDATE `' . $table . '` SET ' . $update . ' ' . $where; $query = 'UPDATE `' . $table . '` SET ' . $update . ' ' . $where;
try { try {
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
$status = $sth->execute($tokens); $status = $sth->execute($tokens);
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
return $status; return $status;
......
...@@ -19,18 +19,9 @@ use Longman\TelegramBot\Entities\Message; ...@@ -19,18 +19,9 @@ use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\Update; use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\User; use Longman\TelegramBot\Entities\User;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
use PDO;
use PDOException;
/**
* @package Telegram
* @author Avtandil Kikabidze <akalongman@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
/**
* Class DB.
*/
class DB class DB
{ {
/** /**
...@@ -43,7 +34,7 @@ class DB ...@@ -43,7 +34,7 @@ class DB
/** /**
* PDO object * PDO object
* *
* @var \PDO * @var PDO
*/ */
static protected $pdo; static protected $pdo;
...@@ -57,40 +48,44 @@ class DB ...@@ -57,40 +48,44 @@ class DB
/** /**
* Telegram class object * Telegram class object
* *
* @var Telegram * @var \Longman\TelegramBot\Telegram
*/ */
static protected $telegram; static protected $telegram;
/** /**
* Initialize * Initialize
* *
* @param array $credentials Database connection details * @param array $credentials Database connection details
* @param Telegram $telegram Telegram object to connect with this object * @param \Longman\TelegramBot\Telegram $telegram Telegram object to connect with this object
* @param string $table_prefix Table prefix * @param string $table_prefix Table prefix
* @param string $encoding Database character encoding * @param string $encoding Database character encoding
* *
* @return \PDO PDO database object * @return PDO PDO database object
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function initialize(array $credentials, Telegram $telegram, $table_prefix = null, $encoding = 'utf8mb4') public static function initialize(
{ array $credentials,
Telegram $telegram,
$table_prefix = null,
$encoding = 'utf8mb4'
) {
if (empty($credentials)) { if (empty($credentials)) {
throw new TelegramException('MySQL credentials not provided!'); throw new TelegramException('MySQL credentials not provided!');
} }
$dsn = 'mysql:host=' . $credentials['host'] . ';dbname=' . $credentials['database']; $dsn = 'mysql:host=' . $credentials['host'] . ';dbname=' . $credentials['database'];
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $encoding]; $options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $encoding];
try { try {
$pdo = new \PDO($dsn, $credentials['user'], $credentials['password'], $options); $pdo = new PDO($dsn, $credentials['user'], $credentials['password'], $options);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
self::$pdo = $pdo; self::$pdo = $pdo;
self::$telegram = $telegram; self::$telegram = $telegram;
self::$mysql_credentials = $credentials; self::$mysql_credentials = $credentials;
self::$table_prefix = $table_prefix; self::$table_prefix = $table_prefix;
self::defineTable(); self::defineTable();
...@@ -102,12 +97,12 @@ class DB ...@@ -102,12 +97,12 @@ class DB
* *
* Let you use the class with an external already existing Pdo Mysql connection. * Let you use the class with an external already existing Pdo Mysql connection.
* *
* @param \PDO $external_pdo_connection PDO database object * @param PDO $external_pdo_connection PDO database object
* @param Telegram $telegram Telegram object to connect with this object * @param \Longman\TelegramBot\Telegram $telegram Telegram object to connect with this object
* @param string $table_prefix Table prefix * @param string $table_prefix Table prefix
* *
* @return \PDO PDO database object * @return PDO PDO database object
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function externalInitialize($external_pdo_connection, Telegram $telegram, $table_prefix = null) public static function externalInitialize($external_pdo_connection, Telegram $telegram, $table_prefix = null)
{ {
...@@ -115,10 +110,10 @@ class DB ...@@ -115,10 +110,10 @@ class DB
throw new TelegramException('MySQL external connection not provided!'); throw new TelegramException('MySQL external connection not provided!');
} }
self::$pdo = $external_pdo_connection; self::$pdo = $external_pdo_connection;
self::$telegram = $telegram; self::$telegram = $telegram;
self::$mysql_credentials = null; self::$mysql_credentials = null;
self::$table_prefix = $table_prefix; self::$table_prefix = $table_prefix;
self::defineTable(); self::defineTable();
...@@ -131,31 +126,31 @@ class DB ...@@ -131,31 +126,31 @@ class DB
protected static function defineTable() protected static function defineTable()
{ {
if (!defined('TB_TELEGRAM_UPDATE')) { if (!defined('TB_TELEGRAM_UPDATE')) {
define('TB_TELEGRAM_UPDATE', self::$table_prefix.'telegram_update'); define('TB_TELEGRAM_UPDATE', self::$table_prefix . 'telegram_update');
} }
if (!defined('TB_MESSAGE')) { if (!defined('TB_MESSAGE')) {
define('TB_MESSAGE', self::$table_prefix.'message'); define('TB_MESSAGE', self::$table_prefix . 'message');
} }
if (!defined('TB_EDITED_MESSAGE')) { if (!defined('TB_EDITED_MESSAGE')) {
define('TB_EDITED_MESSAGE', self::$table_prefix.'edited_message'); define('TB_EDITED_MESSAGE', self::$table_prefix . 'edited_message');
} }
if (!defined('TB_INLINE_QUERY')) { if (!defined('TB_INLINE_QUERY')) {
define('TB_INLINE_QUERY', self::$table_prefix.'inline_query'); define('TB_INLINE_QUERY', self::$table_prefix . 'inline_query');
} }
if (!defined('TB_CHOSEN_INLINE_RESULT')) { if (!defined('TB_CHOSEN_INLINE_RESULT')) {
define('TB_CHOSEN_INLINE_RESULT', self::$table_prefix.'chosen_inline_result'); define('TB_CHOSEN_INLINE_RESULT', self::$table_prefix . 'chosen_inline_result');
} }
if (!defined('TB_CALLBACK_QUERY')) { if (!defined('TB_CALLBACK_QUERY')) {
define('TB_CALLBACK_QUERY', self::$table_prefix.'callback_query'); define('TB_CALLBACK_QUERY', self::$table_prefix . 'callback_query');
} }
if (!defined('TB_USER')) { if (!defined('TB_USER')) {
define('TB_USER', self::$table_prefix.'user'); define('TB_USER', self::$table_prefix . 'user');
} }
if (!defined('TB_CHAT')) { if (!defined('TB_CHAT')) {
define('TB_CHAT', self::$table_prefix.'chat'); define('TB_CHAT', self::$table_prefix . 'chat');
} }
if (!defined('TB_USER_CHAT')) { if (!defined('TB_USER_CHAT')) {
define('TB_USER_CHAT', self::$table_prefix.'user_chat'); define('TB_USER_CHAT', self::$table_prefix . 'user_chat');
} }
} }
...@@ -179,7 +174,7 @@ class DB ...@@ -179,7 +174,7 @@ class DB
* @param int $limit Limit the number of updates to fetch * @param int $limit Limit the number of updates to fetch
* *
* @return array|bool Fetched data or false if not connected * @return array|bool Fetched data or false if not connected
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function selectTelegramUpdate($limit = null) public static function selectTelegramUpdate($limit = null)
{ {
...@@ -196,10 +191,10 @@ class DB ...@@ -196,10 +191,10 @@ class DB
} }
$sth_select_telegram_update = self::$pdo->prepare($query); $sth_select_telegram_update = self::$pdo->prepare($query);
$sth_select_telegram_update->bindParam(':limit', $limit, \PDO::PARAM_INT); $sth_select_telegram_update->bindParam(':limit', $limit, PDO::PARAM_INT);
$sth_select_telegram_update->execute(); $sth_select_telegram_update->execute();
$results = $sth_select_telegram_update->fetchAll(\PDO::FETCH_ASSOC); $results = $sth_select_telegram_update->fetchAll(PDO::FETCH_ASSOC);
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
...@@ -212,7 +207,7 @@ class DB ...@@ -212,7 +207,7 @@ class DB
* @param int $limit Limit the number of messages to fetch * @param int $limit Limit the number of messages to fetch
* *
* @return array|bool Fetched data or false if not connected * @return array|bool Fetched data or false if not connected
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function selectMessages($limit = null) public static function selectMessages($limit = null)
{ {
...@@ -231,10 +226,10 @@ class DB ...@@ -231,10 +226,10 @@ class DB
} }
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
$sth->bindParam(':limit', $limit, \PDO::PARAM_INT); $sth->bindParam(':limit', $limit, PDO::PARAM_INT);
$sth->execute(); $sth->execute();
$results = $sth->fetchAll(\PDO::FETCH_ASSOC); $results = $sth->fetchAll(PDO::FETCH_ASSOC);
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
...@@ -268,10 +263,17 @@ class DB ...@@ -268,10 +263,17 @@ class DB
* @param int $edited_message_id * @param int $edited_message_id
* *
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertTelegramUpdate($id, $chat_id, $message_id, $inline_query_id, $chosen_inline_result_id, $callback_query_id, $edited_message_id) public static function insertTelegramUpdate(
{ $id,
$chat_id,
$message_id,
$inline_query_id,
$chosen_inline_result_id,
$callback_query_id,
$edited_message_id
) {
if (is_null($message_id) && is_null($inline_query_id) && is_null($chosen_inline_result_id) && is_null($callback_query_id) && is_null($edited_message_id)) { if (is_null($message_id) && is_null($inline_query_id) && is_null($chosen_inline_result_id) && is_null($callback_query_id) && is_null($edited_message_id)) {
throw new TelegramException('message_id, inline_query_id, chosen_inline_result_id, callback_query_id, edited_message_id are all null'); throw new TelegramException('message_id, inline_query_id, chosen_inline_result_id, callback_query_id, edited_message_id are all null');
} }
...@@ -290,16 +292,17 @@ class DB ...@@ -290,16 +292,17 @@ class DB
) )
'); ');
$sth_insert_telegram_update->bindParam(':id', $id, \PDO::PARAM_INT); $sth_insert_telegram_update->bindParam(':id', $id, PDO::PARAM_INT);
$sth_insert_telegram_update->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT); $sth_insert_telegram_update->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth_insert_telegram_update->bindParam(':message_id', $message_id, \PDO::PARAM_INT); $sth_insert_telegram_update->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth_insert_telegram_update->bindParam(':inline_query_id', $inline_query_id, \PDO::PARAM_INT); $sth_insert_telegram_update->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
$sth_insert_telegram_update->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, \PDO::PARAM_INT); $sth_insert_telegram_update->bindParam(':chosen_inline_result_id', $chosen_inline_result_id,
$sth_insert_telegram_update->bindParam(':callback_query_id', $callback_query_id, \PDO::PARAM_INT); PDO::PARAM_INT);
$sth_insert_telegram_update->bindParam(':edited_message_id', $edited_message_id, \PDO::PARAM_INT); $sth_insert_telegram_update->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT);
$sth_insert_telegram_update->bindParam(':edited_message_id', $edited_message_id, PDO::PARAM_INT);
return $sth_insert_telegram_update->execute(); return $sth_insert_telegram_update->execute();
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
} }
...@@ -307,12 +310,12 @@ class DB ...@@ -307,12 +310,12 @@ class DB
/** /**
* Insert users and save their connection to chats * Insert users and save their connection to chats
* *
* @param Entities\User $user * @param \Longman\TelegramBot\Entities\User $user
* @param string $date * @param string $date
* @param Entities\Chat $chat * @param \Longman\TelegramBot\Entities\Chat $chat
* *
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertUser(User $user, $date, Chat $chat = null) public static function insertUser(User $user, $date, Chat $chat = null)
{ {
...@@ -320,10 +323,10 @@ class DB ...@@ -320,10 +323,10 @@ class DB
return false; return false;
} }
$user_id = $user->getId(); $user_id = $user->getId();
$username = $user->getUsername(); $username = $user->getUsername();
$first_name = $user->getFirstName(); $first_name = $user->getFirstName();
$last_name = $user->getLastName(); $last_name = $user->getLastName();
try { try {
$sth1 = self::$pdo->prepare('INSERT INTO `' . TB_USER . '` $sth1 = self::$pdo->prepare('INSERT INTO `' . TB_USER . '`
...@@ -337,14 +340,14 @@ class DB ...@@ -337,14 +340,14 @@ class DB
`last_name`=:last_name, `updated_at`=:date `last_name`=:last_name, `updated_at`=:date
'); ');
$sth1->bindParam(':id', $user_id, \PDO::PARAM_INT); $sth1->bindParam(':id', $user_id, PDO::PARAM_INT);
$sth1->bindParam(':username', $username, \PDO::PARAM_STR, 255); $sth1->bindParam(':username', $username, PDO::PARAM_STR, 255);
$sth1->bindParam(':first_name', $first_name, \PDO::PARAM_STR, 255); $sth1->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255);
$sth1->bindParam(':last_name', $last_name, \PDO::PARAM_STR, 255); $sth1->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255);
$sth1->bindParam(':date', $date, \PDO::PARAM_STR); $sth1->bindParam(':date', $date, PDO::PARAM_STR);
$status = $sth1->execute(); $status = $sth1->execute();
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
...@@ -360,11 +363,11 @@ class DB ...@@ -360,11 +363,11 @@ class DB
:user_id, :chat_id :user_id, :chat_id
)'); )');
$sth3->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth3->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth3->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT); $sth3->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$status = $sth3->execute(); $status = $sth3->execute();
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
} }
...@@ -375,12 +378,12 @@ class DB ...@@ -375,12 +378,12 @@ class DB
/** /**
* Insert chat * Insert chat
* *
* @param Entities\Chat $chat * @param \Longman\TelegramBot\Entities\Chat $chat
* @param string $date * @param string $date
* @param int $migrate_to_chat_id * @param int $migrate_to_chat_id
* *
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertChat(Chat $chat, $date, $migrate_to_chat_id = null) public static function insertChat(Chat $chat, $date, $migrate_to_chat_id = null)
{ {
...@@ -388,9 +391,9 @@ class DB ...@@ -388,9 +391,9 @@ class DB
return false; return false;
} }
$chat_id = $chat->getId(); $chat_id = $chat->getId();
$chat_title = $chat->getTitle(); $chat_title = $chat->getTitle();
$type = $chat->getType(); $type = $chat->getType();
try { try {
$sth2 = self::$pdo->prepare('INSERT INTO `' . TB_CHAT . '` $sth2 = self::$pdo->prepare('INSERT INTO `' . TB_CHAT . '`
...@@ -406,19 +409,19 @@ class DB ...@@ -406,19 +409,19 @@ class DB
if ($migrate_to_chat_id) { if ($migrate_to_chat_id) {
$type = 'supergroup'; $type = 'supergroup';
$sth2->bindParam(':id', $migrate_to_chat_id, \PDO::PARAM_INT); $sth2->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_INT);
$sth2->bindParam(':oldid', $chat_id, \PDO::PARAM_INT); $sth2->bindParam(':oldid', $chat_id, PDO::PARAM_INT);
} else { } else {
$sth2->bindParam(':id', $chat_id, \PDO::PARAM_INT); $sth2->bindParam(':id', $chat_id, PDO::PARAM_INT);
$sth2->bindParam(':oldid', $migrate_to_chat_id, \PDO::PARAM_INT); $sth2->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_INT);
} }
$sth2->bindParam(':type', $type, \PDO::PARAM_INT); $sth2->bindParam(':type', $type, PDO::PARAM_INT);
$sth2->bindParam(':title', $chat_title, \PDO::PARAM_STR, 255); $sth2->bindParam(':title', $chat_title, PDO::PARAM_STR, 255);
$sth2->bindParam(':date', $date, \PDO::PARAM_STR); $sth2->bindParam(':date', $date, PDO::PARAM_STR);
return $sth2->execute(); return $sth2->execute();
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
} }
...@@ -428,11 +431,11 @@ class DB ...@@ -428,11 +431,11 @@ class DB
* *
* @todo self::$pdo->lastInsertId() - unsafe usage if expected previous insert fails? * @todo self::$pdo->lastInsertId() - unsafe usage if expected previous insert fails?
* *
* @param Entities\Update &$update * @param \Longman\TelegramBot\Entities\Update $update
* *
* @return bool * @return bool
*/ */
public static function insertRequest(Update &$update) public static function insertRequest(Update $update)
{ {
$update_id = $update->getUpdateId(); $update_id = $update->getUpdateId();
if ($update->getUpdateType() == 'message') { if ($update->getUpdateType() == 'message') {
...@@ -440,7 +443,7 @@ class DB ...@@ -440,7 +443,7 @@ class DB
if (self::insertMessageRequest($message)) { if (self::insertMessageRequest($message)) {
$message_id = $message->getMessageId(); $message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
return self::insertTelegramUpdate($update_id, $chat_id, $message_id, null, null, null, null); return self::insertTelegramUpdate($update_id, $chat_id, $message_id, null, null, null, null);
} }
} elseif ($update->getUpdateType() == 'inline_query') { } elseif ($update->getUpdateType() == 'inline_query') {
...@@ -455,7 +458,8 @@ class DB ...@@ -455,7 +458,8 @@ class DB
if (self::insertChosenInlineResultRequest($chosen_inline_result)) { if (self::insertChosenInlineResultRequest($chosen_inline_result)) {
$chosen_inline_result_local_id = self::$pdo->lastInsertId(); $chosen_inline_result_local_id = self::$pdo->lastInsertId();
return self::insertTelegramUpdate($update_id, null, null, null, $chosen_inline_result_local_id, null, null); return self::insertTelegramUpdate($update_id, null, null, null, $chosen_inline_result_local_id, null,
null);
} }
} elseif ($update->getUpdateType() == 'callback_query') { } elseif ($update->getUpdateType() == 'callback_query') {
$callback_query = $update->getCallbackQuery(); $callback_query = $update->getCallbackQuery();
...@@ -468,9 +472,10 @@ class DB ...@@ -468,9 +472,10 @@ class DB
$edited_message = $update->getEditedMessage(); $edited_message = $update->getEditedMessage();
if (self::insertEditedMessageRequest($edited_message)) { if (self::insertEditedMessageRequest($edited_message)) {
$chat_id = $edited_message->getChat()->getId(); $chat_id = $edited_message->getChat()->getId();
$edited_message_local_id = self::$pdo->lastInsertId(); $edited_message_local_id = self::$pdo->lastInsertId();
return self::insertTelegramUpdate($update_id, $chat_id, null, null, null, null, $edited_message_local_id); return self::insertTelegramUpdate($update_id, $chat_id, null, null, null, null,
$edited_message_local_id);
} }
} }
...@@ -480,12 +485,12 @@ class DB ...@@ -480,12 +485,12 @@ class DB
/** /**
* Insert inline query request into database * Insert inline query request into database
* *
* @param Entities\InlineQuery &$inline_query * @param \Longman\TelegramBot\Entities\InlineQuery $inline_query
* *
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertInlineQueryRequest(InlineQuery &$inline_query) public static function insertInlineQueryRequest(InlineQuery $inline_query)
{ {
if (!self::isDbConnected()) { if (!self::isDbConnected()) {
return false; return false;
...@@ -502,28 +507,28 @@ class DB ...@@ -502,28 +507,28 @@ class DB
$sth_insert_inline_query = self::$pdo->prepare($mysql_query); $sth_insert_inline_query = self::$pdo->prepare($mysql_query);
$date = self::getTimestamp(time()); $date = self::getTimestamp(time());
$inline_query_id = $inline_query->getId(); $inline_query_id = $inline_query->getId();
$from = $inline_query->getFrom(); $from = $inline_query->getFrom();
$user_id = null; $user_id = null;
if (is_object($from)) { if (is_object($from)) {
$user_id = $from->getId(); $user_id = $from->getId();
self::insertUser($from, $date); self::insertUser($from, $date);
} }
$location = $inline_query->getLocation(); $location = $inline_query->getLocation();
$query = $inline_query->getQuery(); $query = $inline_query->getQuery();
$offset = $inline_query->getOffset(); $offset = $inline_query->getOffset();
$sth_insert_inline_query->bindParam(':inline_query_id', $inline_query_id, \PDO::PARAM_INT); $sth_insert_inline_query->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
$sth_insert_inline_query->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth_insert_inline_query->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth_insert_inline_query->bindParam(':location', $location, \PDO::PARAM_STR); $sth_insert_inline_query->bindParam(':location', $location, PDO::PARAM_STR);
$sth_insert_inline_query->bindParam(':query', $query, \PDO::PARAM_STR); $sth_insert_inline_query->bindParam(':query', $query, PDO::PARAM_STR);
$sth_insert_inline_query->bindParam(':param_offset', $offset, \PDO::PARAM_STR); $sth_insert_inline_query->bindParam(':param_offset', $offset, PDO::PARAM_STR);
$sth_insert_inline_query->bindParam(':created_at', $date, \PDO::PARAM_STR); $sth_insert_inline_query->bindParam(':created_at', $date, PDO::PARAM_STR);
return $sth_insert_inline_query->execute(); return $sth_insert_inline_query->execute();
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
} }
...@@ -531,12 +536,12 @@ class DB ...@@ -531,12 +536,12 @@ class DB
/** /**
* Insert chosen inline result request into database * Insert chosen inline result request into database
* *
* @param Entities\ChosenInlineResult &$chosen_inline_result * @param \Longman\TelegramBot\Entities\ChosenInlineResult $chosen_inline_result
* *
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertChosenInlineResultRequest(ChosenInlineResult &$chosen_inline_result) public static function insertChosenInlineResultRequest(ChosenInlineResult $chosen_inline_result)
{ {
if (!self::isDbConnected()) { if (!self::isDbConnected()) {
return false; return false;
...@@ -553,28 +558,28 @@ class DB ...@@ -553,28 +558,28 @@ class DB
$sth_insert_chosen_inline_result = self::$pdo->prepare($mysql_query); $sth_insert_chosen_inline_result = self::$pdo->prepare($mysql_query);
$date = self::getTimestamp(time()); $date = self::getTimestamp(time());
$result_id = $chosen_inline_result->getResultId(); $result_id = $chosen_inline_result->getResultId();
$from = $chosen_inline_result->getFrom(); $from = $chosen_inline_result->getFrom();
$user_id = null; $user_id = null;
if (is_object($from)) { if (is_object($from)) {
$user_id = $from->getId(); $user_id = $from->getId();
self::insertUser($from, $date); self::insertUser($from, $date);
} }
$location = $chosen_inline_result->getLocation(); $location = $chosen_inline_result->getLocation();
$inline_message_id = $chosen_inline_result->getInlineMessageId(); $inline_message_id = $chosen_inline_result->getInlineMessageId();
$query = $chosen_inline_result->getQuery(); $query = $chosen_inline_result->getQuery();
$sth_insert_chosen_inline_result->bindParam(':result_id', $result_id, \PDO::PARAM_STR); $sth_insert_chosen_inline_result->bindParam(':result_id', $result_id, PDO::PARAM_STR);
$sth_insert_chosen_inline_result->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth_insert_chosen_inline_result->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth_insert_chosen_inline_result->bindParam(':location', $location, \PDO::PARAM_INT); $sth_insert_chosen_inline_result->bindParam(':location', $location, PDO::PARAM_INT);
$sth_insert_chosen_inline_result->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR); $sth_insert_chosen_inline_result->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth_insert_chosen_inline_result->bindParam(':query', $query, \PDO::PARAM_STR); $sth_insert_chosen_inline_result->bindParam(':query', $query, PDO::PARAM_STR);
$sth_insert_chosen_inline_result->bindParam(':created_at', $date, \PDO::PARAM_STR); $sth_insert_chosen_inline_result->bindParam(':created_at', $date, PDO::PARAM_STR);
return $sth_insert_chosen_inline_result->execute(); return $sth_insert_chosen_inline_result->execute();
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
} }
...@@ -582,12 +587,12 @@ class DB ...@@ -582,12 +587,12 @@ class DB
/** /**
* Insert callback query request into database * Insert callback query request into database
* *
* @param Entities\CallbackQuery &$callback_query * @param \Longman\TelegramBot\Entities\CallbackQuery $callback_query
* *
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertCallbackQueryRequest(CallbackQuery &$callback_query) public static function insertCallbackQueryRequest(CallbackQuery $callback_query)
{ {
if (!self::isDbConnected()) { if (!self::isDbConnected()) {
return false; return false;
...@@ -607,18 +612,18 @@ class DB ...@@ -607,18 +612,18 @@ class DB
$date = self::getTimestamp(time()); $date = self::getTimestamp(time());
$callback_query_id = $callback_query->getId(); $callback_query_id = $callback_query->getId();
$from = $callback_query->getFrom(); $from = $callback_query->getFrom();
$user_id = null; $user_id = null;
if (is_object($from)) { if (is_object($from)) {
$user_id = $from->getId(); $user_id = $from->getId();
self::insertUser($from, $date); self::insertUser($from, $date);
} }
$message = $callback_query->getMessage(); $message = $callback_query->getMessage();
$chat_id = null; $chat_id = null;
$message_id = null; $message_id = null;
if ($message) { if ($message) {
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId(); $message_id = $message->getMessageId();
$sth = self::$pdo->prepare('SELECT * FROM `' . TB_MESSAGE . '` $sth = self::$pdo->prepare('SELECT * FROM `' . TB_MESSAGE . '`
...@@ -633,18 +638,18 @@ class DB ...@@ -633,18 +638,18 @@ class DB
} }
$inline_message_id = $callback_query->getInlineMessageId(); $inline_message_id = $callback_query->getInlineMessageId();
$data = $callback_query->getData(); $data = $callback_query->getData();
$sth_insert_callback_query->bindParam(':callback_query_id', $callback_query_id, \PDO::PARAM_INT); $sth_insert_callback_query->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth_insert_callback_query->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT); $sth_insert_callback_query->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':message_id', $message_id, \PDO::PARAM_INT); $sth_insert_callback_query->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth_insert_callback_query->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR); $sth_insert_callback_query->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth_insert_callback_query->bindParam(':data', $data, \PDO::PARAM_STR); $sth_insert_callback_query->bindParam(':data', $data, PDO::PARAM_STR);
$sth_insert_callback_query->bindParam(':created_at', $date, \PDO::PARAM_STR); $sth_insert_callback_query->bindParam(':created_at', $date, PDO::PARAM_STR);
return $sth_insert_callback_query->execute(); return $sth_insert_callback_query->execute();
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
} }
...@@ -652,12 +657,12 @@ class DB ...@@ -652,12 +657,12 @@ class DB
/** /**
* Insert Message request in db * Insert Message request in db
* *
* @param Entities\Message &$message * @param \Longman\TelegramBot\Entities\Message $message
* *
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertMessageRequest(Message &$message) public static function insertMessageRequest(Message $message)
{ {
if (!self::isDbConnected()) { if (!self::isDbConnected()) {
return false; return false;
...@@ -670,13 +675,13 @@ class DB ...@@ -670,13 +675,13 @@ class DB
$date = self::getTimestamp($message->getDate()); $date = self::getTimestamp($message->getDate());
$forward_from = $message->getForwardFrom(); $forward_from = $message->getForwardFrom();
$forward_from_chat = $message->getForwardFromChat(); $forward_from_chat = $message->getForwardFromChat();
$photo = $message->getPhoto(); $photo = $message->getPhoto();
$entities = $message->getEntities(); $entities = $message->getEntities();
$new_chat_member = $message->getNewChatMember(); $new_chat_member = $message->getNewChatMember();
$new_chat_photo = $message->getNewChatPhoto(); $new_chat_photo = $message->getNewChatPhoto();
$left_chat_member = $message->getLeftChatMember(); $left_chat_member = $message->getLeftChatMember();
$migrate_to_chat_id = $message->getMigrateToChatId(); $migrate_to_chat_id = $message->getMigrateToChatId();
//Insert chat, update chat id in case it migrated //Insert chat, update chat id in case it migrated
...@@ -732,9 +737,9 @@ class DB ...@@ -732,9 +737,9 @@ class DB
'); ');
$message_id = $message->getMessageId(); $message_id = $message->getMessageId();
$from_id = $from->getId(); $from_id = $from->getId();
$reply_to_message = $message->getReplyToMessage(); $reply_to_message = $message->getReplyToMessage();
$reply_to_message_id = null; $reply_to_message_id = null;
if (is_object($reply_to_message)) { if (is_object($reply_to_message)) {
$reply_to_message_id = $reply_to_message->getMessageId(); $reply_to_message_id = $reply_to_message->getMessageId();
...@@ -743,32 +748,32 @@ class DB ...@@ -743,32 +748,32 @@ class DB
self::insertMessageRequest($reply_to_message); self::insertMessageRequest($reply_to_message);
} }
$text = $message->getText(); $text = $message->getText();
$audio = $message->getAudio(); $audio = $message->getAudio();
$document = $message->getDocument(); $document = $message->getDocument();
$sticker = $message->getSticker(); $sticker = $message->getSticker();
$video = $message->getVideo(); $video = $message->getVideo();
$voice = $message->getVoice(); $voice = $message->getVoice();
$caption = $message->getCaption(); $caption = $message->getCaption();
$contact = $message->getContact(); $contact = $message->getContact();
$location = $message->getLocation(); $location = $message->getLocation();
$venue = $message->getVenue(); $venue = $message->getVenue();
$new_chat_title = $message->getNewChatTitle(); $new_chat_title = $message->getNewChatTitle();
$delete_chat_photo = $message->getDeleteChatPhoto(); $delete_chat_photo = $message->getDeleteChatPhoto();
$group_chat_created = $message->getGroupChatCreated(); $group_chat_created = $message->getGroupChatCreated();
$supergroup_chat_created = $message->getSupergroupChatCreated(); $supergroup_chat_created = $message->getSupergroupChatCreated();
$channel_chat_created = $message->getChannelChatCreated(); $channel_chat_created = $message->getChannelChatCreated();
$migrate_from_chat_id = $message->getMigrateFromChatId(); $migrate_from_chat_id = $message->getMigrateFromChatId();
$migrate_to_chat_id = $message->getMigrateToChatId(); $migrate_to_chat_id = $message->getMigrateToChatId();
$pinned_message = $message->getPinnedMessage(); $pinned_message = $message->getPinnedMessage();
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $from_id, \PDO::PARAM_INT); $sth->bindParam(':user_id', $from_id, PDO::PARAM_INT);
$sth->bindParam(':date', $date, \PDO::PARAM_STR); $sth->bindParam(':date', $date, PDO::PARAM_STR);
$sth->bindParam(':forward_from', $forward_from, \PDO::PARAM_INT); $sth->bindParam(':forward_from', $forward_from, PDO::PARAM_INT);
$sth->bindParam(':forward_from_chat', $forward_from_chat, \PDO::PARAM_INT); $sth->bindParam(':forward_from_chat', $forward_from_chat, PDO::PARAM_INT);
$sth->bindParam(':forward_date', $forward_date, \PDO::PARAM_STR); $sth->bindParam(':forward_date', $forward_date, PDO::PARAM_STR);
$reply_chat_id = null; $reply_chat_id = null;
if ($reply_to_message_id) { if ($reply_to_message_id) {
...@@ -786,12 +791,12 @@ class DB ...@@ -786,12 +791,12 @@ class DB
$entities = null; $entities = null;
} }
$sth->bindParam(':reply_to_chat', $reply_chat_id, \PDO::PARAM_INT); $sth->bindParam(':reply_to_chat', $reply_chat_id, PDO::PARAM_INT);
$sth->bindParam(':reply_to_message', $reply_to_message_id, \PDO::PARAM_INT); $sth->bindParam(':reply_to_message', $reply_to_message_id, PDO::PARAM_INT);
$sth->bindParam(':text', $text, \PDO::PARAM_STR); $sth->bindParam(':text', $text, PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, \PDO::PARAM_STR); $sth->bindParam(':entities', $entities, PDO::PARAM_STR);
$sth->bindParam(':audio', $audio, \PDO::PARAM_STR); $sth->bindParam(':audio', $audio, PDO::PARAM_STR);
$sth->bindParam(':document', $document, \PDO::PARAM_STR); $sth->bindParam(':document', $document, PDO::PARAM_STR);
$var = []; $var = [];
if (is_array($photo)) { if (is_array($photo)) {
...@@ -804,17 +809,17 @@ class DB ...@@ -804,17 +809,17 @@ class DB
$photo = ''; $photo = '';
} }
$sth->bindParam(':photo', $photo, \PDO::PARAM_STR); $sth->bindParam(':photo', $photo, PDO::PARAM_STR);
$sth->bindParam(':sticker', $sticker, \PDO::PARAM_STR); $sth->bindParam(':sticker', $sticker, PDO::PARAM_STR);
$sth->bindParam(':video', $video, \PDO::PARAM_STR); $sth->bindParam(':video', $video, PDO::PARAM_STR);
$sth->bindParam(':voice', $voice, \PDO::PARAM_STR); $sth->bindParam(':voice', $voice, PDO::PARAM_STR);
$sth->bindParam(':caption', $caption, \PDO::PARAM_STR); $sth->bindParam(':caption', $caption, PDO::PARAM_STR);
$sth->bindParam(':contact', $contact, \PDO::PARAM_STR); $sth->bindParam(':contact', $contact, PDO::PARAM_STR);
$sth->bindParam(':location', $location, \PDO::PARAM_STR); $sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':venue', $venue, \PDO::PARAM_STR); $sth->bindParam(':venue', $venue, PDO::PARAM_STR);
$sth->bindParam(':new_chat_member', $new_chat_member, \PDO::PARAM_INT); $sth->bindParam(':new_chat_member', $new_chat_member, PDO::PARAM_INT);
$sth->bindParam(':left_chat_member', $left_chat_member, \PDO::PARAM_INT); $sth->bindParam(':left_chat_member', $left_chat_member, PDO::PARAM_INT);
$sth->bindParam(':new_chat_title', $new_chat_title, \PDO::PARAM_STR); $sth->bindParam(':new_chat_title', $new_chat_title, PDO::PARAM_STR);
//Array of PhotoSize //Array of PhotoSize
$var = []; $var = [];
...@@ -828,17 +833,17 @@ class DB ...@@ -828,17 +833,17 @@ class DB
$new_chat_photo = ''; $new_chat_photo = '';
} }
$sth->bindParam(':new_chat_photo', $new_chat_photo, \PDO::PARAM_STR); $sth->bindParam(':new_chat_photo', $new_chat_photo, PDO::PARAM_STR);
$sth->bindParam(':delete_chat_photo', $delete_chat_photo, \PDO::PARAM_STR); $sth->bindParam(':delete_chat_photo', $delete_chat_photo, PDO::PARAM_STR);
$sth->bindParam(':group_chat_created', $group_chat_created, \PDO::PARAM_STR); $sth->bindParam(':group_chat_created', $group_chat_created, PDO::PARAM_STR);
$sth->bindParam(':supergroup_chat_created', $supergroup_chat_created, \PDO::PARAM_INT); $sth->bindParam(':supergroup_chat_created', $supergroup_chat_created, PDO::PARAM_INT);
$sth->bindParam(':channel_chat_created', $channel_chat_created, \PDO::PARAM_INT); $sth->bindParam(':channel_chat_created', $channel_chat_created, PDO::PARAM_INT);
$sth->bindParam(':migrate_from_chat_id', $migrate_from_chat_id, \PDO::PARAM_INT); $sth->bindParam(':migrate_from_chat_id', $migrate_from_chat_id, PDO::PARAM_INT);
$sth->bindParam(':migrate_to_chat_id', $migrate_to_chat_id, \PDO::PARAM_INT); $sth->bindParam(':migrate_to_chat_id', $migrate_to_chat_id, PDO::PARAM_INT);
$sth->bindParam(':pinned_message', $pinned_message, \PDO::PARAM_INT); $sth->bindParam(':pinned_message', $pinned_message, PDO::PARAM_INT);
return $sth->execute(); return $sth->execute();
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
} }
...@@ -846,12 +851,12 @@ class DB ...@@ -846,12 +851,12 @@ class DB
/** /**
* Insert Edited Message request in db * Insert Edited Message request in db
* *
* @param Entities\Message &$edited_message * @param \Longman\TelegramBot\Entities\Message $edited_message
* *
* @return bool If the insert was successful * @return bool If the insert was successful
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertEditedMessageRequest(Message &$edited_message) public static function insertEditedMessageRequest(Message $edited_message)
{ {
if (!self::isDbConnected()) { if (!self::isDbConnected()) {
return false; return false;
...@@ -882,15 +887,15 @@ class DB ...@@ -882,15 +887,15 @@ class DB
)'); )');
$message_id = $edited_message->getMessageId(); $message_id = $edited_message->getMessageId();
$from_id = $from->getId(); $from_id = $from->getId();
$text = $edited_message->getText(); $text = $edited_message->getText();
$caption = $edited_message->getCaption(); $caption = $edited_message->getCaption();
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $from_id, \PDO::PARAM_INT); $sth->bindParam(':user_id', $from_id, PDO::PARAM_INT);
$sth->bindParam(':date', $edit_date, \PDO::PARAM_STR); $sth->bindParam(':date', $edit_date, PDO::PARAM_STR);
$var = []; $var = [];
if (is_array($entities)) { if (is_array($entities)) {
...@@ -903,12 +908,12 @@ class DB ...@@ -903,12 +908,12 @@ class DB
$entities = null; $entities = null;
} }
$sth->bindParam(':text', $text, \PDO::PARAM_STR); $sth->bindParam(':text', $text, PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, \PDO::PARAM_STR); $sth->bindParam(':entities', $entities, PDO::PARAM_STR);
$sth->bindParam(':caption', $caption, \PDO::PARAM_STR); $sth->bindParam(':caption', $caption, PDO::PARAM_STR);
return $sth->execute(); return $sth->execute();
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
} }
...@@ -916,16 +921,16 @@ class DB ...@@ -916,16 +921,16 @@ class DB
/** /**
* Select Group and/or single Chats * Select Group and/or single Chats
* *
* @param bool $select_groups * @param bool $select_groups
* @param bool $select_super_groups * @param bool $select_super_groups
* @param bool $select_users * @param bool $select_users
* @param string $date_from * @param string $date_from
* @param string $date_to * @param string $date_to
* @param int $chat_id * @param int $chat_id
* @param string $text * @param string $text
* *
* @return array|bool (Selected chats or false if invalid arguments) * @return array|bool (Selected chats or false if invalid arguments)
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function selectChats( public static function selectChats(
$select_groups = true, $select_groups = true,
...@@ -940,7 +945,7 @@ class DB ...@@ -940,7 +945,7 @@ class DB
return false; return false;
} }
if (!$select_groups & !$select_users & !$select_super_groups) { if (!$select_groups && !$select_users && !$select_super_groups) {
return false; return false;
} }
...@@ -954,7 +959,7 @@ class DB ...@@ -954,7 +959,7 @@ class DB
ON ' . TB_CHAT . '.`id`=' . TB_USER . '.`id`' : 'FROM `' . TB_CHAT . '`'); ON ' . TB_CHAT . '.`id`=' . TB_USER . '.`id`' : 'FROM `' . TB_CHAT . '`');
//Building parts of query //Building parts of query
$where = []; $where = [];
$tokens = []; $tokens = [];
if (!$select_groups || !$select_users || !$select_super_groups) { if (!$select_groups || !$select_users || !$select_super_groups) {
...@@ -983,29 +988,29 @@ class DB ...@@ -983,29 +988,29 @@ class DB
$where[] = '(' . $chat_or_user . ')'; $where[] = '(' . $chat_or_user . ')';
} }
if (! is_null($date_from)) { if (!is_null($date_from)) {
$where[] = TB_CHAT . '.`updated_at` >= :date_from'; $where[] = TB_CHAT . '.`updated_at` >= :date_from';
$tokens[':date_from'] = $date_from; $tokens[':date_from'] = $date_from;
} }
if (! is_null($date_to)) { if (!is_null($date_to)) {
$where[] = TB_CHAT . '.`updated_at` <= :date_to'; $where[] = TB_CHAT . '.`updated_at` <= :date_to';
$tokens[':date_to'] = $date_to; $tokens[':date_to'] = $date_to;
} }
if (! is_null($chat_id)) { if (!is_null($chat_id)) {
$where[] = TB_CHAT . '.`id` = :chat_id'; $where[] = TB_CHAT . '.`id` = :chat_id';
$tokens[':chat_id'] = $chat_id; $tokens[':chat_id'] = $chat_id;
} }
if (! is_null($text)) { if (!is_null($text)) {
if ($select_users) { if ($select_users) {
$where[] = '(LOWER('.TB_CHAT . '.`title`) LIKE :text OR LOWER(' . TB_USER . '.`first_name`) LIKE :text OR LOWER(' . TB_USER . '.`last_name`) LIKE :text OR LOWER(' . TB_USER . '.`username`) LIKE :text)'; $where[] = '(LOWER(' . TB_CHAT . '.`title`) LIKE :text OR LOWER(' . TB_USER . '.`first_name`) LIKE :text OR LOWER(' . TB_USER . '.`last_name`) LIKE :text OR LOWER(' . TB_USER . '.`username`) LIKE :text)';
} else { } else {
$where[] = 'LOWER('.TB_CHAT . '.`title`) LIKE :text'; $where[] = 'LOWER(' . TB_CHAT . '.`title`) LIKE :text';
} }
$tokens[':text'] = '%'.strtolower($text).'%'; $tokens[':text'] = '%' . strtolower($text) . '%';
} }
$a = 0; $a = 0;
...@@ -1023,8 +1028,8 @@ class DB ...@@ -1023,8 +1028,8 @@ class DB
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
$sth->execute($tokens); $sth->execute($tokens);
$result = $sth->fetchAll(\PDO::FETCH_ASSOC); $result = $sth->fetchAll(PDO::FETCH_ASSOC);
} catch (\PDOException $e) { } catch (PDOException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
......
...@@ -21,7 +21,7 @@ class Request ...@@ -21,7 +21,7 @@ class Request
/** /**
* Telegram object * Telegram object
* *
* @var Telegram * @var \Longman\TelegramBot\Telegram
*/ */
private static $telegram; private static $telegram;
...@@ -86,13 +86,14 @@ class Request ...@@ -86,13 +86,14 @@ class Request
/** /**
* Initialize * Initialize
* *
* @param Telegram $telegram * @param \Longman\TelegramBot\Telegram $telegram
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function initialize(Telegram $telegram) public static function initialize(Telegram $telegram)
{ {
if (is_object($telegram)) { if (is_object($telegram)) {
self::$telegram = $telegram; self::$telegram = $telegram;
self::$client = new Client(['base_uri' => self::$api_base_uri]); self::$client = new Client(['base_uri' => self::$api_base_uri]);
} else { } else {
throw new TelegramException('Telegram pointer is empty!'); throw new TelegramException('Telegram pointer is empty!');
} }
...@@ -102,6 +103,7 @@ class Request ...@@ -102,6 +103,7 @@ class Request
* Set input from custom input or stdin and return it * Set input from custom input or stdin and return it
* *
* @return string * @return string
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getInput() public static function getInput()
{ {
...@@ -145,13 +147,13 @@ class Request ...@@ -145,13 +147,13 @@ class Request
//some data to let iniatilize the class method SendMessage //some data to let iniatilize the class method SendMessage
if (isset($data['chat_id'])) { if (isset($data['chat_id'])) {
$data['message_id'] = '1234'; $data['message_id'] = '1234';
$data['date'] = '1441378360'; $data['date'] = '1441378360';
$data['from'] = [ $data['from'] = [
'id' => 123456789, 'id' => 123456789,
'first_name' => 'botname', 'first_name' => 'botname',
'username' => 'namebot', 'username' => 'namebot',
]; ];
$data['chat'] = ['id' => $data['chat_id']]; $data['chat'] = ['id' => $data['chat_id']];
$fake_response['result'] = $data; $fake_response['result'] = $data;
} }
...@@ -166,6 +168,7 @@ class Request ...@@ -166,6 +168,7 @@ class Request
* @param array|null $data Data to attach to the execution * @param array|null $data Data to attach to the execution
* *
* @return mixed Result of the HTTP Request * @return mixed Result of the HTTP Request
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function execute($action, array $data = null) public static function execute($action, array $data = null)
{ {
...@@ -224,6 +227,7 @@ class Request ...@@ -224,6 +227,7 @@ class Request
* @param Entities\File $file * @param Entities\File $file
* *
* @return boolean * @return boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function downloadFile(File $file) public static function downloadFile(File $file)
{ {
...@@ -260,6 +264,7 @@ class Request ...@@ -260,6 +264,7 @@ class Request
* @param string $file * @param string $file
* *
* @return resource * @return resource
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
protected static function encodeFile($file) protected static function encodeFile($file)
{ {
...@@ -278,7 +283,8 @@ class Request ...@@ -278,7 +283,8 @@ class Request
* @param string $action * @param string $action
* @param array|null $data * @param array|null $data
* *
* @return Entities\ServerResponse * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function send($action, array $data = null) public static function send($action, array $data = null)
{ {
...@@ -322,13 +328,14 @@ class Request ...@@ -322,13 +328,14 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendMessage(array $data) public static function sendMessage(array $data)
{ {
if (empty($data)) { if (empty($data)) {
throw new TelegramException('Data is empty!'); throw new TelegramException('Data is empty!');
} }
$text = $data['text']; $text = $data['text'];
$string_len_utf8 = mb_strlen($text, 'UTF-8'); $string_len_utf8 = mb_strlen($text, 'UTF-8');
if ($string_len_utf8 > 4096) { if ($string_len_utf8 > 4096) {
$data['text'] = mb_substr($text, 0, 4096); $data['text'] = mb_substr($text, 0, 4096);
...@@ -345,6 +352,7 @@ class Request ...@@ -345,6 +352,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function forwardMessage(array $data) public static function forwardMessage(array $data)
{ {
...@@ -358,10 +366,11 @@ class Request ...@@ -358,10 +366,11 @@ class Request
/** /**
* Send photo * Send photo
* *
* @param array $data * @param array $data
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendPhoto(array $data, $file = null) public static function sendPhoto(array $data, $file = null)
{ {
...@@ -383,6 +392,7 @@ class Request ...@@ -383,6 +392,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendAudio(array $data, $file = null) public static function sendAudio(array $data, $file = null)
{ {
...@@ -404,6 +414,7 @@ class Request ...@@ -404,6 +414,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendDocument(array $data, $file = null) public static function sendDocument(array $data, $file = null)
{ {
...@@ -425,6 +436,7 @@ class Request ...@@ -425,6 +436,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendSticker(array $data, $file = null) public static function sendSticker(array $data, $file = null)
{ {
...@@ -446,6 +458,7 @@ class Request ...@@ -446,6 +458,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendVideo(array $data, $file = null) public static function sendVideo(array $data, $file = null)
{ {
...@@ -467,6 +480,7 @@ class Request ...@@ -467,6 +480,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendVoice(array $data, $file = null) public static function sendVoice(array $data, $file = null)
{ {
...@@ -487,6 +501,7 @@ class Request ...@@ -487,6 +501,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendLocation(array $data) public static function sendLocation(array $data)
{ {
...@@ -503,6 +518,7 @@ class Request ...@@ -503,6 +518,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendVenue(array $data) public static function sendVenue(array $data)
{ {
...@@ -519,6 +535,7 @@ class Request ...@@ -519,6 +535,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendContact(array $data) public static function sendContact(array $data)
{ {
...@@ -535,6 +552,7 @@ class Request ...@@ -535,6 +552,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendChatAction(array $data) public static function sendChatAction(array $data)
{ {
...@@ -551,6 +569,7 @@ class Request ...@@ -551,6 +569,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getUserProfilePhotos(array $data) public static function getUserProfilePhotos(array $data)
{ {
...@@ -602,6 +621,7 @@ class Request ...@@ -602,6 +621,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getFile(array $data) public static function getFile(array $data)
{ {
...@@ -618,6 +638,7 @@ class Request ...@@ -618,6 +638,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function kickChatMember(array $data) public static function kickChatMember(array $data)
{ {
...@@ -634,6 +655,7 @@ class Request ...@@ -634,6 +655,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function leaveChat(array $data) public static function leaveChat(array $data)
{ {
...@@ -650,6 +672,7 @@ class Request ...@@ -650,6 +672,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function unbanChatMember(array $data) public static function unbanChatMember(array $data)
{ {
...@@ -668,6 +691,7 @@ class Request ...@@ -668,6 +691,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getChat(array $data) public static function getChat(array $data)
{ {
...@@ -686,6 +710,7 @@ class Request ...@@ -686,6 +710,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getChatAdministrators(array $data) public static function getChatAdministrators(array $data)
{ {
...@@ -704,6 +729,7 @@ class Request ...@@ -704,6 +729,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getChatMembersCount(array $data) public static function getChatMembersCount(array $data)
{ {
...@@ -722,6 +748,7 @@ class Request ...@@ -722,6 +748,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getChatMember(array $data) public static function getChatMember(array $data)
{ {
...@@ -738,6 +765,7 @@ class Request ...@@ -738,6 +765,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function answerCallbackQuery(array $data) public static function answerCallbackQuery(array $data)
{ {
...@@ -754,6 +782,7 @@ class Request ...@@ -754,6 +782,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function answerInlineQuery(array $data) public static function answerInlineQuery(array $data)
{ {
...@@ -770,6 +799,7 @@ class Request ...@@ -770,6 +799,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function editMessageText(array $data) public static function editMessageText(array $data)
{ {
...@@ -786,6 +816,7 @@ class Request ...@@ -786,6 +816,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function editMessageCaption(array $data) public static function editMessageCaption(array $data)
{ {
...@@ -802,6 +833,7 @@ class Request ...@@ -802,6 +833,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function editMessageReplyMarkup(array $data) public static function editMessageReplyMarkup(array $data)
{ {
...@@ -837,6 +869,7 @@ class Request ...@@ -837,6 +869,7 @@ class Request
* @param string $date_to * @param string $date_to
* *
* @return array * @return array
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendToActiveChats( public static function sendToActiveChats(
$callback_function, $callback_function,
...@@ -857,7 +890,7 @@ class Request ...@@ -857,7 +890,7 @@ class Request
$results = []; $results = [];
foreach ($chats as $row) { foreach ($chats as $row) {
$data['chat_id'] = $row['chat_id']; $data['chat_id'] = $row['chat_id'];
$results[] = call_user_func_array($callback_path . '::' . $callback_function, [$data]); $results[] = call_user_func_array($callback_path . '::' . $callback_function, [$data]);
} }
return $results; return $results;
......
...@@ -16,7 +16,6 @@ define('BASE_COMMANDS_PATH', BASE_PATH . '/Commands'); ...@@ -16,7 +16,6 @@ define('BASE_COMMANDS_PATH', BASE_PATH . '/Commands');
use Longman\TelegramBot\Entities\Update; use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
class Telegram class Telegram
{ {
/** /**
...@@ -152,6 +151,7 @@ class Telegram ...@@ -152,6 +151,7 @@ class Telegram
* *
* @param array $credential * @param array $credential
* @param string $table_prefix * @param string $table_prefix
* @param string $encoding
* *
* @return \Longman\TelegramBot\Telegram * @return \Longman\TelegramBot\Telegram
*/ */
......
...@@ -15,9 +15,6 @@ use Monolog\Handler\StreamHandler; ...@@ -15,9 +15,6 @@ use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use Longman\TelegramBot\Exception\TelegramLogException; use Longman\TelegramBot\Exception\TelegramLogException;
/**
* Class TelegramLog.
*/
class TelegramLog class TelegramLog
{ {
/** /**
...@@ -99,6 +96,7 @@ class TelegramLog ...@@ -99,6 +96,7 @@ class TelegramLog
* @param string $path * @param string $path
* *
* @return \Monolog\Logger * @return \Monolog\Logger
* @throws \Longman\TelegramBot\Exception\TelegramLogException
*/ */
public static function initErrorLog($path) public static function initErrorLog($path)
{ {
...@@ -120,6 +118,7 @@ class TelegramLog ...@@ -120,6 +118,7 @@ class TelegramLog
* @param string $path * @param string $path
* *
* @return \Monolog\Logger * @return \Monolog\Logger
* @throws \Longman\TelegramBot\Exception\TelegramLogException
*/ */
public static function initDebugLog($path) public static function initDebugLog($path)
{ {
...@@ -162,9 +161,9 @@ class TelegramLog ...@@ -162,9 +161,9 @@ class TelegramLog
if (self::$debug_log_temp_stream_handle !== null) { if (self::$debug_log_temp_stream_handle !== null) {
rewind(self::$debug_log_temp_stream_handle); rewind(self::$debug_log_temp_stream_handle);
self::debug(sprintf( self::debug(sprintf(
$message, $message,
stream_get_contents(self::$debug_log_temp_stream_handle) stream_get_contents(self::$debug_log_temp_stream_handle)
)); ));
fclose(self::$debug_log_temp_stream_handle); fclose(self::$debug_log_temp_stream_handle);
self::$debug_log_temp_stream_handle = null; self::$debug_log_temp_stream_handle = null;
} }
...@@ -179,6 +178,7 @@ class TelegramLog ...@@ -179,6 +178,7 @@ class TelegramLog
* @param string $path * @param string $path
* *
* @return \Monolog\Logger * @return \Monolog\Logger
* @throws \Longman\TelegramBot\Exception\TelegramLogException
*/ */
public static function initUpdateLog($path) public static function initUpdateLog($path)
{ {
...@@ -189,7 +189,7 @@ class TelegramLog ...@@ -189,7 +189,7 @@ class TelegramLog
if (self::$monolog_update === null) { if (self::$monolog_update === null) {
self::$monolog_update = new Logger('bot_update_log'); self::$monolog_update = new Logger('bot_update_log');
// Create a formatter // Create a formatter
$output = "%message%\n"; $output = "%message%\n";
$formatter = new LineFormatter($output); $formatter = new LineFormatter($output);
// Update handler // Update handler
......
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