getWebhookUpdates())) { getTelegram()->sendMessage([ 'chat_id' => getTelegram()->getWebhookUpdates()->get('message')->get('chat')->get('id'), 'text' => "Sorry, Dad says I can't talk to you." ]); exit(0); } getTelegram()->addCommand( new class extends Command { protected $name = 'searchmovies'; protected $description = 'Search through the movie collection'; public function handle($arguments) { $top5 = ∘(unlines, aaray_column('title'), aaray_slice(0)(5), 'array_reverse', 'array_values', ssort(∘(∘f(field('similarity')), ⬄, field('similarity')))); $movies = map(function($movie) use ($arguments) { similar_text($arguments, substr($movie, 0, -7) ?: '', $perc); return ['title' => $movie, 'similarity' => $perc]; })(scandir('/mnt/media/Movies')); $this->replyWithMessage( [ 'text' => "Here are the most similar movies titles I could find...\n\n" . $top5($movies) ] ); } } ); getTelegram()->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) { $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 \of M') ); }, getMessagesFromInbox( getInbox( 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay' ), require 'rules.php', FALSE ) ) ?: ['You have no unpaid bills! Nice one.'] ) ]); } } ); getTelegram()->addCommand( new class extends Command { protected $name = 'paybill'; protected $description = 'Mark a bill as paid'; public function handle($arguments) { 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