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