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
fe4c5455
Commit
fe4c5455
authored
May 26, 2016
by
Jack'lul
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #202 from jacklul/quickupdate
Quick updates
parents
1549a4fd
0fcd30a8
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
224 additions
and
155 deletions
+224
-155
Botan.php
src/Botan.php
+39
-15
InlinequeryCommand.php
src/Commands/SystemCommands/InlinequeryCommand.php
+3
-3
DB.php
src/DB.php
+87
-72
Telegram.php
src/Telegram.php
+9
-3
structure.sql
structure.sql
+86
-62
No files found.
src/Botan.php
View file @
fe4c5455
...
@@ -34,6 +34,11 @@ class Botan
...
@@ -34,6 +34,11 @@ class Botan
*/
*/
protected
static
$token
=
''
;
protected
static
$token
=
''
;
/**
* @var string The actual command that is going to be reported
*/
public
static
$command
=
''
;
/**
/**
* Initilize botan
* Initilize botan
*/
*/
...
@@ -47,17 +52,30 @@ class Botan
...
@@ -47,17 +52,30 @@ class Botan
}
}
/**
/**
* Track function
* Lock function to make sure only the first command is reported
* ( in case commands are calling other commands $telegram->executedCommand() )
*
*
* @todo Advanced integration: https://github.com/botanio/sdk#advanced-integration
* @param string $command
*/
public
static
function
lock
(
$command
=
''
)
{
if
(
empty
(
self
::
$command
))
{
self
::
$command
=
$command
;
}
}
/**
* Track function
*
*
* @param string $input
* @param string $input
* @param string $command
* @param string $command
*
* @return bool|string
* @return bool|string
* @throws TelegramException
*/
*/
public
static
function
track
(
$input
,
$command
=
''
)
public
static
function
track
(
$input
,
$command
=
''
)
{
{
if
(
empty
(
self
::
$token
))
{
if
(
empty
(
self
::
$token
)
||
$command
!=
self
::
$command
)
{
return
false
;
return
false
;
}
}
...
@@ -65,22 +83,26 @@ class Botan
...
@@ -65,22 +83,26 @@ class Botan
throw
new
TelegramException
(
'Input is empty!'
);
throw
new
TelegramException
(
'Input is empty!'
);
}
}
self
::
$command
=
''
;
$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'
;
if
((
isset
(
$obj
[
'message'
][
'entities'
])
&&
$obj
[
'message'
][
'entities'
][
0
][
'type'
]
==
'bot_command'
&&
$obj
[
'message'
][
'entities'
][
0
][
'offset'
]
==
0
)
||
substr
(
$obj
[
'message'
][
'text'
],
0
,
1
)
==
'/'
)
{
if
(
isset
(
$obj
[
'message'
][
'entities'
])
&&
is_array
(
$obj
[
'message'
][
'entities'
]))
{
foreach
(
$obj
[
'message'
][
'entities'
]
as
$entity
)
{
if
(
$entity
[
'type'
]
==
'bot_command'
&&
$entity
[
'offset'
]
==
0
)
{
if
(
strtolower
(
$command
)
==
'generic'
)
{
if
(
strtolower
(
$command
)
==
'generic'
)
{
$command
=
'Generic'
;
$command
=
'Generic'
;
}
elseif
(
strtolower
(
$command
)
==
'genericmessage'
)
{
$command
=
'Generic Message'
;
}
else
{
}
else
{
$command
=
'/'
.
strtolower
(
$command
);
$command
=
'/'
.
strtolower
(
$command
);
}
}
$event_name
=
'Command ('
.
$command
.
')'
;
$event_name
=
'Command ('
.
$command
.
')'
;
}
else
{
break
;
$event_name
=
'Message'
;
}
}
}
}
}
elseif
(
isset
(
$obj
[
'inline_query'
]))
{
}
elseif
(
isset
(
$obj
[
'inline_query'
]))
{
$data
=
$obj
[
'inline_query'
];
$data
=
$obj
[
'inline_query'
];
...
@@ -129,7 +151,9 @@ class Botan
...
@@ -129,7 +151,9 @@ class Botan
*
*
* @param $url
* @param $url
* @param $user_id
* @param $user_id
*
* @return string
* @return string
* @throws TelegramException
*/
*/
public
static
function
shortenUrl
(
$url
,
$user_id
)
public
static
function
shortenUrl
(
$url
,
$user_id
)
{
{
...
...
src/Commands/SystemCommands/InlinequeryCommand.php
View file @
fe4c5455
...
@@ -40,9 +40,9 @@ class InlinequeryCommand extends SystemCommand
...
@@ -40,9 +40,9 @@ class InlinequeryCommand extends SystemCommand
$data
=
[
'inline_query_id'
=>
$inline_query
->
getId
()];
$data
=
[
'inline_query_id'
=>
$inline_query
->
getId
()];
$articles
=
[
$articles
=
[
[
'id'
=>
'001'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
new
InputTextMessageContent
([
'message_text'
=>
$query
])
],
[
'id'
=>
'001'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
new
InputTextMessageContent
([
'message_text'
=>
' '
.
$query
])
],
[
'id'
=>
'002'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
new
InputTextMessageContent
([
'message_text'
=>
$query
])
],
[
'id'
=>
'002'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
new
InputTextMessageContent
([
'message_text'
=>
' '
.
$query
])
],
[
'id'
=>
'003'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
new
InputTextMessageContent
([
'message_text'
=>
$query
])
],
[
'id'
=>
'003'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
new
InputTextMessageContent
([
'message_text'
=>
' '
.
$query
])
],
];
];
$array_article
=
[];
$array_article
=
[];
...
...
src/DB.php
View file @
fe4c5455
This diff is collapsed.
Click to expand it.
src/Telegram.php
View file @
fe4c5455
...
@@ -515,11 +515,16 @@ class Telegram
...
@@ -515,11 +515,16 @@ class Telegram
//Handle a generic command or non existing one
//Handle a generic command or non existing one
$this
->
last_command_response
=
$this
->
executeCommand
(
'Generic'
);
$this
->
last_command_response
=
$this
->
executeCommand
(
'Generic'
);
}
else
{
}
else
{
//Botan.io integration, make sure only the command user executed is reported
if
(
$this
->
botan_enabled
)
{
Botan
::
lock
(
$command
);
}
//execute() method is executed after preExecute()
//execute() method is executed after preExecute()
//This is to prevent executing a DB query without a valid connection
//This is to prevent executing a DB query without a valid connection
$this
->
last_command_response
=
$command_obj
->
preExecute
();
$this
->
last_command_response
=
$command_obj
->
preExecute
();
//Botan.io integration
//Botan.io integration
, send report after executing the command
if
(
$this
->
botan_enabled
)
{
if
(
$this
->
botan_enabled
)
{
Botan
::
track
(
$this
->
update
,
$command
);
Botan
::
track
(
$this
->
update
,
$command
);
}
}
...
@@ -582,9 +587,11 @@ class Telegram
...
@@ -582,9 +587,11 @@ class Telegram
$user_id
=
$from
->
getId
();
$user_id
=
$from
->
getId
();
}
elseif
((
$inline_query
=
$this
->
update
->
getInlineQuery
())
&&
(
$from
=
$inline_query
->
getFrom
()))
{
}
elseif
((
$inline_query
=
$this
->
update
->
getInlineQuery
())
&&
(
$from
=
$inline_query
->
getFrom
()))
{
$user_id
=
$from
->
getId
();
$user_id
=
$from
->
getId
();
}
elseif
((
$chosen_inline_result
=
$this
->
update
->
getChosenInlineResult
())
&&
(
$from
=
$chosen_inline_result
->
getFrom
()))
{
$user_id
=
$from
->
getId
();
}
elseif
((
$callback_query
=
$this
->
update
->
getCallbackQuery
())
&&
(
$from
=
$callback_query
->
getFrom
()))
{
}
elseif
((
$callback_query
=
$this
->
update
->
getCallbackQuery
())
&&
(
$from
=
$callback_query
->
getFrom
()))
{
$user_id
=
$from
->
getId
();
$user_id
=
$from
->
getId
();
}
elseif
((
$
chosen_inline_result
=
$this
->
update
->
getChosenInlineResult
())
&&
(
$from
=
$chosen_inline_result
->
getFrom
()))
{
}
elseif
((
$
edited_message
=
$this
->
update
->
getEditedMessage
())
&&
(
$from
=
$edited_message
->
getFrom
()))
{
$user_id
=
$from
->
getId
();
$user_id
=
$from
->
getId
();
}
}
}
}
...
@@ -808,7 +815,6 @@ class Telegram
...
@@ -808,7 +815,6 @@ class Telegram
* Enable Botan.io integration
* Enable Botan.io integration
*
*
* @param $token
* @param $token
* @param $custom
* @return Telegram
* @return Telegram
*/
*/
public
function
enableBotan
(
$token
)
public
function
enableBotan
(
$token
)
...
...
structure.sql
View file @
fe4c5455
This diff is collapsed.
Click to expand it.
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