Don't need the commands classes anymore
authorCameron Ball <cameron@cameron1729.xyz>
Sun, 18 Nov 2018 04:26:56 +0000 (12:26 +0800)
committerCameron Ball <cameron@cameron1729.xyz>
Sun, 18 Nov 2018 04:26:56 +0000 (12:26 +0800)
Commands/MyBills.php [deleted file]
common.php

diff --git a/Commands/MyBills.php b/Commands/MyBills.php
deleted file mode 100644 (file)
index e6aaf8f..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-<?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
index 17f6800..5244cfe 100644 (file)
@@ -3,7 +3,6 @@
 namespace Common;
 
 require 'vendor/autoload.php';
-require 'Commands/MyBills.php';
 require '../../config.php';
 
 use Telegram\Bot\Api;