diff options
author | Alexander NeonXP Kiryukhin <frei@neonxp.info> | 2016-05-27 17:16:31 +0300 |
---|---|---|
committer | Alexander NeonXP Kiryukhin <frei@neonxp.info> | 2016-05-27 17:16:31 +0300 |
commit | ad59bf1073cf368aa1539f991b5ce9eb68393a40 (patch) | |
tree | 7e3843ed7b385ddb8f2a2b1869f870b0f6b9eff3 | |
parent | fb5adfc60241bc5e3b37e9143be267467eaaf6d6 (diff) |
Geo working
-rw-r--r-- | composer.lock | 30 | ||||
-rw-r--r-- | src/NeonXP/BotScript.php | 21 |
2 files changed, 36 insertions, 15 deletions
diff --git a/composer.lock b/composer.lock index db038dc..9b09cb0 100644 --- a/composer.lock +++ b/composer.lock @@ -316,16 +316,16 @@ }, { "name": "guzzlehttp/promises", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8" + "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8", - "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8", + "url": "https://api.github.com/repos/guzzle/promises/zipball/c10d860e2a9595f8883527fa0021c7da9e65f579", + "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579", "shasum": "" }, "require": { @@ -363,7 +363,7 @@ "keywords": [ "promise" ], - "time": "2016-03-08 01:15:46" + "time": "2016-05-18 16:56:05" }, { "name": "guzzlehttp/psr7", @@ -429,12 +429,12 @@ "source": { "type": "git", "url": "https://github.com/schmittjoh/metadata.git", - "reference": "427a06e7c25d0fa1fbd37bf0325d9d3eb2dc383a" + "reference": "79d24dbd62ab7eba4973d677c5af31aca24adc1d" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/schmittjoh/metadata/zipball/79d24dbd62ab7eba4973d677c5af31aca24adc1d", - "reference": "427a06e7c25d0fa1fbd37bf0325d9d3eb2dc383a", + "reference": "79d24dbd62ab7eba4973d677c5af31aca24adc1d", "shasum": "" }, "require": { @@ -471,7 +471,7 @@ "xml", "yaml" ], - "time": "2015-01-14 15:37:39" + "time": "2016-05-27 05:53:38" }, { "name": "jms/parser-lib", @@ -514,12 +514,12 @@ "source": { "type": "git", "url": "https://github.com/schmittjoh/serializer.git", - "reference": "602bd84453b3b080c0aa4c4bd09a0024b8a08ea4" + "reference": "b0a46c80cf3dbd97205f2e2ffeb9229080899c76" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/b0a46c80cf3dbd97205f2e2ffeb9229080899c76", - "reference": "602bd84453b3b080c0aa4c4bd09a0024b8a08ea4", + "reference": "b0a46c80cf3dbd97205f2e2ffeb9229080899c76", "shasum": "" }, "require": { @@ -580,7 +580,7 @@ "serialization", "xml" ], - "time": "2016-05-12 12:20:22" + "time": "2016-05-21 12:25:17" }, { "name": "neonxp/telegram-api", @@ -588,12 +588,12 @@ "source": { "type": "git", "url": "https://github.com/NeonXP/TelegramApi.git", - "reference": "37ab7ca5510b9ecd42c7263b87b3294278838821" + "reference": "fd9da8bd6344505590603389e15a2debab3b7e60" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/NeonXP/TelegramApi/zipball/37ab7ca5510b9ecd42c7263b87b3294278838821", - "reference": "37ab7ca5510b9ecd42c7263b87b3294278838821", + "url": "https://api.github.com/repos/NeonXP/TelegramApi/zipball/fd9da8bd6344505590603389e15a2debab3b7e60", + "reference": "fd9da8bd6344505590603389e15a2debab3b7e60", "shasum": "" }, "require": { @@ -618,7 +618,7 @@ "email": "frei@neonxp.info" } ], - "time": "2016-01-06 21:11:59" + "time": "2016-05-27 14:03:43" }, { "name": "phpcollection/phpcollection", 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')-> |