diff options
Diffstat (limited to 'src/NeonXP/BotScript.php')
-rw-r--r-- | src/NeonXP/BotScript.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/NeonXP/BotScript.php b/src/NeonXP/BotScript.php index 1570955..8720f07 100644 --- a/src/NeonXP/BotScript.php +++ b/src/NeonXP/BotScript.php @@ -3,10 +3,12 @@ namespace NeonXP; use Doctrine\Common\Cache\CacheProvider; +use NeonXP\TelegramApi\Types\Location; use \NeonXP\TelegramApi\Types\Message; use \NeonXP\TelegramApi\Script; use \NeonXP\TelegramApi\Script\State; use \NeonXP\TelegramApi\Script\Conditions\isText; +use \NeonXP\TelegramApi\Script\Conditions\isLocation; use \NeonXP\TelegramApi\Script\Conditions\isMatch; use \NeonXP\TelegramApi\Script\Conditions\isAnyText; use \NeonXP\TelegramApi\Telegram; @@ -44,6 +46,23 @@ class BotScript return State::INITIAL; //Set initial state }; + $geoCode = function (Message $message, Telegram $telegram) use ($dozorApi) { + $coords = explode(',', trim($message->getText())); + $location = new Location(); + $location->setLatitude($coords[0]); + $location->setLongitude($coords[1]); + $telegram->getMethods()->sendLocation($message->getChat(), $location); + + return State::INITIAL; //Set initial state + }; + $reverseGeoCode = function (Message $message, Telegram $telegram) use ($dozorApi) { + + $telegram->getMethods()->sendMessage($message->getChat(), + sprintf('%s, %s', $message->getLocation()->getLatitude(), $message->getLocation()->getLongitude()) + ); + + return State::INITIAL; //Set initial state + }; $getDb = function (Message $message, Telegram $telegram) { $text = trim(substr($message->getText(), 1)); @@ -150,6 +169,8 @@ class BotScript ])-> action(new isMatch('/^\!.+?$/i'), $sendCode)-> action(new isMatch('/^\?.+?$/i'), $getDb)-> + action(new isMatch('/^\d\d\.\d+\s?\,\s?\d\d\.\d+\s?$/i'), $geoCode)-> + action(new isLocation(), $reverseGeoCode)-> action(new isAnyText(), $goBack)-> end()-> state('STATE_SET_LINK')-> |