+++ /dev/null
-<?php declare(strict_types=1);
-
-namespace Commands;
-
-use Telegram\Bot\Actions;
-use Telegram\Bot\Commands\Command;
-
-class MyBills extends Command {
- CONST CAM = 131202815;
- CONST ASH = 242626501;
-
- protected $name = "mybills";
-
- protected $description = "List my bills 💰";
-
- private static function splitBill($amount) {
- return floor($amount/2);
- }
-
- private static function identity($x) {
- return $x;
- }
-
- private function generateMessages($imapResource, $rules) {
- return array_filter(array_map(
- function($email) use ($imapResource, $reminder) {
- $emails = imap_search($imapResource, 'SEEN ' . $email['imapQuery']);
-
- if(!$emails) {
- return '';
- }
-
- preg_match($email['regex'], $email['messageTransform'](imap_fetchbody($imapResource, $emails[0], 1)), $matches);
-
- return sprintf(
- $email['telegramMessage'],
- splitBill($matches['amount']),
- (new DateTimeImmutable(
- $email['dateTransform']($matches['due'])
- ))->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: \$(?<amount>[0-9]+(\.[0-9]{2})?) Due (?<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:.*(?<due>\d{1,2}\/\d{2}\/\d{4}).*Amount to pay:.*\$(?<amount>[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 \$(?<amount>[0-9]+(\.[0-9]{2})?).*Due Date (?<due>\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: \$(?<amount>[0-9]+(\.[0-9]{2})?).*Direct Debit date: (?<due>\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