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
1009ee82
Unverified
Commit
1009ee82
authored
Dec 30, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify some code bits.
Update code style.
parent
706fc120
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
57 deletions
+57
-57
Botan.php
src/Botan.php
+57
-57
No files found.
src/Botan.php
View file @
1009ee82
...
...
@@ -69,7 +69,7 @@ class Botan
}
$options_default
=
[
'timeout'
=>
3
'timeout'
=>
3
,
];
$options
=
array_merge
(
$options_default
,
$options
);
...
...
@@ -115,7 +115,7 @@ class Botan
return
false
;
}
if
(
empty
(
$update
)
)
{
if
(
$update
===
null
)
{
throw
new
TelegramException
(
'Update object is empty!'
);
}
...
...
@@ -133,16 +133,15 @@ class Botan
'edited_channel_post'
=>
'Edited Channel Post'
,
'inline_query'
=>
'Inline Query'
,
'chosen_inline_result'
=>
'Chosen Inline Result'
,
'callback_query'
=>
'Callback Query'
'callback_query'
=>
'Callback Query'
,
];
if
(
array_key_exists
(
$update_type
,
$update_object_names
))
{
$data
=
$update_data
[
$update_type
];
$event_name
=
$update_object_names
[
$update_type
];
if
(
$update_type
===
'message'
)
{
if
(
$update
->
getMessage
()
->
getEntities
())
{
foreach
(
$update
->
getMessage
()
->
getEntities
()
as
$entity
)
{
if
(
$update_type
===
'message'
&&
$entities
=
$update
->
getMessage
()
->
getEntities
())
{
foreach
(
$entities
as
$entity
)
{
if
(
$entity
->
getType
()
===
'bot_command'
&&
$entity
->
getOffset
()
===
0
)
{
if
(
$command
===
'generic'
)
{
$command
=
'Generic'
;
...
...
@@ -158,48 +157,47 @@ class Botan
}
}
}
}
if
(
empty
(
$event_name
))
{
TelegramLog
::
error
(
"Botan.io stats report failed, no suitable update object found!"
);
TelegramLog
::
error
(
'Botan.io stats report failed, no suitable update object found!'
);
return
false
;
}
// In case there is no from field assign id = 0
$uid
=
isset
(
$data
[
'from'
][
'id'
])
?
$data
[
'from'
][
'id'
]
:
0
;
$result
=
null
;
try
{
$response
=
self
::
$client
->
post
(
str_replace
(
[
'#TOKEN'
,
'#UID'
,
'#NAME'
],
[
self
::
$token
,
$uid
,
urlencode
(
$event_name
)],
'/track?token=#TOKEN&uid=#UID&name=#NAME'
sprintf
(
'/track?token=%1$s&uid=%2$s&name=%3$s'
,
self
::
$token
,
$uid
,
urlencode
(
$event_name
)
),
[
'headers'
=>
[
'Content-Type'
=>
'application/json'
'Content-Type'
=>
'application/json'
,
],
'json'
=>
$data
'json'
=>
$data
,
]
);
$result
=
(
string
)
$response
->
getBody
();
}
catch
(
RequestException
$e
)
{
$result
=
$e
->
getMessage
();
}
finally
{
}
$responseData
=
json_decode
(
$result
,
true
);
if
(
$responseData
[
'status'
]
!==
'accepted'
)
{
TelegramLog
::
debug
(
'Botan.io stats report failed: '
.
(
$result
?:
'empty response'
)
.
"
\n\n
"
);
if
(
!
$responseData
||
$responseData
[
'status'
]
!==
'accepted'
)
{
TelegramLog
::
debug
(
'Botan.io stats report failed: '
.
(
$result
?:
'empty response'
)
);
return
false
;
}
return
$responseData
;
}
}
/**
* Url Shortener function
...
...
@@ -226,25 +224,27 @@ class Botan
try
{
$response
=
self
::
$client
->
post
(
str_replace
(
[
'#TOKEN'
,
'#UID'
,
'#URL'
],
[
self
::
$token
,
$user_id
,
urlencode
(
$url
)],
'/s/?token=#TOKEN&user_ids=#UID&url=#URL'
sprintf
(
'/s?token=%1$s&user_ids=%2$s&url=%3$s'
,
self
::
$token
,
$user_id
,
urlencode
(
$url
)
)
);
$result
=
(
string
)
$response
->
getBody
();
}
catch
(
RequestException
$e
)
{
$result
=
$e
->
getMessage
();
}
finally
{
if
(
filter_var
(
$result
,
FILTER_VALIDATE_URL
)
!==
false
)
{
BotanDB
::
insertShortUrl
(
$url
,
$user_id
,
$result
);
return
$result
;
}
else
{
TelegramLog
::
debug
(
'Botan.io URL shortening failed for \''
.
$url
.
'\': '
.
(
$result
?:
'empty response'
)
.
"
\n\n
"
);
}
if
(
filter_var
(
$result
,
FILTER_VALIDATE_URL
)
===
false
)
{
TelegramLog
::
debug
(
'Botan.io URL shortening failed for "'
.
$url
.
'": '
.
(
$result
?:
'empty response'
));
return
$url
;
}
}
BotanDB
::
insertShortUrl
(
$url
,
$user_id
,
$result
);
return
$result
;
}
}
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