diff options
author | Alexander NeonXP Kiryukhin <frei@neonxp.info> | 2016-05-27 14:55:52 +0300 |
---|---|---|
committer | Alexander NeonXP Kiryukhin <frei@neonxp.info> | 2016-05-27 14:55:52 +0300 |
commit | 7746e8bcfe3a57501fb44ab1f9a664fee2a1326f (patch) | |
tree | dfb0d981754a63048d72c067e15dd89c73ab3ee8 | |
parent | d51264c55ba73330cf129b43f635c9489fe663f9 (diff) |
initial
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | composer.json | 18 | ||||
-rw-r--r-- | composer.lock | 828 | ||||
-rw-r--r-- | config/nginx.d/default.conf.erb | 2 | ||||
-rw-r--r-- | config/php.d/extensions.ini | 3 | ||||
-rw-r--r-- | src/NeonXP/BotScript.php | 73 | ||||
-rw-r--r-- | src/NeonXP/DozorApi.php | 112 | ||||
-rw-r--r-- | www/index.php | 126 |
8 files changed, 1077 insertions, 86 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..22d0d82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..2a4568e --- /dev/null +++ b/composer.json @@ -0,0 +1,18 @@ +{ + "name": "neonxp/bot", + "authors": [ + { + "name": "Alexander NeonXP Kiryukhin", + "email": "frei@neonxp.info" + } + ], + "autoload": { + "psr-0": { + "NeonXP": "src/" + } + }, + "minimum-stability": "dev", + "require": { + "neonxp/telegram-api": "dev-master" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..e768e91 --- /dev/null +++ b/composer.lock @@ -0,0 +1,828 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "ab6d18a75d53e6ce7e09d13e1cd21c75", + "content-hash": "37cc07983cf693f0d4af43c8cced2b31", + "packages": [ + { + "name": "doctrine/annotations", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "2e1b1f7597e2f647e99e96e747fcae9718ac817b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/2e1b1f7597e2f647e99e96e747fcae9718ac817b", + "reference": "2e1b1f7597e2f647e99e96e747fcae9718ac817b", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": ">=5.3.2" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Annotations\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2016-03-24 07:09:52" + }, + { + "name": "doctrine/cache", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/cache.git", + "reference": "4e3b8b9464d511eccbefe07cef94c275bce7e434" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/cache/zipball/4e3b8b9464d511eccbefe07cef94c275bce7e434", + "reference": "4e3b8b9464d511eccbefe07cef94c275bce7e434", + "shasum": "" + }, + "require": { + "php": "~5.5|~7.0" + }, + "conflict": { + "doctrine/common": ">2.2,<2.4" + }, + "require-dev": { + "phpunit/phpunit": "~4.8|~5.0", + "predis/predis": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Caching library offering an object-oriented API for many cache backends", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2016-03-11 16:30:04" + }, + { + "name": "doctrine/instantiator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "416fb8ad1d095a87f1d21bc40711843cd122fd4a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/416fb8ad1d095a87f1d21bc40711843cd122fd4a", + "reference": "416fb8ad1d095a87f1d21bc40711843cd122fd4a", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2016-03-31 10:24:22" + }, + { + "name": "doctrine/lexer", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09 13:34:57" + }, + { + "name": "guzzlehttp/guzzle", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "b1a96f6134f69cb41f8538d3a6491f4bb1dbab78" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/b1a96f6134f69cb41f8538d3a6491f4bb1dbab78", + "reference": "b1a96f6134f69cb41f8538d3a6491f4bb1dbab78", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "~1.0", + "guzzlehttp/psr7": "~1.1", + "php": ">=5.5.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0", + "psr/log": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.2-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2016-05-08 19:39:56" + }, + { + "name": "guzzlehttp/promises", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8", + "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-03-08 01:15:46" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "31382fef2889136415751badebbd1cb022a4ed72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72", + "reference": "31382fef2889136415751badebbd1cb022a4ed72", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "PSR-7 message implementation", + "keywords": [ + "http", + "message", + "stream", + "uri" + ], + "time": "2016-04-13 19:56:01" + }, + { + "name": "jms/metadata", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/metadata.git", + "reference": "427a06e7c25d0fa1fbd37bf0325d9d3eb2dc383a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/metadata/zipball/427a06e7c25d0fa1fbd37bf0325d9d3eb2dc383a", + "reference": "427a06e7c25d0fa1fbd37bf0325d9d3eb2dc383a", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "doctrine/cache": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5.x-dev" + } + }, + "autoload": { + "psr-0": { + "Metadata\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Class/method/property metadata management in PHP", + "keywords": [ + "annotations", + "metadata", + "xml", + "yaml" + ], + "time": "2015-01-14 15:37:39" + }, + { + "name": "jms/parser-lib", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/parser-lib.git", + "reference": "6067cc609074ae215b96dc51047affee65f77b0f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/parser-lib/zipball/6067cc609074ae215b96dc51047affee65f77b0f", + "reference": "6067cc609074ae215b96dc51047affee65f77b0f", + "shasum": "" + }, + "require": { + "phpoption/phpoption": ">=0.9,<2.0-dev" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-0": { + "JMS\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "description": "A library for easily creating recursive-descent parsers.", + "time": "2014-07-08 16:40:41" + }, + { + "name": "jms/serializer", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/serializer.git", + "reference": "602bd84453b3b080c0aa4c4bd09a0024b8a08ea4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/602bd84453b3b080c0aa4c4bd09a0024b8a08ea4", + "reference": "602bd84453b3b080c0aa4c4bd09a0024b8a08ea4", + "shasum": "" + }, + "require": { + "doctrine/annotations": "^1.0", + "doctrine/instantiator": "^1.0.3", + "jms/metadata": "~1.1", + "jms/parser-lib": "1.*", + "php": ">=5.5.0", + "phpcollection/phpcollection": "~0.1", + "phpoption/phpoption": "^1.1" + }, + "conflict": { + "twig/twig": "<1.12" + }, + "require-dev": { + "doctrine/orm": "~2.1", + "doctrine/phpcr-odm": "^1.3", + "jackalope/jackalope-doctrine-dbal": "^1.1.5", + "phpunit/phpunit": "^4.8|^5.0", + "propel/propel1": "~1.7", + "symfony/filesystem": "^2.1", + "symfony/form": "~2.1", + "symfony/translation": "^2.1", + "symfony/validator": "^2.2", + "symfony/yaml": "^2.1", + "twig/twig": "~1.12|~2.0" + }, + "suggest": { + "symfony/yaml": "Required if you'd like to serialize data to YAML format." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-0": { + "JMS\\Serializer": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML.", + "homepage": "http://jmsyst.com/libs/serializer", + "keywords": [ + "deserialization", + "jaxb", + "json", + "serialization", + "xml" + ], + "time": "2016-05-12 12:20:22" + }, + { + "name": "neonxp/telegram-api", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/NeonXP/TelegramApi.git", + "reference": "37ab7ca5510b9ecd42c7263b87b3294278838821" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/NeonXP/TelegramApi/zipball/37ab7ca5510b9ecd42c7263b87b3294278838821", + "reference": "37ab7ca5510b9ecd42c7263b87b3294278838821", + "shasum": "" + }, + "require": { + "doctrine/cache": "^1.4", + "guzzlehttp/guzzle": "^6.1", + "jms/serializer": "^1.0", + "psr/log": "^1.0@dev" + }, + "type": "project", + "autoload": { + "psr-0": { + "NeonXP": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0" + ], + "authors": [ + { + "name": "Alexander NeonXP Kiryukhin", + "email": "frei@neonxp.info" + } + ], + "time": "2016-01-06 21:11:59" + }, + { + "name": "phpcollection/phpcollection", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/php-collection.git", + "reference": "f2bcff45c0da7c27991bbc1f90f47c4b7fb434a6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/php-collection/zipball/f2bcff45c0da7c27991bbc1f90f47c4b7fb434a6", + "reference": "f2bcff45c0da7c27991bbc1f90f47c4b7fb434a6", + "shasum": "" + }, + "require": { + "phpoption/phpoption": "1.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.4-dev" + } + }, + "autoload": { + "psr-0": { + "PhpCollection": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "General-Purpose Collection Library for PHP", + "keywords": [ + "collection", + "list", + "map", + "sequence", + "set" + ], + "time": "2015-05-17 12:39:23" + }, + { + "name": "phpoption/phpoption", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/php-option.git", + "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/94e644f7d2051a5f0fcf77d81605f152eecff0ed", + "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "4.7.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-0": { + "PhpOption\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Option Type for PHP", + "keywords": [ + "language", + "option", + "php", + "type" + ], + "time": "2015-07-25 16:39:46" + }, + { + "name": "psr/http-message", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2015-05-04 20:22:00" + }, + { + "name": "psr/log", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d8e60a5619fff77f9669da8997697443ef1a1d7e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d8e60a5619fff77f9669da8997697443ef1a1d7e", + "reference": "d8e60a5619fff77f9669da8997697443ef1a1d7e", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-01-06 21:40:42" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": { + "neonxp/telegram-api": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/config/nginx.d/default.conf.erb b/config/nginx.d/default.conf.erb index d82da13..c7bf65e 100644 --- a/config/nginx.d/default.conf.erb +++ b/config/nginx.d/default.conf.erb @@ -19,7 +19,7 @@ server { include openshift_params; # uncomment to export all environment variables to fastcgi - #include <%= ENV['OPENSHIFT_REPO_DIR'] %>/config/nginx.d/export_env; + include <%= ENV['OPENSHIFT_REPO_DIR'] %>/config/nginx.d/export_env; } # avoid unnecessary log diff --git a/config/php.d/extensions.ini b/config/php.d/extensions.ini index 0379fe6..e6559d9 100644 --- a/config/php.d/extensions.ini +++ b/config/php.d/extensions.ini @@ -41,5 +41,4 @@ extension=xml.so extension=xmlwriter.so extension=xsl.so extension=wddx.so -extension=zip.so -#extension=mongodb.so +extension=zip.so
\ No newline at end of file diff --git a/src/NeonXP/BotScript.php b/src/NeonXP/BotScript.php new file mode 100644 index 0000000..0a447bf --- /dev/null +++ b/src/NeonXP/BotScript.php @@ -0,0 +1,73 @@ +<?php + +namespace NeonXP; + +use Doctrine\Common\Cache\CacheProvider; +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\isMatch; +use \NeonXP\TelegramApi\Script\Conditions\isAnyText; +use \NeonXP\TelegramApi\Telegram; + +class BotScript +{ + public static function getScript(Telegram $telegram, DozorApi $dozorApi) + { + $saveLink = function (Message $message, Telegram $telegram) { + $telegram->getCache()->save("link_{$message->getChat()->getId()}", $message->getText()); + $telegram->getMethods()->sendMessage($message->getChat(), 'Ок, записал: ' . $message->getText()); + + return State::INITIAL; + }; + $showLink = function (Message $message, Telegram $telegram) { + $link = $telegram->getCache()->fetch("link_{$message->getChat()->getId()}"); + $telegram->getMethods()->sendMessage($message->getChat(), $link); + + return State::INITIAL; + }; + $sendCode = function (Message $message, Telegram $telegram) use ($dozorApi) { + $code = trim(substr($message->getText(),1)); + try { + $result = $dozorApi->sendCode($message->getChat(), $code); + }catch (\Exception $e) { + $telegram->getMethods()->sendMessage($message->getChat(), 'Ошибка сети', true); + } + + $telegram->getMethods()->sendMessage($message->getChat(), $result, true); + + + return State::INITIAL; //Set initial state + }; + $goBack = function (Message $message, Telegram $telegram) { + return State::INITIAL; + }; + $pause = function (Message $message, Telegram $telegram) { + return 'STATE_PAUSE'; + }; + + return (new Script($telegram))-> + state(State::INITIAL)-> //Start initial state + action(new isText('/link'), $showLink)-> + action(new isText('/setlink'), [ + 'Пришлите ссылку с пином /cancel', + 'STATE_SET_LINK' + ])-> + action(new isText('/pause'), [ + 'Замер. /resume для возврата', + 'STATE_PAUSE' + ])-> + action(new isMatch('/^\!.+?$/i'), $sendCode)-> + action(new isAnyText(), $goBack)-> + end()-> + state('STATE_SET_LINK')-> + action(new isText('/cancel'), $goBack)-> + action(new isAnyText(), $saveLink)-> + end()-> + state('STATE_PAUSE')-> + action(new isText('/resume'), ['Я вернулся!', State::INITIAL])-> + action(new isAnyText(), $pause)-> + end(); + } +}
\ No newline at end of file diff --git a/src/NeonXP/DozorApi.php b/src/NeonXP/DozorApi.php new file mode 100644 index 0000000..c3b492e --- /dev/null +++ b/src/NeonXP/DozorApi.php @@ -0,0 +1,112 @@ +<?php +/** + * @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 +{ + /** + * @var CacheProvider + */ + private $cache; + + /** + * DozorApi constructor. + * @param CacheProvider $cache + */ + public function __construct(CacheProvider $cache) + { + $this->cache = $cache; + } + + public function sendCode(Chat $chat, $code) + { + $params = [ + "log" => 'on', + "mes" => '', + "legend" => 'on', + "nostat" => '', + "notext" => '', + "refresh" => '0', + "bonus" => '', + "kladMap" => '', + "notags" => '', + "cod" => $code, + "action" => 'entcod', + ]; + $data = http_build_query($params); + $context = [ + 'http' => [ + 'method' => 'POST', + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'content' => $data + ] + ]; + $context = stream_context_create($context); + $result = file_get_contents($this->getLink($chat), false, $context); + + return $this->parseResult($result); + } + + private function parseResult($html) + { + $crawler = new Crawler($html); + + $answer = [ + $this->parseCodeEnter($html), + $this->parseTask($crawler) + ]; + + $answer = array_merge($answer, $this->parseCodes($crawler)); + $answer = array_filter($answer); + + return implode(PHP_EOL, $answer); + } + + private function parseCodeEnter($html) + { + $result = iconv('cp1251', 'utf8', $html); + $result = mb_strtolower($result, 'utf8'); + if (strpos($result, 'код принят')) { + $result = 'Код принят'; + } else { + $result = 'Код НЕ принят'; + } + + return $result; + } + + private function parseTask(Crawler $crawler) + { + return $crawler->filter('body > p')->reduce(function ($node) { + return strpos($node->text(), 'Задание '); + })->text(); + } + + private function parseCodes(Crawler $crawler) + { + $codesHtml = $crawler->filter('body > .dcodes')->html(); + $codesHtml = preg_replace('/\<span\ style\=\"color\:red\"\>(.+?)\<\/span\>/i', '*[$1]*', $codesHtml); + $codesHtml = preg_replace('/\<br(\s*)?\/?\>/i', PHP_EOL, $codesHtml); + $codesHtml = strip_tags($codesHtml); + $codesHtml = explode(PHP_EOL, $codesHtml); + array_shift($codesHtml); + + return $codesHtml; + } + + private function getLink(Chat $chat) + { + return $this->cache->fetch("link_{$chat->getId()}"); + } +}
\ No newline at end of file diff --git a/www/index.php b/www/index.php index 74b121d..7278d8d 100644 --- a/www/index.php +++ b/www/index.php @@ -1,83 +1,43 @@ -<!doctype html> -<html> -<head> - <meta charset="utf-8" /> - <title>Welcome to OpenShift</title> - <link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet" type="text/css" /> - <style type="text/css"> - html, body { - margin: 0; - padding: 0; - } - - body { - font-family: 'Open Sans', sans-serif; - padding-top: 100px; - } - - h1 { - font-size: 52px; - margin-bottom: 0; - } - - h1, h2, p { - margin-top: 0; - font-weight: normal; - } - - a { - color: #DB242F; - } - - a:not(:hover) { - text-decoration: none; - } - - .container { - display: flex; - flex-direction: row; - margin: 0 auto; - width: 960px; - } - - .section { - padding: 15px; - } - - .section + .section { - margin-left: 15px; - } - - .welcome { - background: #eee; - border-radius: 5px; - text-align: center; - flex: 0 0 300px; - } - </style> -</head> -<body> - <div class="container"> - <div class="section welcome"> - <div> - <img src="/static/openshift-logo.png" alt="OpenShift Logo" /> - </div> - <h1>Welcome!</h1> - <p>You are running PHP <?php echo phpversion(); ?></p> - </div> - <div class="section"> - <h2>What's next?</h2> - <p>Make changes to this website by editing the files inside <code>www/</code> of your repository.</p> - <p>Commit your changes after, then push to the remote repository.</p> - <pre><code>$ git commit -a -m "Some commit message" -$ git push origin master</code></pre> - <h2>More</h2> - <ul> - <li>Visit <a href="http://www.openshift.com">http://www.openshift.com</a>.</li> - <li>Get help in the <a href="http://www.openshift.com/forums/openshift">OpenShift forums</a>.</li> - <li>More on the cartridge at <a href="https://github.com/pinodex/openshift-cartridge-nginx-php7">pinodex/openshift-cartridge-nginx-php7</a>.</li> - </ul> - </div> - </div> -</body> -</html>
\ No newline at end of file +<?php + +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'; + +AnnotationRegistry::registerAutoloadNamespace( + 'JMS\Serializer\Annotation', + __DIR__.'/../vendor/jms/serializer/src' +); +$script = require_once __DIR__ . '/script.php'; + +$pgsqlConnection = 'postgresql://' . getenv('OPENSHIFT_POSTGRESQL_DB_HOST') . ':' . getenv('OPENSHIFT_POSTGRESQL_DB_PORT'); + +$cache = new \Doctrine\Common\Cache\ApcuCache(); + +$dozorApi = new \NeonXP\DozorApi($cache); + +$telegram = new Telegram([ + 'token' => getenv('TELEGRAM_BOT_TOKEN') +]); +$telegram->setCache($cache); +$telegram->setScript(\NeonXP\BotScript::getScript($telegram, $dozorApi)); +$telegram->handleWebhook(); |