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
b18d216e
Unverified
Commit
b18d216e
authored
Apr 22, 2018
by
Avtandil Kikabidze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move botan integration in to separate namespace
parent
457da719
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
22 deletions
+46
-22
Botan.php
src/Extensions/Botan/Botan.php
+36
-7
BotanDB.php
src/Extensions/Botan/BotanDB.php
+5
-4
Telegram.php
src/Telegram.php
+5
-11
No files found.
src/Botan.php
→
src/
Extensions/Botan/
Botan.php
View file @
b18d216e
...
...
@@ -8,12 +8,13 @@
* file that was distributed with this source code.
*/
namespace
Longman\TelegramBot
;
namespace
Longman\TelegramBot
\Extensions\Botan
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Exception\RequestException
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Exception\TelegramException
;
use
Longman\TelegramBot\TelegramLog
;
/**
* Class Botan
...
...
@@ -54,11 +55,18 @@ class Botan
*/
public
static
$command
=
''
;
/**
* Enabled
*
* @var bool
*/
protected
static
$enabled
=
false
;
/**
* Initialize Botan
*
* @param string $token
* @param array
$options
* @param array $options
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
...
...
@@ -74,7 +82,7 @@ class Botan
$options
=
array_merge
(
$options_default
,
$options
);
if
(
!
is_numeric
(
$options
[
'timeout'
]))
{
if
(
!
is_numeric
(
$options
[
'timeout'
]))
{
throw
new
TelegramException
(
'Timeout must be a number!'
);
}
...
...
@@ -102,7 +110,7 @@ class Botan
* Track function
*
* @param \Longman\TelegramBot\Entities\Update $update
* @param string
$command
* @param string $command
*
* @return bool|string
* @throws \Longman\TelegramBot\Exception\TelegramException
...
...
@@ -145,7 +153,7 @@ class Botan
if
(
$entity
->
getType
()
===
'bot_command'
&&
$entity
->
getOffset
()
===
0
)
{
if
(
$command
===
'generic'
)
{
$command
=
'Generic'
;
}
elseif
(
$command
===
'genericmessage'
)
{
// This should not happen as it equals normal message but leaving it as a fail-safe
}
else
if
(
$command
===
'genericmessage'
)
{
// This should not happen as it equals normal message but leaving it as a fail-safe
$command
=
'Generic Message'
;
}
else
{
$command
=
'/'
.
$command
;
...
...
@@ -190,7 +198,7 @@ class Botan
$responseData
=
json_decode
(
$result
,
true
);
if
(
!
$responseData
||
$responseData
[
'status'
]
!==
'accepted'
)
{
if
(
!
$responseData
||
$responseData
[
'status'
]
!==
'accepted'
)
{
TelegramLog
::
debug
(
'Botan.io stats report failed: %s'
,
$result
?:
'empty response'
);
return
false
;
...
...
@@ -202,7 +210,7 @@ class Botan
/**
* Url Shortener function
*
* @param string
$url
* @param string $url
* @param integer $user_id
*
* @return string
...
...
@@ -247,4 +255,25 @@ class Botan
return
$result
;
}
/**
* Return enabled status
*
* @return bool
*/
public
static
function
isEnabled
()
{
return
self
::
$enabled
;
}
/**
* Set enabled status
*
* @param $enabled bool
* @return void
*/
public
static
function
setEnabled
(
$enabled
)
{
self
::
$enabled
=
$enabled
;
}
}
src/BotanDB.php
→
src/
Extensions/Botan/
BotanDB.php
View file @
b18d216e
...
...
@@ -8,9 +8,10 @@
* file that was distributed with this source code.
*/
namespace
Longman\TelegramBot
;
namespace
Longman\TelegramBot
\Extensions\Botan
;
use
Exception
;
use
Longman\TelegramBot\DB
;
use
Longman\TelegramBot\Exception\TelegramException
;
/**
...
...
@@ -23,7 +24,7 @@ class BotanDB extends DB
*/
public
static
function
initializeBotanDb
()
{
if
(
!
defined
(
'TB_BOTAN_SHORTENER'
))
{
if
(
!
defined
(
'TB_BOTAN_SHORTENER'
))
{
define
(
'TB_BOTAN_SHORTENER'
,
self
::
$table_prefix
.
'botan_shortener'
);
}
}
...
...
@@ -39,7 +40,7 @@ class BotanDB extends DB
*/
public
static
function
selectShortUrl
(
$url
,
$user_id
)
{
if
(
!
self
::
isDbConnected
())
{
if
(
!
self
::
isDbConnected
())
{
return
false
;
}
...
...
@@ -75,7 +76,7 @@ class BotanDB extends DB
*/
public
static
function
insertShortUrl
(
$url
,
$user_id
,
$short_url
)
{
if
(
!
self
::
isDbConnected
())
{
if
(
!
self
::
isDbConnected
())
{
return
false
;
}
...
...
src/Telegram.php
View file @
b18d216e
...
...
@@ -19,6 +19,7 @@ use Longman\TelegramBot\Commands\Command;
use
Longman\TelegramBot\Console\Kernel
as
ConsoleKernel
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Exception\TelegramException
;
use
Longman\TelegramBot\Extensions\Botan\Botan
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Kernel
;
use
Longman\TelegramBot\Http\Request
;
...
...
@@ -114,13 +115,6 @@ class Telegram
*/
protected
$last_command_response
;
/**
* Botan.io integration
*
* @var boolean
*/
protected
$botan_enabled
=
false
;
/**
* Check if runCommands() is running in this session
*
...
...
@@ -500,7 +494,7 @@ class Telegram
$this
->
last_command_response
=
$this
->
executeCommand
(
'generic'
);
}
else
{
// Botan.io integration, make sure only the actual command user executed is reported
if
(
$this
->
botan_enabled
)
{
if
(
Botan
::
isEnabled
()
)
{
Botan
::
lock
(
$command
);
}
...
...
@@ -509,7 +503,7 @@ class Telegram
$this
->
last_command_response
=
$command_obj
->
preExecute
();
// Botan.io integration, send report after executing the command
if
(
$this
->
botan_enabled
)
{
if
(
Botan
::
isEnabled
()
)
{
Botan
::
track
(
$this
->
update
,
$command
);
}
}
...
...
@@ -872,7 +866,7 @@ class Telegram
public
function
enableBotan
(
$token
,
array
$options
=
[])
{
Botan
::
initializeBotan
(
$token
,
$options
);
$this
->
botan_enabled
=
true
;
Botan
::
setEnabled
(
true
)
;
return
$this
;
}
...
...
@@ -905,7 +899,7 @@ class Telegram
}
$this
->
run_commands
=
true
;
$this
->
botan_enabled
=
false
;
// Force disable Botan.io integration, we don't want to track self-executed commands!
Botan
::
setEnabled
(
false
)
;
// Force disable Botan.io integration, we don't want to track self-executed commands!
$result
=
Client
::
getMe
();
...
...
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