addCommand( new class extends Command { protected $name = 'chatid'; protected $description = 'Get the id for this chat.'; public function handle($arguments) { $this->replyWithMessage([ 'text' => $this->getUpdate()->get('message')->get('chat')->get('id') ]); } } ); getTelegram()->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