From b6d0cdb1f3d8e747219cb2d8518a4dad223022fb Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Fri, 16 Nov 2018 11:23:23 +0800 Subject: [PATCH 1/1] Initial commit --- .gitignore | 1 + Commands/MyBills.php | 105 ++++++ bins.php | 12 + common.php | 86 +++++ composer.json | 5 + composer.lock | 753 ++++++++++++++++++++++++++++++++++++++++++ purjolok.php | 97 ++++++ readEmailsAndSendMessages.php | 44 +++ rules.php | 40 +++ wednesday.php | 87 +++++ 10 files changed, 1230 insertions(+) create mode 100644 .gitignore create mode 100644 Commands/MyBills.php create mode 100644 bins.php create mode 100644 common.php create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 purjolok.php create mode 100644 readEmailsAndSendMessages.php create mode 100644 rules.php create mode 100644 wednesday.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f4773f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.php diff --git a/Commands/MyBills.php b/Commands/MyBills.php new file mode 100644 index 0000000..e6aaf8f --- /dev/null +++ b/Commands/MyBills.php @@ -0,0 +1,105 @@ +format('jS') + ); + }, + $rules + ), function($message) { + return !!$message; + }); + } + + public function handle($arguments) + { + + if ((int)$this->getUpdate()->get('message')->get('from')->get('id') == self::CAM) { + $inbox = 'Utilities/Cam To Pay'; + } elseif ((int)$this->getUpdate()->get('message')->get('from')->get('id') == self::ASH) { + $inbox = 'Utilities/Ash To Pay'; + } + + $mailbox = '{imap.gmail.com:993/debug/imap/ssl/novalidate-cert}' . $inbox; + $username = 'molelord@gmail.com'; + $password = '#NiceMeme420!'; + + $memes = [ + 'Electricity' => [ + 'imapQuery' => 'FROM "@synergy.net.au"', + 'regex' => '/New charges: \$(?[0-9]+(\.[0-9]{2})?) Due (?\d{1,2} \w{3} \d+)/', + 'messageTransform' => 'identity', + 'dateTransform' => 'identity', + 'telegramMessage' => "Electricity bill: $%s each due on the %s" + ], + 'Water' => [ + 'imapQuery' => 'FROM "@watercorporation.com.au"', + 'regex' => '/Due date:.*(?\d{1,2}\/\d{2}\/\d{4}).*Amount to pay:.*\$(?[0-9]+(\.[0-9]{2})?)/', + 'messageTransform' => function($message) { + return implode(" ", array_map('trim', explode("\n", strip_tags(base64_decode($message))))); + }, + 'dateTransform' => function($date) { + return str_replace('/', '-', $date); + }, + 'telegramMessage' => "Water bill: $%s each due on the %s" + ], + 'Internet' => [ + 'imapQuery' => 'FROM "@online.telstra.com"', + 'regex' => '/Total \$(?[0-9]+(\.[0-9]{2})?).*Due Date (?\d{1,2} \w{3} \d{4})/', + 'messageTransform' => function($message) { + return implode(" ", array_map('trim', explode("\n", strip_tags(html_entity_decode($message))))); + }, + 'dateTransform' => 'identity', + 'telegramMessage' => "Internet bill: $%s each due on the %s" + ], + 'Gas' => [ + 'imapQuery' => 'FROM "@energy.agl.com.au"', + 'regex' => '/Direct Debit amount: \$(?[0-9]+(\.[0-9]{2})?).*Direct Debit date: (?\d{1,2} \w{3} \d+)/', + 'messageTransform' => function($message) { + return implode(" ", array_map('trim', explode("\n", $message))); + }, + 'dateTransform' => 'identity', + 'telegramMessage' => "Gas bill: $%s each due on the %s" + ] + ]; + + $imapResource = imap_open($mailbox, $username, $password); + $messages = $this->generateMessages($imapResource, $memes); + $this->replyWithMessage(['text' => $this->getUpdate()->get('message')->get('from')->get('id')]); + } +} \ No newline at end of file diff --git a/bins.php b/bins.php new file mode 100644 index 0000000..8473ea4 --- /dev/null +++ b/bins.php @@ -0,0 +1,12 @@ +sendMessage( + [ + 'chat_id' => CHAT_ID, + 'text' => 'Take out that BINZ #TrashSLAM 🚮' + ] +); diff --git a/common.php b/common.php new file mode 100644 index 0000000..324fe6c --- /dev/null +++ b/common.php @@ -0,0 +1,86 @@ +get('message')->get('from')->get('id')]; +} + +function getMessageSenderDisplayName($update) { + return $update->get('message')->get('from')->get('first_name'); +} + +function canChatWith($update) { + return in_array($update->get('message')->get('from')->get('id'), array_keys(PARTICIPANT_IDS)); +} + +function debug($whatever) { + echo '
';
+    print_r($whatever);
+    echo '
'; +} + +function getInbox($inbox) { + STATIC $inboxes; + + if (!isset($inboxes[$inbox])) { + $inboxes[$inbox] = imap_open( + '{imap.gmail.com:993/debug/imap/ssl/novalidate-cert}' . $inbox, + EMAIL, + PASSWORD + ); + } + + return $inboxes[$inbox]; +} + +function getMessagesFromInbox($inbox, array $rules, $unseenOnly = true) { + return array_filter( + array_map( + function($rule, $service) use ($inbox, $unseenOnly) { + $emails = imap_search($inbox, ['SEEN ', 'UNSEEN '][$unseenOnly] . $rule['imapQuery'], SE_UID); + + if(!$emails) { + return []; + } + + $body = imap_fetchbody($inbox, $emails[0], '1', FT_UID); + preg_match($rule['regex'], $rule['messageTransform']($body), $matches); + + return [ + 'service' => $service, + 'id' => substr(md5($body), 0, 6), + 'uid' => $emails[0], + 'telegramMessage' => $rule['telegramMessage'], + 'due' => new DateTimeImmutable($rule['dateTransform']($matches['due'])), + 'amount' => $matches['amount'] + ]; + }, + $rules, + array_keys($rules) + ), + function($e) { + return !!$e; + } + ); +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..cda6a21 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "irazasyed/telegram-bot-sdk": "^2.0" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..fdd80a0 --- /dev/null +++ b/composer.lock @@ -0,0 +1,753 @@ +{ + "_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" + ], + "content-hash": "4fc59fc846328b44db644ed8cd44face", + "packages": [ + { + "name": "doctrine/inflector", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "e11d84c6e018beedd929cff5220969a3c6d1d462" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/e11d84c6e018beedd929cff5220969a3c6d1d462", + "reference": "e11d84c6e018beedd929cff5220969a3c6d1d462", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" + } + }, + "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": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2017-07-22T12:18:28+00:00" + }, + { + "name": "guzzlehttp/guzzle", + "version": "6.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.4", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0 || ^5.0", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "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": "2017-06-22T18:50:49+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-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-12-20T10:07:11+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "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.4-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" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2017-03-20T17:10:46+00:00" + }, + { + "name": "illuminate/contracts", + "version": "v5.5.17", + "source": { + "type": "git", + "url": "https://github.com/illuminate/contracts.git", + "reference": "d9e269284eba43bd2e9e8d1f1ba12362b00ec096" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/d9e269284eba43bd2e9e8d1f1ba12362b00ec096", + "reference": "d9e269284eba43bd2e9e8d1f1ba12362b00ec096", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/container": "~1.0", + "psr/simple-cache": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.5-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Contracts\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Contracts package.", + "homepage": "https://laravel.com", + "time": "2017-09-19T13:09:37+00:00" + }, + { + "name": "illuminate/support", + "version": "v5.5.17", + "source": { + "type": "git", + "url": "https://github.com/illuminate/support.git", + "reference": "132b06edaab3808f63943004911d58785f164ab4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/support/zipball/132b06edaab3808f63943004911d58785f164ab4", + "reference": "132b06edaab3808f63943004911d58785f164ab4", + "shasum": "" + }, + "require": { + "doctrine/inflector": "~1.1", + "ext-mbstring": "*", + "illuminate/contracts": "5.5.*", + "nesbot/carbon": "^1.20", + "php": ">=7.0" + }, + "replace": { + "tightenco/collect": "self.version" + }, + "suggest": { + "illuminate/filesystem": "Required to use the composer class (5.2.*).", + "symfony/process": "Required to use the composer class (~3.3).", + "symfony/var-dumper": "Required to use the dd function (~3.3)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.5-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Support\\": "" + }, + "files": [ + "helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Support package.", + "homepage": "https://laravel.com", + "time": "2017-10-17T12:18:29+00:00" + }, + { + "name": "irazasyed/telegram-bot-sdk", + "version": "v2.2.0", + "source": { + "type": "git", + "url": "https://github.com/irazasyed/telegram-bot-sdk.git", + "reference": "2824278370b231dfc9172104db8acc23fc5ade94" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/irazasyed/telegram-bot-sdk/zipball/2824278370b231dfc9172104db8acc23fc5ade94", + "reference": "2824278370b231dfc9172104db8acc23fc5ade94", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "~6.0", + "illuminate/support": "~5.0", + "php": ">=5.5.0" + }, + "require-dev": { + "phpspec/prophecy": "^1.5", + "phpunit/phpunit": "^4.8 || ^5.0" + }, + "suggest": { + "illuminate/container": "Hold dependencies to be injected in commands constructors", + "irazasyed/larasupport": "Allows you to use any Laravel Package in Lumen by adding support!" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Telegram\\Bot\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Syed Irfaq R.", + "email": "syed+gh@lukonet.com", + "homepage": "https://github.com/irazasyed" + } + ], + "description": "The Unofficial Telegram Bot API PHP SDK", + "homepage": "https://github.com/irazasyed/telegram-bot-sdk", + "keywords": [ + "laravel", + "laravel telegram", + "telegram", + "telegram bot", + "telegram bot api", + "telegram php", + "telegram sdk" + ], + "time": "2017-01-05T09:01:54+00:00" + }, + { + "name": "nesbot/carbon", + "version": "1.22.1", + "source": { + "type": "git", + "url": "https://github.com/briannesbitt/Carbon.git", + "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", + "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "symfony/translation": "~2.6 || ~3.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2", + "phpunit/phpunit": "~4.0 || ~5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.23-dev" + } + }, + "autoload": { + "psr-4": { + "Carbon\\": "src/Carbon/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + } + ], + "description": "A simple API extension for DateTime.", + "homepage": "http://carbon.nesbot.com", + "keywords": [ + "date", + "datetime", + "time" + ], + "time": "2017-01-16T07:55:07+00:00" + }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "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", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "psr/simple-cache", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/753fa598e8f3b9966c886fe13f370baa45ef0e24", + "reference": "753fa598e8f3b9966c886fe13f370baa45ef0e24", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "time": "2017-01-02T13:31:39+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", + "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2017-10-11T12:05:26+00:00" + }, + { + "name": "symfony/translation", + "version": "v3.3.10", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "409bf229cd552bf7e3faa8ab7e3980b07672073f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/409bf229cd552bf7e3faa8ab7e3980b07672073f", + "reference": "409bf229cd552bf7e3faa8ab7e3980b07672073f", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/config": "<2.8", + "symfony/yaml": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0", + "symfony/intl": "^2.8.18|^3.2.5", + "symfony/yaml": "~3.3" + }, + "suggest": { + "psr/log": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com", + "time": "2017-10-02T06:42:24+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/purjolok.php b/purjolok.php new file mode 100644 index 0000000..69e22d4 --- /dev/null +++ b/purjolok.php @@ -0,0 +1,97 @@ +addCommand( + new class extends Command { + protected $name = 'mybills'; + protected $description = 'List my bills'; + + public function handle($arguments) { + if (!canChatWith($this->getUpdate())) { + $this->replyWithMessage(['text' => "Sorry, Dad says I can't talk to you."]); + return; + } + + $this->replyWithMessage(['text' => 'Fetching ' . getMessageSenderDisplayName($this->getUpdate()) . "'s unpaid bills. Just a sec ..."]); + $this->replyWithChatAction(['action' => Actions::TYPING]); + $this->replyWithMessage([ + 'text' => implode( + "\n", + array_map( + function($bill) { + return sprintf( + "%s (%s): $%s each due on the %s", + $bill['service'], + $bill['id'], + splitBill($bill['amount']), + $bill['due']->format('jS') + ); + }, + getMessagesFromInbox( + getInbox( + 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay' + ), + require 'rules.php', + FALSE + ) + ) + ) + ]); + } + } +); + +getTelegram()->addCommand( + new class extends Command { + protected $name = 'paybill'; + protected $description = 'Mark a bill as paid'; + + public function handle($arguments) { + if (!canChatWith($this->getUpdate())) { + $this->replyWithMessage(['text' => "Sorry, Dad says I can't talk to you."]); + return; + } + + if (!$arguments) { + $this->replyWithMessage(['text' => "I need the bill id. The /mybills command lists all your bills with the ids in brackets. Here, I'll show you..."]); + $this->triggerCommand('mybills'); + } + + $messages = array_values(array_filter( + getMessagesFromInbox( + getInbox( + 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay' + ), + require 'rules.php', + FALSE + ), + function($e) use ($arguments) { + return $e['id'] == $arguments; + } + )); + + if(!$messages || count($messages) !== 1) { + $this->replyWithMessage(['text' => "That doesn't look like a valid id. Use /mybills to list your bills."]); + } + + imap_delete(getInbox('Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'), $messages[0]['uid'], FT_UID); + $this->replyWithMessage(['text' => "I marked " . getMessageSenderDisplayName($this->getUpdate()) . " as having paid the " . strtolower($messages[0]['service']) . " bill, thanks!"]); + } + } + +); + +getTelegram()->commandsHandler(true); //must come afterwards because lolzer diff --git a/readEmailsAndSendMessages.php b/readEmailsAndSendMessages.php new file mode 100644 index 0000000..b13741e --- /dev/null +++ b/readEmailsAndSendMessages.php @@ -0,0 +1,44 @@ +sendMessage( + [ + 'chat_id' => CHAT_ID, + 'text'=> $message + ] + ); + }, + array_merge( + array_map( + function($message) { + return sprintf( + '[REMINDER: %d DAYS] ' . $message['telegramMessage'], + REMIND_THRESHOLD, + splitBill($message['amount']), + $message['due']->format('jS') + ); + }, + array_filter( + getMessagesFromInbox(getInbox('Multiple Inboxes/Needs Action'), require 'rules.php', false), + function($message) { + return $message['due']->diff(new DateTimeImmutable)->d == REMIND_THRESHOLD; + } + ) + ), + array_map( + function($message) { + return sprintf( + $message['telegramMessage'], + splitBill($message['amount']), + $message['due']->format('jS') + ); + }, + getMessagesFromInbox(getInbox('Multiple Inboxes/Needs Action'), require 'rules.php') + ) + ) +); diff --git a/rules.php b/rules.php new file mode 100644 index 0000000..e31341c --- /dev/null +++ b/rules.php @@ -0,0 +1,40 @@ + [ + 'imapQuery' => 'FROM "@synergy.net.au"', + 'regex' => '/New charges: \$(?[0-9]+(\.[0-9]{2})?) Due (?\d{1,2} \w{3} \d+)/', + 'messageTransform' => 'Common\identity', + 'dateTransform' => 'Common\identity', + 'telegramMessage' => "Electricity bill: $%s each due on the %s" + ], + 'Water' => [ + 'imapQuery' => 'FROM "@watercorporation.com.au"', + 'regex' => '/Due date:.*?(?\d{1,2}\/\d{2}\/\d{4}).*?Amount to pay:.*\$(?[0-9]+(\.[0-9]{2})?)/', + 'messageTransform' => function($message) { + return implode(" ", array_map('trim', explode("\n", strip_tags(base64_decode($message))))); + }, + 'dateTransform' => function($date) { + return str_replace('/', '-', $date); + }, + 'telegramMessage' => "Water bill: $%s each due on the %s" + ], + 'Internet' => [ + 'imapQuery' => 'FROM "@online.telstra.com"', + 'regex' => '/Total \$(?[0-9]+(\.[0-9]{2})?).*?Due Date (?\d{1,2} \w{3} \d{4})/', + 'messageTransform' => function($message) { + return implode(" ", array_map('trim', explode("\n", strip_tags(html_entity_decode($message))))); + }, + 'dateTransform' => 'Common\identity', + 'telegramMessage' => "Internet bill: $%s each due on the %s" + ], + 'Gas' => [ + 'imapQuery' => 'FROM "@energy.agl.com.au"', + 'regex' => '/Direct Debit amount: \$(?[0-9]+(\.[0-9]{2})?).*?Direct Debit date: (?\d{1,2} \w{3} \d+)/', + 'messageTransform' => function($message) { + return implode(" ", array_map('trim', explode("\n", $message))); + }, + 'dateTransform' => 'Common\identity', + 'telegramMessage' => "Gas bill: $%s each due on the %s" + ] +]; diff --git a/wednesday.php b/wednesday.php new file mode 100644 index 0000000..14dae41 --- /dev/null +++ b/wednesday.php @@ -0,0 +1,87 @@ +sendMessage( + [ + 'chat_id' => CHAT_ID, + 'parse_mode' => 'Markdown', + 'text' => implode("\n", [ + "```", + "🐸 MEME ALERT MY DUDES 🐸", + " ** It is Wednesday **", + " Meme Inbound", + "🐸 MEME ALERT MY DUDES 🐸", + "```" + ]) + ] +); + +getTelegram()->sendChatAction(['chat_id' => CHAT_ID, 'action' => Actions::TYPING]); + +sleep(2); + +getTelegram()->sendMessage( + [ + 'chat_id' => CHAT_ID, + 'text' => 'https://www.youtube.com/watch?v=' . $wednesdays[(int)(new DateTimeImmutable)->format("W") - 1] + ] +); -- 2.11.0