Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
87e0d1c4
Commit
87e0d1c4
authored
Aug 23, 2016
by
Avtandil Kikabidze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved code and doc-blocks
parent
c6e430a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
37 deletions
+37
-37
Telegram.php
src/Telegram.php
+37
-37
No files found.
src/Telegram.php
View file @
87e0d1c4
...
@@ -16,13 +16,7 @@ define('BASE_COMMANDS_PATH', BASE_PATH . '/Commands');
...
@@ -16,13 +16,7 @@ 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
;
/**
* @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
Telegram
class
Telegram
{
{
/**
/**
...
@@ -63,7 +57,7 @@ class Telegram
...
@@ -63,7 +57,7 @@ class Telegram
/**
/**
* Current Update object
* Current Update object
*
*
* @var Entities\Update
* @var
\Longman\TelegramBot\
Entities\Update
*/
*/
protected
$update
;
protected
$update
;
...
@@ -112,7 +106,7 @@ class Telegram
...
@@ -112,7 +106,7 @@ class Telegram
/**
/**
* ServerResponse of the last Command execution
* ServerResponse of the last Command execution
*
*
* @var Entities\ServerResponse
* @var
\Longman\TelegramBot\
Entities\ServerResponse
*/
*/
protected
$last_command_response
;
protected
$last_command_response
;
...
@@ -124,10 +118,11 @@ class Telegram
...
@@ -124,10 +118,11 @@ class Telegram
protected
$botan_enabled
=
false
;
protected
$botan_enabled
=
false
;
/**
/**
*
Constructor
*
Telegram constructor.
*
*
* @param string $api_key
* @param $api_key
* @param string $bot_name
* @param $bot_name
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
__construct
(
$api_key
,
$bot_name
)
public
function
__construct
(
$api_key
,
$bot_name
)
{
{
...
@@ -139,7 +134,7 @@ class Telegram
...
@@ -139,7 +134,7 @@ class Telegram
throw
new
TelegramException
(
'Bot Username not defined!'
);
throw
new
TelegramException
(
'Bot Username not defined!'
);
}
}
$this
->
api_key
=
$api_key
;
$this
->
api_key
=
$api_key
;
$this
->
bot_name
=
$bot_name
;
$this
->
bot_name
=
$bot_name
;
//Set default download and upload path
//Set default download and upload path
...
@@ -158,7 +153,7 @@ class Telegram
...
@@ -158,7 +153,7 @@ class Telegram
* @param array $credential
* @param array $credential
* @param string $table_prefix
* @param string $table_prefix
*
*
* @return Telegram
* @return
\Longman\TelegramBot\
Telegram
*/
*/
public
function
enableMySql
(
array
$credential
,
$table_prefix
=
null
,
$encoding
=
'utf8mb4'
)
public
function
enableMySql
(
array
$credential
,
$table_prefix
=
null
,
$encoding
=
'utf8mb4'
)
{
{
...
@@ -185,6 +180,7 @@ class Telegram
...
@@ -185,6 +180,7 @@ class Telegram
* Get commands list
* Get commands list
*
*
* @return array $commands
* @return array $commands
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
getCommandsList
()
public
function
getCommandsList
()
{
{
...
@@ -202,7 +198,7 @@ class Telegram
...
@@ -202,7 +198,7 @@ class Telegram
foreach
(
$files
as
$file
)
{
foreach
(
$files
as
$file
)
{
//Remove "Command.php" from filename
//Remove "Command.php" from filename
$command
=
$this
->
sanitizeCommand
(
substr
(
$file
->
getFilename
(),
0
,
-
11
));
$command
=
$this
->
sanitizeCommand
(
substr
(
$file
->
getFilename
(),
0
,
-
11
));
$command_name
=
strtolower
(
$command
);
$command_name
=
strtolower
(
$command
);
if
(
array_key_exists
(
$command_name
,
$commands
))
{
if
(
array_key_exists
(
$command_name
,
$commands
))
{
...
@@ -211,7 +207,6 @@ class Telegram
...
@@ -211,7 +207,6 @@ class Telegram
require_once
$file
->
getPathname
();
require_once
$file
->
getPathname
();
$command_obj
=
$this
->
getCommandObject
(
$command
);
$command_obj
=
$this
->
getCommandObject
(
$command
);
if
(
$command_obj
instanceof
Commands\Command
)
{
if
(
$command_obj
instanceof
Commands\Command
)
{
$commands
[
$command_name
]
=
$command_obj
;
$commands
[
$command_name
]
=
$command_obj
;
...
@@ -274,7 +269,7 @@ class Telegram
...
@@ -274,7 +269,7 @@ class Telegram
/**
/**
* Get the ServerResponse of the last Command execution
* Get the ServerResponse of the last Command execution
*
*
* @return Entities\ServerResponse
* @return
\Longman\TelegramBot\
Entities\ServerResponse
*/
*/
public
function
getLastCommandResponse
()
public
function
getLastCommandResponse
()
{
{
...
@@ -293,9 +288,9 @@ class Telegram
...
@@ -293,9 +288,9 @@ class Telegram
{
{
if
(
!
DB
::
isDbConnected
())
{
if
(
!
DB
::
isDbConnected
())
{
return
new
Entities\ServerResponse
([
return
new
Entities\ServerResponse
([
'ok'
=>
false
,
'ok'
=>
false
,
'description'
=>
'getUpdates needs MySQL connection!'
,
'description'
=>
'getUpdates needs MySQL connection!'
,
],
$this
->
bot_name
);
],
$this
->
bot_name
);
}
}
//DB Query
//DB Query
...
@@ -305,14 +300,14 @@ class Telegram
...
@@ -305,14 +300,14 @@ class Telegram
$offset
=
(
isset
(
$last_update
[
0
][
'id'
]))
?
$last_update
[
0
][
'id'
]
+
1
:
null
;
$offset
=
(
isset
(
$last_update
[
0
][
'id'
]))
?
$last_update
[
0
][
'id'
]
+
1
:
null
;
$response
=
Request
::
getUpdates
([
$response
=
Request
::
getUpdates
([
'offset'
=>
$offset
,
'offset'
=>
$offset
,
'limit'
=>
$limit
,
'limit'
=>
$limit
,
'timeout'
=>
$timeout
,
'timeout'
=>
$timeout
,
]);
]);
if
(
$response
->
isOk
())
{
if
(
$response
->
isOk
())
{
//Process all updates
//Process all updates
foreach
((
array
)
$response
->
getResult
()
as
$result
)
{
foreach
((
array
)
$response
->
getResult
()
as
$result
)
{
$this
->
processUpdate
(
$result
);
$this
->
processUpdate
(
$result
);
}
}
}
}
...
@@ -361,9 +356,9 @@ class Telegram
...
@@ -361,9 +356,9 @@ class Telegram
/**
/**
* Process bot Update request
* Process bot Update request
*
*
* @param Entities\Update $update
* @param
\Longman\TelegramBot\
Entities\Update $update
*
*
* @return Entities\ServerResponse
* @return
\Longman\TelegramBot\
Entities\ServerResponse
*/
*/
public
function
processUpdate
(
Update
$update
)
public
function
processUpdate
(
Update
$update
)
{
{
...
@@ -419,6 +414,7 @@ class Telegram
...
@@ -419,6 +414,7 @@ class Telegram
* @param string $command
* @param string $command
*
*
* @return mixed
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
executeCommand
(
$command
)
public
function
executeCommand
(
$command
)
{
{
...
@@ -451,7 +447,6 @@ class Telegram
...
@@ -451,7 +447,6 @@ class Telegram
return
$this
->
last_command_response
;
return
$this
->
last_command_response
;
}
}
/**
/**
* Sanitize Command
* Sanitize Command
*
*
...
@@ -469,7 +464,7 @@ class Telegram
...
@@ -469,7 +464,7 @@ class Telegram
*
*
* @param integer $admin_id Single admin id
* @param integer $admin_id Single admin id
*
*
* @return Telegram
* @return
\Longman\TelegramBot\
Telegram
*/
*/
public
function
enableAdmin
(
$admin_id
)
public
function
enableAdmin
(
$admin_id
)
{
{
...
@@ -487,7 +482,7 @@ class Telegram
...
@@ -487,7 +482,7 @@ class Telegram
*
*
* @param array $admin_ids List of admin ids
* @param array $admin_ids List of admin ids
*
*
* @return Telegram
* @return
\Longman\TelegramBot\
Telegram
*/
*/
public
function
enableAdmins
(
array
$admin_ids
)
public
function
enableAdmins
(
array
$admin_ids
)
{
{
...
@@ -556,7 +551,7 @@ class Telegram
...
@@ -556,7 +551,7 @@ class Telegram
* @param string $path Custom commands path to add
* @param string $path Custom commands path to add
* @param bool $before If the path should be prepended or appended to the list
* @param bool $before If the path should be prepended or appended to the list
*
*
* @return Telegram
* @return
\Longman\TelegramBot\
Telegram
*/
*/
public
function
addCommandsPath
(
$path
,
$before
=
true
)
public
function
addCommandsPath
(
$path
,
$before
=
true
)
{
{
...
@@ -579,7 +574,7 @@ class Telegram
...
@@ -579,7 +574,7 @@ class Telegram
* @param array $paths Custom commands paths to add
* @param array $paths Custom commands paths to add
* @param bool $before If the paths should be prepended or appended to the list
* @param bool $before If the paths should be prepended or appended to the list
*
*
* @return Telegram
* @return
\Longman\TelegramBot\
Telegram
*/
*/
public
function
addCommandsPaths
(
array
$paths
,
$before
=
true
)
public
function
addCommandsPaths
(
array
$paths
,
$before
=
true
)
{
{
...
@@ -699,10 +694,11 @@ class Telegram
...
@@ -699,10 +694,11 @@ class Telegram
/**
/**
* Set Webhook for bot
* Set Webhook for bot
*
*
* @param string
$url
* @param string $url
* @param string|null
$path_certificate
* @param string|null $path_certificate
*
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
setWebHook
(
$url
,
$path_certificate
=
null
)
public
function
setWebHook
(
$url
,
$path_certificate
=
null
)
{
{
...
@@ -724,7 +720,8 @@ class Telegram
...
@@ -724,7 +720,8 @@ class Telegram
/**
/**
* Unset Webhook for bot
* Unset Webhook for bot
*
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
unsetWebHook
()
public
function
unsetWebHook
()
{
{
...
@@ -762,14 +759,17 @@ class Telegram
...
@@ -762,14 +759,17 @@ class Telegram
*/
*/
protected
function
ucfirstUnicode
(
$str
,
$encoding
=
'UTF-8'
)
protected
function
ucfirstUnicode
(
$str
,
$encoding
=
'UTF-8'
)
{
{
return
mb_strtoupper
(
mb_substr
(
$str
,
0
,
1
,
$encoding
),
$encoding
)
.
mb_strtolower
(
mb_substr
(
$str
,
1
,
mb_strlen
(
$str
),
$encoding
),
$encoding
);
return
mb_strtoupper
(
mb_substr
(
$str
,
0
,
1
,
$encoding
),
$encoding
)
.
mb_strtolower
(
mb_substr
(
$str
,
1
,
mb_strlen
(
$str
),
$encoding
),
$encoding
);
}
}
/**
/**
* Enable Botan.io integration
* Enable Botan.io integration
*
*
* @param $token
* @param $token
* @return Telegram
* @return
\Longman\TelegramBot\
Telegram
*/
*/
public
function
enableBotan
(
$token
)
public
function
enableBotan
(
$token
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment