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
ba4b607a
Commit
ba4b607a
authored
Feb 03, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing DocBlocks and prettify some string concatenations.
parent
dbfdd577
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
71 additions
and
16 deletions
+71
-16
DateCommand.php
src/Commands/DateCommand.php
+38
-3
GenericCommand.php
src/Commands/GenericCommand.php
+4
-1
GenericmessageCommand.php
src/Commands/GenericmessageCommand.php
+3
-1
InlinequeryCommand.php
src/Commands/InlinequeryCommand.php
+0
-1
NewchatparticipantCommand.php
src/Commands/NewchatparticipantCommand.php
+1
-1
SlapCommand.php
src/Commands/SlapCommand.php
+2
-2
SupergroupchatcreatedCommand.php
src/Commands/SupergroupchatcreatedCommand.php
+4
-2
WeatherCommand.php
src/Commands/WeatherCommand.php
+14
-0
WhoamiCommand.php
src/Commands/WhoamiCommand.php
+5
-5
No files found.
src/Commands/DateCommand.php
View file @
ba4b607a
...
...
@@ -62,9 +62,26 @@ class DateCommand extends Command
*/
protected
$public
=
true
;
/**
* Base URL for Google Maps API
*
* @var string
*/
private
$base_url
=
'https://maps.googleapis.com/maps/api'
;
/**
* Date format
*
* @var string
*/
private
$date_format
=
'd-m-Y H:i:s'
;
/**
* Get coordinates
*
* @param string $location
* @return array|boolean
*/
private
function
getCoordinates
(
$location
)
{
$url
=
$this
->
base_url
.
'/geocode/json?'
;
...
...
@@ -97,6 +114,13 @@ class DateCommand extends Command
return
[
$lat
,
$lng
,
$acc
,
$types
];
}
/**
* Get date
*
* @param string $lat
* @param string $lng
* @return array|boolean
*/
private
function
getDate
(
$lat
,
$lng
)
{
$url
=
$this
->
base_url
.
'/timezone/json?'
;
...
...
@@ -131,11 +155,18 @@ class DateCommand extends Command
return
[
$local_time
,
$data
[
'timeZoneId'
]];
}
/**
* Get formatted date
*
* @param string $location
* @return string
*/
private
function
getFormattedDate
(
$location
)
{
if
(
empty
(
$location
))
{
return
'The time in nowhere is never'
;
}
list
(
$lat
,
$lng
,
$acc
,
$types
)
=
$this
->
getCoordinates
(
$location
);
if
(
empty
(
$lat
)
||
empty
(
$lng
))
{
...
...
@@ -146,11 +177,15 @@ class DateCommand extends Command
$date_utc
=
new
\DateTime
(
gmdate
(
'Y-m-d H:i:s'
,
$local_time
),
new
\DateTimeZone
(
$timezone_id
));
$return
=
'The local time in '
.
$timezone_id
.
' is: '
.
$date_utc
->
format
(
$this
->
date_format
)
.
''
;
return
$return
;
return
'The local time in '
.
$timezone_id
.
' is: '
.
$date_utc
->
format
(
$this
->
date_format
);
}
/**
* Perform a simple cURL request
*
* @param string $url
* @return object
*/
private
function
request
(
$url
)
{
$ch
=
curl_init
();
...
...
src/Commands/GenericCommand.php
View file @
ba4b607a
...
...
@@ -57,6 +57,8 @@ class GenericCommand extends Command
/**
* Execute command
*
* @todo This can't be right, as it always returns "Command: xyz not found.. :("
*
* @return boolean
*/
public
function
execute
()
...
...
@@ -64,9 +66,10 @@ class GenericCommand extends Command
$update
=
$this
->
getUpdate
();
$message
=
$this
->
getMessage
();
$chat_id
=
$message
->
getChat
()
->
getId
();
//You can use $command as param
$command
=
$message
->
getCommand
();
$chat_id
=
$message
->
getChat
()
->
getId
();
$text
=
$message
->
getText
(
true
);
...
...
src/Commands/GenericmessageCommand.php
View file @
ba4b607a
...
...
@@ -64,11 +64,13 @@ class GenericmessageCommand extends Command
$update
=
$this
->
getUpdate
();
$message
=
$this
->
getMessage
();
$chat_id
=
$message
->
getChat
()
->
getId
();
//You can use $command as param
$command
=
$message
->
getCommand
();
$chat_id
=
$message
->
getChat
()
->
getId
();
$text
=
$message
->
getText
(
true
);
//Do nothing
return
1
;
}
...
...
src/Commands/InlinequeryCommand.php
View file @
ba4b607a
...
...
@@ -90,7 +90,6 @@ class InlinequeryCommand extends Command
$data
[
'results'
]
=
$array_json
;
$result
=
Request
::
answerInlineQuery
(
$data
);
return
$result
->
isOk
();
}
}
src/Commands/NewchatparticipantCommand.php
View file @
ba4b607a
...
...
@@ -70,7 +70,7 @@ class NewchatparticipantCommand extends Command
if
(
strtolower
(
$participant
->
getUsername
())
==
strtolower
(
$this
->
getTelegram
()
->
getBotName
()))
{
$text
=
'Hi there!'
;
}
else
{
$text
=
'Hi '
.
$participant
->
tryMention
()
.
' !'
;
$text
=
'Hi '
.
$participant
->
tryMention
()
.
' !'
;
}
$data
=
[
...
...
src/Commands/SlapCommand.php
View file @
ba4b607a
...
...
@@ -66,9 +66,8 @@ class SlapCommand extends Command
$chat_id
=
$message
->
getChat
()
->
getId
();
$message_id
=
$message
->
getMessageId
();
$text
=
$message
->
getText
(
true
);
$sender
=
'@'
.
$message
->
getFrom
()
->
getUsername
();
$sender
=
'@'
.
$message
->
getFrom
()
->
getUsername
();
//username validation
$test
=
preg_match
(
'/@[\w_]{5,}/'
,
$text
);
...
...
@@ -82,6 +81,7 @@ class SlapCommand extends Command
'chat_id'
=>
$chat_id
,
'text'
=>
$text
,
];
$result
=
Request
::
sendMessage
(
$data
);
return
$result
->
isOk
();
}
...
...
src/Commands/SupergroupchatcreatedCommand.php
View file @
ba4b607a
...
...
@@ -57,6 +57,8 @@ class SupergroupchatcreatedCommand extends Command
/**
* Execute command
*
* @todo $chat_id isn't defined!
*
* @return boolean
*/
public
function
execute
()
...
...
@@ -66,8 +68,8 @@ class SupergroupchatcreatedCommand extends Command
$text
=
''
;
if
(
$message
->
getSuperGroupChatCreated
())
{
$text
=
"Your group has become a Supergroup!
\n
"
;
$text
.=
'Chat id has changed from
'
.
$message
->
getMigrateFromChatId
()
.
' to '
.
$message
->
getMigrateToChatId
();
$text
=
'Your group has become a Supergroup!'
.
"
\n
"
;
$text
.=
'Chat id has changed from
'
.
$message
->
getMigrateFromChatId
()
.
' to '
.
$message
->
getMigrateToChatId
();
}
$data
=
[
...
...
src/Commands/WeatherCommand.php
View file @
ba4b607a
...
...
@@ -61,6 +61,12 @@ class WeatherCommand extends Command
*/
protected
$public
=
true
;
/**
* Get weather using cURL request
*
* @param string $location
* @return object
*/
private
function
getWeather
(
$location
)
{
$url
=
'http://api.openweathermap.org/data/2.5/weather?q='
.
$location
.
'&units=metric'
;
...
...
@@ -90,6 +96,12 @@ class WeatherCommand extends Command
return
$response
;
}
/**
* Get weather string
*
* @param string $location
* @return bool|string
*/
private
function
getWeatherString
(
$location
)
{
if
(
empty
(
$location
))
{
...
...
@@ -103,6 +115,7 @@ class WeatherCommand extends Command
if
(
empty
(
$decode
)
||
$decode
[
'cod'
]
!=
200
)
{
return
false
;
}
$city
=
$decode
[
'name'
];
$country
=
$decode
[
'sys'
][
'country'
];
$temp
=
'The temperature in '
.
$city
.
' ('
.
$country
.
') is '
.
$decode
[
'main'
][
'temp'
]
.
'°C'
;
...
...
@@ -130,6 +143,7 @@ class WeatherCommand extends Command
}
catch
(
\Exception
$e
)
{
$result
=
''
;
}
return
$result
;
}
...
...
src/Commands/WhoamiCommand.php
View file @
ba4b607a
...
...
@@ -82,10 +82,10 @@ class WhoamiCommand extends Command
//Send chat action
Request
::
sendChatAction
([
'chat_id'
=>
$chat_id
,
'action'
=>
'typing'
]);
$caption
=
'Your Id: '
.
$message
->
getFrom
()
->
getId
();
$caption
.=
"
\n
"
.
'Name: '
.
$message
->
getFrom
()
->
getFirstName
()
.
' '
.
$message
->
getFrom
()
->
getLastName
();
$caption
.=
"
\n
"
.
'Username: '
.
$message
->
getFrom
()
->
getUsername
();
$caption
=
'Your Id: '
.
$message
->
getFrom
()
->
getId
()
.
"
\n
"
;
$caption
.=
'Name: '
.
$message
->
getFrom
()
->
getFirstName
()
.
' '
.
$message
->
getFrom
()
->
getLastName
()
.
"
\n
"
;
$caption
.=
'Username: '
.
$message
->
getFrom
()
->
getUsername
();
//Fetch user profile photo
$limit
=
10
;
...
...
@@ -115,7 +115,6 @@ class WhoamiCommand extends Command
$photo
=
$photos
[
0
][
2
];
$file_id
=
$photo
->
getFileId
();
$data
[
'photo'
]
=
$file_id
;
$data
[
'caption'
]
=
$caption
;
...
...
@@ -134,6 +133,7 @@ class WhoamiCommand extends Command
$data
[
'text'
]
=
$caption
;
$result
=
Request
::
sendMessage
(
$data
);
}
return
$result
->
isOk
();
}
}
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