Commit ba4b607a authored by Armando Lüscher's avatar Armando Lüscher

Add missing DocBlocks and prettify some string concatenations.

parent dbfdd577
......@@ -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();
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -90,7 +90,6 @@ class InlinequeryCommand extends Command
$data['results'] = $array_json;
$result = Request::answerInlineQuery($data);
return $result->isOk();
}
}
......@@ -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 = [
......
......@@ -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();
}
......
......@@ -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 = [
......
......@@ -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;
}
......
......@@ -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();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment