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
3204a0c0
Commit
3204a0c0
authored
Dec 30, 2016
by
Armando Lüscher
Committed by
GitHub
Dec 30, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #368 from noplanman/scrutinizer_fixes
Scrutinizer fixes
parents
ad4ab40f
2036770f
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
34 additions
and
30 deletions
+34
-30
Botan.php
src/Botan.php
+3
-1
Conversation.php
src/Conversation.php
+15
-12
DB.php
src/DB.php
+1
-1
Entity.php
src/Entities/Entity.php
+2
-1
Message.php
src/Entities/Message.php
+1
-1
Request.php
src/Request.php
+3
-4
TelegramLog.php
src/TelegramLog.php
+9
-10
No files found.
src/Botan.php
View file @
3204a0c0
...
@@ -166,7 +166,9 @@ class Botan
...
@@ -166,7 +166,9 @@ class Botan
}
}
// In case there is no from field assign id = 0
// In case there is no from field assign id = 0
$uid
=
(
isset
(
$data
[
'from'
][
'id'
]))
?
$data
[
'from'
][
'id'
]
:
0
;
$uid
=
isset
(
$data
[
'from'
][
'id'
])
?
$data
[
'from'
][
'id'
]
:
0
;
$result
=
null
;
try
{
try
{
$response
=
self
::
$client
->
post
(
$response
=
self
::
$client
->
post
(
...
...
src/Conversation.php
View file @
3204a0c0
...
@@ -21,23 +21,23 @@ class Conversation
...
@@ -21,23 +21,23 @@ class Conversation
/**
/**
* All information fetched from the database
* All information fetched from the database
*
*
* @var array
* @var array
|null
*/
*/
protected
$conversation
=
null
;
protected
$conversation
;
/**
/**
* Notes stored inside the conversation
* Notes stored inside the conversation
*
*
* @var
array
* @var
mixed
*/
*/
protected
$protected_notes
=
null
;
protected
$protected_notes
;
/**
/**
* Notes to be stored
* Notes to be stored
*
*
* @var
array
* @var
mixed
*/
*/
public
$notes
=
null
;
public
$notes
;
/**
/**
* Telegram user id
* Telegram user id
...
@@ -66,6 +66,8 @@ class Conversation
...
@@ -66,6 +66,8 @@ class Conversation
* @param int $user_id
* @param int $user_id
* @param int $chat_id
* @param int $chat_id
* @param string $command
* @param string $command
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
__construct
(
$user_id
,
$chat_id
,
$command
=
null
)
public
function
__construct
(
$user_id
,
$chat_id
,
$command
=
null
)
{
{
...
@@ -98,10 +100,10 @@ class Conversation
...
@@ -98,10 +100,10 @@ class Conversation
* Load the conversation from the database
* Load the conversation from the database
*
*
* @return bool
* @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
protected
function
load
()
protected
function
load
()
{
{
//Select an active conversation
//Select an active conversation
$conversation
=
ConversationDB
::
selectConversation
(
$this
->
user_id
,
$this
->
chat_id
,
1
);
$conversation
=
ConversationDB
::
selectConversation
(
$this
->
user_id
,
$this
->
chat_id
,
1
);
if
(
isset
(
$conversation
[
0
]))
{
if
(
isset
(
$conversation
[
0
]))
{
...
@@ -138,11 +140,13 @@ class Conversation
...
@@ -138,11 +140,13 @@ class Conversation
* Start a new conversation if the current command doesn't have one yet
* Start a new conversation if the current command doesn't have one yet
*
*
* @return bool
* @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
protected
function
start
()
protected
function
start
()
{
{
if
(
!
$this
->
exists
()
&&
$this
->
command
)
{
if
(
$this
->
command
if
(
ConversationDB
::
insertConversation
(
&&
!
$this
->
exists
()
&&
ConversationDB
::
insertConversation
(
$this
->
user_id
,
$this
->
user_id
,
$this
->
chat_id
,
$this
->
chat_id
,
$this
->
command
$this
->
command
...
@@ -150,7 +154,6 @@ class Conversation
...
@@ -150,7 +154,6 @@ class Conversation
)
{
)
{
return
$this
->
load
();
return
$this
->
load
();
}
}
}
return
false
;
return
false
;
}
}
...
...
src/DB.php
View file @
3204a0c0
...
@@ -116,7 +116,7 @@ class DB
...
@@ -116,7 +116,7 @@ class DB
self
::
$pdo
=
$external_pdo_connection
;
self
::
$pdo
=
$external_pdo_connection
;
self
::
$telegram
=
$telegram
;
self
::
$telegram
=
$telegram
;
self
::
$mysql_credentials
=
null
;
self
::
$mysql_credentials
=
[]
;
self
::
$table_prefix
=
$table_prefix
;
self
::
$table_prefix
=
$table_prefix
;
self
::
defineTables
();
self
::
defineTables
();
...
...
src/Entities/Entity.php
View file @
3204a0c0
...
@@ -22,6 +22,7 @@ use ReflectionObject;
...
@@ -22,6 +22,7 @@ use ReflectionObject;
* @link https://core.telegram.org/bots/api#available-types
* @link https://core.telegram.org/bots/api#available-types
*
*
* @method array getRawData() Get the raw data passed to this entity
* @method array getRawData() Get the raw data passed to this entity
* @method string getBotName() Return the bot name passed to this entity
*/
*/
abstract
class
Entity
abstract
class
Entity
{
{
...
...
src/Entities/Message.php
View file @
3204a0c0
...
@@ -182,7 +182,7 @@ class Message extends Entity
...
@@ -182,7 +182,7 @@ class Message extends Entity
$split_cmd
=
explode
(
'@'
,
$cmd
);
$split_cmd
=
explode
(
'@'
,
$cmd
);
if
(
isset
(
$split_cmd
[
1
]))
{
if
(
isset
(
$split_cmd
[
1
]))
{
//command is followed by name check if is addressed to me
//command is followed by name check if is addressed to me
if
(
strtolower
(
$split_cmd
[
1
])
===
strtolower
(
$this
->
bot_name
))
{
if
(
strtolower
(
$split_cmd
[
1
])
===
strtolower
(
$this
->
getBotName
()
))
{
return
$split_cmd
[
0
];
return
$split_cmd
[
0
];
}
}
}
else
{
}
else
{
...
...
src/Request.php
View file @
3204a0c0
...
@@ -209,10 +209,9 @@ class Request
...
@@ -209,10 +209,9 @@ class Request
$data
[
'reply_markup'
]
=
json_encode
(
$data
[
'reply_markup'
]);
$data
[
'reply_markup'
]
=
json_encode
(
$data
[
'reply_markup'
]);
}
}
$result
=
null
;
$request_params
=
self
::
setUpRequestParams
(
$data
);
$request_params
=
self
::
setUpRequestParams
(
$data
);
$request_params
[
'debug'
]
=
TelegramLog
::
getDebugLogTempStream
();
$debug_handle
=
TelegramLog
::
getDebugLogTempStream
();
$request_params
[
'debug'
]
=
$debug_handle
;
try
{
try
{
$response
=
self
::
$client
->
post
(
$response
=
self
::
$client
->
post
(
...
...
src/TelegramLog.php
View file @
3204a0c0
...
@@ -10,10 +10,10 @@
...
@@ -10,10 +10,10 @@
namespace
Longman\TelegramBot
;
namespace
Longman\TelegramBot
;
use
Monolog\Logger
;
use
Monolog\Handler\StreamHandler
;
use
Monolog\Formatter\LineFormatter
;
use
Longman\TelegramBot\Exception\TelegramLogException
;
use
Longman\TelegramBot\Exception\TelegramLogException
;
use
Monolog\Formatter\LineFormatter
;
use
Monolog\Handler\StreamHandler
;
use
Monolog\Logger
;
class
TelegramLog
class
TelegramLog
{
{
...
@@ -55,7 +55,7 @@ class TelegramLog
...
@@ -55,7 +55,7 @@ class TelegramLog
/**
/**
* Temporary stream handle for debug log
* Temporary stream handle for debug log
*
*
* @var null
* @var
resource|
null
*/
*/
static
protected
$debug_log_temp_stream_handle
;
static
protected
$debug_log_temp_stream_handle
;
...
@@ -77,10 +77,10 @@ class TelegramLog
...
@@ -77,10 +77,10 @@ class TelegramLog
foreach
(
self
::
$monolog
->
getHandlers
()
as
$handler
)
{
foreach
(
self
::
$monolog
->
getHandlers
()
as
$handler
)
{
if
(
$handler
->
getLevel
()
===
400
)
{
if
(
$handler
->
getLevel
()
===
400
)
{
self
::
$error_log_path
=
true
;
self
::
$error_log_path
=
'true'
;
}
}
if
(
$handler
->
getLevel
()
===
100
)
{
if
(
$handler
->
getLevel
()
===
100
)
{
self
::
$debug_log_path
=
true
;
self
::
$debug_log_path
=
'true'
;
}
}
}
}
}
else
{
}
else
{
...
@@ -147,11 +147,10 @@ class TelegramLog
...
@@ -147,11 +147,10 @@ class TelegramLog
public
static
function
getDebugLogTempStream
()
public
static
function
getDebugLogTempStream
()
{
{
if
(
self
::
$debug_log_temp_stream_handle
===
null
)
{
if
(
self
::
$debug_log_temp_stream_handle
===
null
)
{
if
(
self
::
isDebugLogActive
())
{
if
(
!
self
::
isDebugLogActive
())
{
self
::
$debug_log_temp_stream_handle
=
fopen
(
'php://temp'
,
'w+'
);
}
else
{
return
false
;
return
false
;
}
}
self
::
$debug_log_temp_stream_handle
=
fopen
(
'php://temp'
,
'w+b'
);
}
}
return
self
::
$debug_log_temp_stream_handle
;
return
self
::
$debug_log_temp_stream_handle
;
...
@@ -164,7 +163,7 @@ class TelegramLog
...
@@ -164,7 +163,7 @@ class TelegramLog
*/
*/
public
static
function
endDebugLogTempStream
(
$message
=
'%s'
)
public
static
function
endDebugLogTempStream
(
$message
=
'%s'
)
{
{
if
(
self
::
$debug_log_temp_stream_handle
!==
null
)
{
if
(
is_resource
(
self
::
$debug_log_temp_stream_handle
)
)
{
rewind
(
self
::
$debug_log_temp_stream_handle
);
rewind
(
self
::
$debug_log_temp_stream_handle
);
self
::
debug
(
self
::
debug
(
sprintf
(
sprintf
(
...
...
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