1 <?php
declare(strict_types
=1);
11 getMessageSenderDisplayName
,
14 use Telegram\Bot\Actions
;
15 use Telegram\Bot\Commands\Command
;
17 getTelegram()->addCommand(
18 new class extends Command
{
19 protected $name = 'mybills';
20 protected $description = 'List my bills';
22 public function handle($arguments) {
23 if (!canChatWith($this->getUpdate())) {
24 $this->replyWithMessage(['text' => "Sorry, Dad says I can't talk to you."]);
28 $this->replyWithMessage(['text' => 'Fetching ' . getMessageSenderDisplayName($this->getUpdate()) . "'s unpaid bills. Just a sec ..."]);
29 $this->replyWithChatAction(['action' => Actions
::TYPING
]);
30 $this->replyWithMessage([
36 "%s (%s): $%s each due on the %s",
39 splitBill($bill['amount']),
40 $bill['due']->format('jS')
45 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'
57 getTelegram()->addCommand(
58 new class extends Command
{
59 protected $name = 'paybill';
60 protected $description = 'Mark a bill as paid';
62 public function handle($arguments) {
63 if (!canChatWith($this->getUpdate())) {
64 $this->replyWithMessage(['text' => "Sorry, Dad says I can't talk to you."]);
69 $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..."]);
70 $this->triggerCommand('mybills');
73 $messages = array_values(array_filter(
76 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'
81 function($e) use ($arguments) {
82 return $e['id'] == $arguments;
86 if(!$messages ||
count($messages) !== 1) {
87 $this->replyWithMessage(['text' => "That doesn't look like a valid id. Use /mybills to list your bills."]);
90 imap_delete(getInbox('Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'), $messages[0]['uid'], FT_UID
);
91 $this->replyWithMessage(['text' => "I marked " . getMessageSenderDisplayName($this->getUpdate()) . " as having paid the " . strtolower($messages[0]['service']) . " bill, thanks!"]);
97 getTelegram()->commandsHandler(true
); //must come afterwards because lolzer