diff options
-rw-r--r-- | composer.json | 3 | ||||
-rw-r--r-- | composer.lock | 130 | ||||
-rwxr-xr-x | log.1.html | 85 | ||||
-rw-r--r-- | log.txt | 85 | ||||
-rw-r--r-- | src/NeonXP/BotScript.php | 67 | ||||
-rw-r--r-- | src/NeonXP/DozorApi.php | 47 | ||||
-rw-r--r-- | www/index.php | 46 | ||||
-rw-r--r-- | www/static/openshift-logo.png | bin | 9714 -> 0 bytes |
8 files changed, 346 insertions, 117 deletions
diff --git a/composer.json b/composer.json index 67919f2..a3cbab0 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "minimum-stability": "dev", "require": { "neonxp/telegram-api": "dev-master", - "symfony/dom-crawler": "^3.0" + "symfony/dom-crawler": "^3.0", + "symfony/css-selector": "^3.1" } } diff --git a/composer.lock b/composer.lock index 9b09cb0..01b1eea 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "b905a956faf901fc0ce67f9a4bca4445", - "content-hash": "c477f795380531a57cf3aa81e30c9dc3", + "hash": "4eea464407058e91b2e5a6e1d83bf070", + "content-hash": "a80265640d93978625f150ac21c0343c", "packages": [ { "name": "doctrine/annotations", @@ -81,12 +81,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "4e3b8b9464d511eccbefe07cef94c275bce7e434" + "reference": "fe68e4f78804684e31cce17590b0bd9f088db1b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/4e3b8b9464d511eccbefe07cef94c275bce7e434", - "reference": "4e3b8b9464d511eccbefe07cef94c275bce7e434", + "url": "https://api.github.com/repos/doctrine/cache/zipball/fe68e4f78804684e31cce17590b0bd9f088db1b0", + "reference": "fe68e4f78804684e31cce17590b0bd9f088db1b0", "shasum": "" }, "require": { @@ -142,7 +142,7 @@ "cache", "caching" ], - "time": "2016-03-11 16:30:04" + "time": "2016-07-15 15:57:08" }, { "name": "doctrine/instantiator", @@ -258,23 +258,23 @@ "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "b1a96f6134f69cb41f8538d3a6491f4bb1dbab78" + "reference": "158c17127299b183d4b9784d7385bb29fe2f5982" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/b1a96f6134f69cb41f8538d3a6491f4bb1dbab78", - "reference": "b1a96f6134f69cb41f8538d3a6491f4bb1dbab78", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/158c17127299b183d4b9784d7385bb29fe2f5982", + "reference": "158c17127299b183d4b9784d7385bb29fe2f5982", "shasum": "" }, "require": { - "guzzlehttp/promises": "~1.0", - "guzzlehttp/psr7": "~1.1", - "php": ">=5.5.0" + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.3.1", + "php": ">=5.5" }, "require-dev": { "ext-curl": "*", - "phpunit/phpunit": "~4.0", - "psr/log": "~1.0" + "phpunit/phpunit": "^4.0", + "psr/log": "^1.0" }, "type": "library", "extra": { @@ -312,7 +312,7 @@ "rest", "web service" ], - "time": "2016-05-08 19:39:56" + "time": "2016-07-21 20:48:12" }, { "name": "guzzlehttp/promises", @@ -367,16 +367,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.3.0", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "31382fef2889136415751badebbd1cb022a4ed72" + "reference": "b1501c9fd5845473f39b89db5ac9a39a7ab62a38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72", - "reference": "31382fef2889136415751badebbd1cb022a4ed72", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/b1501c9fd5845473f39b89db5ac9a39a7ab62a38", + "reference": "b1501c9fd5845473f39b89db5ac9a39a7ab62a38", "shasum": "" }, "require": { @@ -392,7 +392,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -412,16 +412,23 @@ "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" } ], - "description": "PSR-7 message implementation", + "description": "PSR-7 message implementation that also provides common utility methods", "keywords": [ "http", "message", + "request", + "response", "stream", - "uri" + "uri", + "url" ], - "time": "2016-04-13 19:56:01" + "time": "2016-07-25 11:34:12" }, { "name": "jms/metadata", @@ -514,12 +521,12 @@ "source": { "type": "git", "url": "https://github.com/schmittjoh/serializer.git", - "reference": "b0a46c80cf3dbd97205f2e2ffeb9229080899c76" + "reference": "e0704d3959885d8999ff84791dcda19fb0b30980" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/b0a46c80cf3dbd97205f2e2ffeb9229080899c76", - "reference": "b0a46c80cf3dbd97205f2e2ffeb9229080899c76", + "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/e0704d3959885d8999ff84791dcda19fb0b30980", + "reference": "e0704d3959885d8999ff84791dcda19fb0b30980", "shasum": "" }, "require": { @@ -580,7 +587,7 @@ "serialization", "xml" ], - "time": "2016-05-21 12:25:17" + "time": "2016-07-27 11:04:12" }, { "name": "neonxp/telegram-api", @@ -815,17 +822,70 @@ "time": "2016-01-06 21:40:42" }, { + "name": "symfony/css-selector", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/symfony/css-selector.git", + "reference": "7a3ee9a4689295146659044f7c47c4734e0c552a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/7a3ee9a4689295146659044f7c47c4734e0c552a", + "reference": "7a3ee9a4689295146659044f7c47c4734e0c552a", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\CssSelector\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony CssSelector Component", + "homepage": "https://symfony.com", + "time": "2016-06-29 05:43:10" + }, + { "name": "symfony/dom-crawler", "version": "dev-master", "source": { "type": "git", "url": "https://github.com/symfony/dom-crawler.git", - "reference": "d69763ec860db5f9e1b74d7cf06329030e24e170" + "reference": "2042e4285ed15bd36f7e82bce0dfc015ec60c2b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/d69763ec860db5f9e1b74d7cf06329030e24e170", - "reference": "d69763ec860db5f9e1b74d7cf06329030e24e170", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/2042e4285ed15bd36f7e82bce0dfc015ec60c2b3", + "reference": "2042e4285ed15bd36f7e82bce0dfc015ec60c2b3", "shasum": "" }, "require": { @@ -868,7 +928,7 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2016-05-13 18:13:23" + "time": "2016-07-26 08:08:27" }, { "name": "symfony/polyfill-mbstring", @@ -876,12 +936,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "67f0d2b927796648c5c38cedb7a2c8f1cf14e7dc" + "reference": "8a6bdec191138e01c92ae026e5aacb7b3e66267d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/67f0d2b927796648c5c38cedb7a2c8f1cf14e7dc", - "reference": "67f0d2b927796648c5c38cedb7a2c8f1cf14e7dc", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8a6bdec191138e01c92ae026e5aacb7b3e66267d", + "reference": "8a6bdec191138e01c92ae026e5aacb7b3e66267d", "shasum": "" }, "require": { @@ -927,7 +987,7 @@ "portable", "shim" ], - "time": "2016-05-26 01:13:28" + "time": "2016-06-29 14:58:48" } ], "packages-dev": [], diff --git a/log.1.html b/log.1.html new file mode 100755 index 0000000..91ba1a7 --- /dev/null +++ b/log.1.html @@ -0,0 +1,85 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<html> +<head> + <META http-equiv="Content-Type" Content="text/html; charset=windows-1251"> + <meta http-equiv="Cache-Control" content="max-age=0" /> + <script src="timer.js" type="text/javascript"></script> + <title>DozoR.Lite / Joker`s revenge. </title> + + +<style> +body { + background-color : #FFFFFF; + color : #000000; + + +} + + +</style> + +</head> + +<body> + +<!--errorText--><p><strong> . . .</strong></p><!--errorTextEnd--><p> 22:18:26<br /></p><!--contentBegin--> + +<!--gameType Through--> + + +<p><strong> <!--levelNumberBegin-->1<!--levelNumberEnd-->. ( 22:00:00):</strong><!--levelTextBegin--><p><img src="http://s018.radikal.ru/i506/1606/44/9fdc5107f40e.jpg" alt="" /></p><div class=spoiler><strong> </strong>: <!--taskNotes--><p>, . .</p><!--taskNotesEnd--></div><br/><!--levelTextEnd--><!--bonusCodeCount 0--><!--mainCodeCount 7--><!--difficultyCods 1,1+,1,1+,1,1,1,--><div class='dcodes'><strong> </strong><br> : <span style='color:red'>1</span>, <span style='color:red'>1+</span>, 1, <span style='color:red'>1+</span>, <span style='color:red'>1</span>, <span style='color:red'>1</span>, 1<br> ( - 7 , 6 , - 5) <br /></p></div><p> : : 1939, 7721, 385, 4218, 3</p><p> </p> <form data-ajax="false" method=post> + <input type=hidden name="nomessage" value=""> + <input type=hidden name=action value=entcod> + <input type=hidden name=pin value=373293> + <input type=hidden name=lev value=0> + <input type=text id="levelCodeInput" placeholder=" " name=cod size=25 value=""><br> + <input id="sendCode" type=submit value=" "> + </form> + +<!--contentEnd--> : <span id=clock2></span><br> + : <span id=clock> </span> + <script> + window.setTimeout('countDown(695,1106)',1000); + </script> + <!--timeOnLevelBegin 1106 timeOnLevelEnd--> + <!--timeToFinishBegin 695 timeToFinishEnd--> + <div class=title> </div><table cellpadding=3 cellspacing=0 border=1><tr><th></th><th></th><th></th></tr><tr bgcolor=><td nowrap>22:17:10</td><td> </td><td>8331 </td></tr><tr bgcolor=><td nowrap>22:16:17</td><td> </td><td>562 </td></tr><tr bgcolor=><td nowrap>22:15:40</td><td> </td><td>4218 </td></tr></table><br> + <form method=get data-ajax="false"> + <input type=hidden name="pin" value="373293"> + <input type=hidden name="q" value="80534361QWYOMRBD"/> + <input type=hidden name="zone" value=""/> + <input type=hidden name="nomessage" value=""/> + <input type=submit value=" "> + </form> + <form method=get name=refr data-ajax="false"> + <input type=hidden name="pin" value="373293"> + <input type=hidden name="q" value="80534361QWYOMRBD"/> + <input type=hidden name="nomessage" value=""/> + <input type=submit value=" "> <input type=text name=refresh size=3 value="0"> . + </form> +<p> ! - . +<style> +.teamstat td, .teamstat th { + font-family : Arial; + font-size : 12px; +} + +.teamstat table, .teamstat table td, .teamstat table th { + border: 1px solid gray; + border-collapse: collapse; +} + +.teamstat table td, .teamstat table th { + padding : 2px 2px 2px 2px; +} +</style> +<hr/><p><b> </b><br/><form method=post> + <input type=hidden name=action value=message> + <input type=hidden name=gameData[id] value=319> + <input type=hidden name=pin value=373293> + <textarea name=content rows=5 cols=30></textarea><br> + <input type=submit value=' '> + </form><p>: <strong> 2.0</strong><!--<br>: <strong></strong>--><br>: <strong>Joker`s revenge. . 2016-06-17 22:00:00. </strong><br> :<strong> 11</strong>. : <strong>0</strong><br><br> : <strong>20 .</strong><br>: <strong> </strong>. ICQ: <strong>332831243</strong>. tel: <strong>+79047650935</strong></p> +</body> +</html>
\ No newline at end of file @@ -0,0 +1,85 @@ +a:2:{s:4:"http";a:3:{s:6:"method";s:4:"POST";s:6:"header";s:47:"Content-type: application/x-www-form-urlencoded";s:7:"content";s:93:"log=on&mes=&legend=on&nostat=¬ext=&refresh=0&bonus=&kladMap=¬ags=&cod=123&action=entcod";}s:6:"result";s:4383:"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<html> +<head> + <META http-equiv="Content-Type" Content="text/html; charset=windows-1251"> + <meta http-equiv="Cache-Control" content="max-age=0" /> + <script src="timer.js" type="text/javascript"></script> + <title>DozoR.Lite / Joker`s revenge. </title> + + +<style> +body { + background-color : #FFFFFF; + color : #000000; + + +} + + +</style> + +</head> + +<body> + +<!--errorText--><p><strong> . . .</strong></p><!--errorTextEnd--><p> 22:18:26<br /></p><!--contentBegin--> + +<!--gameType Through--> + + +<p><strong> <!--levelNumberBegin-->1<!--levelNumberEnd-->. ( 22:00:00):</strong><!--levelTextBegin--><p><img src="http://s018.radikal.ru/i506/1606/44/9fdc5107f40e.jpg" alt="" /></p><div class=spoiler><strong> </strong>: <!--taskNotes--><p>, . .</p><!--taskNotesEnd--></div><br/><!--levelTextEnd--><!--bonusCodeCount 0--><!--mainCodeCount 7--><!--difficultyCods 1,1+,1,1+,1,1,1,--><div class='dcodes'><strong> </strong><br> : <span style='color:red'>1</span>, <span style='color:red'>1+</span>, 1, <span style='color:red'>1+</span>, <span style='color:red'>1</span>, <span style='color:red'>1</span>, 1<br> ( - 7 , 6 , - 5) <br /></p></div><p> : : 1939, 7721, 385, 4218, 3</p><p> </p> <form data-ajax="false" method=post> + <input type=hidden name="nomessage" value=""> + <input type=hidden name=action value=entcod> + <input type=hidden name=pin value=373293> + <input type=hidden name=lev value=0> + <input type=text id="levelCodeInput" placeholder=" " name=cod size=25 value=""><br> + <input id="sendCode" type=submit value=" "> + </form> + +<!--contentEnd--> : <span id=clock2></span><br> + : <span id=clock> </span> + <script> + window.setTimeout('countDown(695,1106)',1000); + </script> + <!--timeOnLevelBegin 1106 timeOnLevelEnd--> + <!--timeToFinishBegin 695 timeToFinishEnd--> + <div class=title> </div><table cellpadding=3 cellspacing=0 border=1><tr><th></th><th></th><th></th></tr><tr bgcolor=><td nowrap>22:17:10</td><td> </td><td>8331 </td></tr><tr bgcolor=><td nowrap>22:16:17</td><td> </td><td>562 </td></tr><tr bgcolor=><td nowrap>22:15:40</td><td> </td><td>4218 </td></tr></table><br> + <form method=get data-ajax="false"> + <input type=hidden name="pin" value="373293"> + <input type=hidden name="q" value="80534361QWYOMRBD"/> + <input type=hidden name="zone" value=""/> + <input type=hidden name="nomessage" value=""/> + <input type=submit value=" "> + </form> + <form method=get name=refr data-ajax="false"> + <input type=hidden name="pin" value="373293"> + <input type=hidden name="q" value="80534361QWYOMRBD"/> + <input type=hidden name="nomessage" value=""/> + <input type=submit value=" "> <input type=text name=refresh size=3 value="0"> . + </form> +<p> ! - . +<style> +.teamstat td, .teamstat th { + font-family : Arial; + font-size : 12px; +} + +.teamstat table, .teamstat table td, .teamstat table th { + border: 1px solid gray; + border-collapse: collapse; +} + +.teamstat table td, .teamstat table th { + padding : 2px 2px 2px 2px; +} +</style> +<hr/><p><b> </b><br/><form method=post> + <input type=hidden name=action value=message> + <input type=hidden name=gameData[id] value=319> + <input type=hidden name=pin value=373293> + <textarea name=content rows=5 cols=30></textarea><br> + <input type=submit value=' '> + </form><p>: <strong> 2.0</strong><!--<br>: <strong></strong>--><br>: <strong>Joker`s revenge. . 2016-06-17 22:00:00. </strong><br> :<strong> 11</strong>. : <strong>0</strong><br><br> : <strong>20 .</strong><br>: <strong> </strong>. ICQ: <strong>332831243</strong>. tel: <strong>+79047650935</strong></p> +</body> +</html>";}
\ No newline at end of file diff --git a/src/NeonXP/BotScript.php b/src/NeonXP/BotScript.php index 9309b5a..12313d2 100644 --- a/src/NeonXP/BotScript.php +++ b/src/NeonXP/BotScript.php @@ -2,16 +2,15 @@ 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; +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; class BotScript { @@ -19,7 +18,8 @@ class BotScript { $saveLink = function (Message $message, Telegram $telegram) { $telegram->getCache()->save("link_{$message->getChat()->getId()}", $message->getText()); - $telegram->getMethods()->sendMessage($message->getChat(), 'Ок, записал: ' . $message->getText()); + $link = $telegram->getCache()->fetch("link_{$message->getChat()->getId()}"); + $telegram->getMethods()->sendMessage($message->getChat(), 'Ок, записал: '.$link); return State::INITIAL; }; @@ -38,7 +38,7 @@ class BotScript try { $result = $dozorApi->sendCode($message->getChat(), $code); } catch (\Exception $e) { - $telegram->getMethods()->sendMessage($message->getChat(), 'Ошибка сети', true); + $telegram->getMethods()->sendMessage($message->getChat(), 'Ошибка сети: '.$e->getMessage(), true); } if ($result) { $telegram->getMethods()->sendMessage($message->getChat(), $result, true); @@ -67,15 +67,15 @@ class BotScript $getDb = function (Message $message, Telegram $telegram) { $text = trim(substr($message->getText(), 1)); $db = [ - '1' => ['А', 'Я', 'A', 'Z', '00000', '. -'], - '2' => ['Б', 'Ю', 'B', 'Y', '00001', '- . . .'], - '3' => ['В', 'Э', 'C', 'X', '00010', '. - -'], - '4' => ['Г', 'Ь', 'D', 'W', '00011', '- - .'], - '5' => ['Д', 'Ы', 'E', 'V', '00100', '- . .'], - '6' => ['Е', 'Ъ', 'F', 'U', '00101', '.'], - '7' => ['Ё', 'Щ', 'G', 'T', '00101', '.'], - '8' => ['Ж', 'Ш', 'H', 'S', '00110', '. . . -'], - '9' => ['З', 'Ч', 'I', 'R', '00111', '- - . .'], + '1' => ['А', 'Я', 'A', 'Z', '00000', '. -'], + '2' => ['Б', 'Ю', 'B', 'Y', '00001', '- . . .'], + '3' => ['В', 'Э', 'C', 'X', '00010', '. - -'], + '4' => ['Г', 'Ь', 'D', 'W', '00011', '- - .'], + '5' => ['Д', 'Ы', 'E', 'V', '00100', '- . .'], + '6' => ['Е', 'Ъ', 'F', 'U', '00101', '.'], + '7' => ['Ё', 'Щ', 'G', 'T', '00101', '.'], + '8' => ['Ж', 'Ш', 'H', 'S', '00110', '. . . -'], + '9' => ['З', 'Ч', 'I', 'R', '00111', '- - . .'], '10' => ['И', 'Ц', 'J', 'Q', '01000', '. .'], '11' => ['Й', 'Х', 'K', 'P', '01001', '. - - -'], '12' => ['К', 'Ф', 'L', 'O', '01010', '- . -'], @@ -102,48 +102,49 @@ class BotScript '33' => ['Я', 'А', ' ', ' ', '11111', '. - . -'], ]; $result = 'Непонятно :('; - $header = ' № | А | Я | A | Z | Двоичн | Морзе ' . PHP_EOL . '____________________________________'; + $header = ' № | А | Я | A | Z | Двоич | Морзе '.PHP_EOL. + '___________________________________'; if ($text == '?') { $result = ''; foreach ($db as $key => $value) { if ($key < 10) { - $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } else { - $result .= "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $result .= "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } } } elseif (is_numeric($text) && (isset($db[$text]))) { $value = $db[$text]; if ($text < 10) { - $result = "0$text | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $result = "0$text | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } else { - $result = "$text | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $result = "$text | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } } else { $result = ''; - for ($i = 0; $i < mb_strlen($text, 'utf8'); $i++) { + for ($i = 0; $i < mb_strlen($text, 'utf8'); ++$i) { $char = mb_substr($text, $i, 1, 'utf8'); foreach ($db as $key => $value) { if (mb_strtolower($value[0], 'utf8') == mb_strtolower($char)) { if ($key < 10) { - $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } else { - $result .= "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $result .= "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } } if (strtolower($value[2]) == strtolower($char)) { if ($key < 10) { - $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } else { - $result .= "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $result .= "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } } } } } if ($result) { - $telegram->getMethods()->sendMessage($message->getChat(), '```' . $header . PHP_EOL . $result . '```', true); + $telegram->getMethods()->sendMessage($message->getChat(), '```'.$header.PHP_EOL.$result.'```', true); } return State::INITIAL; //Set initial state @@ -161,11 +162,11 @@ class BotScript action(new isText('/link'), $showLink)-> action(new isText('/setlink'), [ 'Пришлите ссылку с пином /cancel', - 'STATE_SET_LINK' + 'STATE_SET_LINK', ])-> action(new isText('/pause'), [ 'Замер. /resume для возврата', - 'STATE_PAUSE' + 'STATE_PAUSE', ])-> action(new isMatch('/^\!.+?$/i'), $sendCode)-> action(new isMatch('/^\?.+?$/i'), $getDb)-> diff --git a/src/NeonXP/DozorApi.php b/src/NeonXP/DozorApi.php index da724a9..4865e96 100644 --- a/src/NeonXP/DozorApi.php +++ b/src/NeonXP/DozorApi.php @@ -2,16 +2,15 @@ /** * @author Alexander "NeonXP" Kiryukhin */ + namespace NeonXP; + use Doctrine\Common\Cache\CacheProvider; use NeonXP\TelegramApi\Types\Chat; -use Symfony\Component\CssSelector\Node\AbstractNode; use Symfony\Component\DomCrawler\Crawler; - /** - * Class DozorApi - * @package NeonXP + * Class DozorApi. */ class DozorApi { @@ -22,6 +21,7 @@ class DozorApi /** * DozorApi constructor. + * * @param CacheProvider $cache */ public function __construct(CacheProvider $cache) @@ -32,31 +32,35 @@ class DozorApi public function sendCode(Chat $chat, $code) { $params = [ - "log" => 'on', - "mes" => '', - "legend" => 'on', - "nostat" => '', - "notext" => '', - "refresh" => '0', - "bonus" => '', - "kladMap" => '', - "notags" => '', - "cod" => $code, - "action" => 'entcod', + 'log' => 'on', + 'mes' => '', + 'legend' => 'on', + 'nostat' => '', + 'notext' => '', + 'refresh' => '0', + 'bonus' => '', + 'kladMap' => '', + 'notags' => '', + 'cod' => $code, + 'action' => 'entcod', ]; $data = http_build_query($params); $contextData = [ 'http' => [ 'method' => 'POST', - 'header' => 'Content-type: application/x-www-form-urlencoded', - 'content' => $data - ] + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'content' => $data, + ], ]; $context = stream_context_create($contextData); + if (!$this->getLink($chat)) { + throw new \Exception('Не задана ссылка'); + } $result = file_get_contents($this->getLink($chat), false, $context); $contextData['result'] = $result; - file_put_contents(getenv('OPENSHIFT_DATA_DIR') . 'log.txt', serialize($contextData)); + file_put_contents(getenv('OPENSHIFT_DATA_DIR').'log.txt', serialize($contextData)); + return $this->parseResult($result); } @@ -66,7 +70,7 @@ class DozorApi $answer = [ $this->parseCodeEnter($html), - $this->parseTask($crawler) + $this->parseTask($crawler), ]; $answer = array_merge($answer, $this->parseCodes($crawler)); @@ -78,9 +82,10 @@ class DozorApi private function parseCodeEnter($html) { $html = iconv('cp1251', 'utf8', $html); - $regex = '/\<\!\-\-errorText\-\-\>\<p\>\<strong\>(.+?)\<\/strong\>\<\/p\>\<\!\-\-errorTextEnd\-\-\>'; + $regex = '/\<\!\-\-errorText\-\-\>\<p\>\<strong\>(.+?)\<\/strong\>\<\/p\>\<\!\-\-errorTextEnd\-\-\>/i'; $result = []; preg_match($regex, $html, $result); + return $result[1]; } diff --git a/www/index.php b/www/index.php index 592919c..c7459a4 100644 --- a/www/index.php +++ b/www/index.php @@ -2,39 +2,31 @@ use \NeonXP\TelegramApi\Telegram; use \Doctrine\Common\Annotations\AnnotationRegistry; -use \NeonXP\TelegramApi\Types\Message; -use \NeonXP\TelegramApi\Types\InputFile; -use \NeonXP\TelegramApi\Script; -use \NeonXP\TelegramApi\Script\State; -use \NeonXP\TelegramApi\Script\Conditions\isText; -use \NeonXP\TelegramApi\Script\Conditions\isMatch; -use \NeonXP\TelegramApi\Script\Conditions\isAnyText; -use \NeonXP\TelegramApi\Script\Conditions\isContact; -use \NeonXP\TelegramApi\Script\Conditions\isPhoto; -use \NeonXP\TelegramApi\Script\Conditions\isSticker; -use \NeonXP\TelegramApi\Script\Conditions\isLocation; -use \NeonXP\TelegramApi\Script\Conditions\isDocument; -use \NeonXP\TelegramApi\Script\Conditions\isReply; -use \NeonXP\TelegramApi\Script\Conditions\isForward; -use \NeonXP\TelegramApi\Script\Conditions\isVideo; -use \NeonXP\TelegramApi\Script\Conditions\isVoice; -use \NeonXP\TelegramApi\Script\Conditions\isAudio; -use \NeonXP\TelegramApi\Helpers\StatusActions; -require './../vendor/autoload.php'; +require __DIR__ . '/../vendor/autoload.php'; AnnotationRegistry::registerAutoloadNamespace( 'JMS\Serializer\Annotation', __DIR__.'/../vendor/jms/serializer/src' ); -$cache = new \Doctrine\Common\Cache\ApcuCache(); - -$dozorApi = new \NeonXP\DozorApi($cache); - $telegram = new Telegram([ - 'token' => getenv('TELEGRAM_BOT_TOKEN') + 'token' => getenv('TELEGRAM_BOT_TOKEN'), ]); -$telegram->setCache($cache); -$telegram->setScript(\NeonXP\BotScript::getScript($telegram, $dozorApi)); -$telegram->handleWebhook(); + +if (getenv('env') == 'dev') { + $cache = new \Doctrine\Common\Cache\ArrayCache(); + $dozorApi = new \NeonXP\DozorApi($cache); + $telegram->setCache($cache); + $telegram->setScript(\NeonXP\BotScript::getScript($telegram, $dozorApi)); + while(1) { + $telegram->handleGetUpdates(); + sleep(1); + } +} else { + $cache = new \Doctrine\Common\Cache\ApcuCache(); + $dozorApi = new \NeonXP\DozorApi($cache); + $telegram->setCache($cache); + $telegram->setScript(\NeonXP\BotScript::getScript($telegram, $dozorApi)); + $telegram->handleWebhook(); +} diff --git a/www/static/openshift-logo.png b/www/static/openshift-logo.png Binary files differdeleted file mode 100644 index e83e59b..0000000 --- a/www/static/openshift-logo.png +++ /dev/null |