1 <?php
declare(strict_types
=1);
3 require_once('common.php');
5 use Telegram\Bot\Actions
;
6 use Telegram\Bot\Commands\Command
;
8 if(!canChatWith(getTelegram()->getWebhookUpdates())) {
9 getTelegram()->sendMessage([
10 'chat_id' => getTelegram()->getWebhookUpdates()->get('message')->get('from')->get('id'),
11 'text' => "Sorry, Dad says I can't talk to you."
16 getTelegram()->addCommand(
17 new class extends Command
{
18 protected $name = 'searchmovies';
19 protected $description = 'Search through the movie collection';
21 public function handle($arguments) {
23 function($moviename) use ($arguments) {
24 similar_text($arguments, substr($moviename, 0, -7) ?
: '', $perc);
25 return ['title' => $moviename, 'similarity' => $perc];
27 scandir('/mnt/media/Movies')
30 uasort($results, function($a, $b) {
31 return $b['similarity'] <=> $a['similarity'];
34 $results = array_column(array_slice(array_values($results), 0, 5), 'title');
35 $this->replyWithMessage(['text' => "Here are the most similar movies titles I could find...\n\n" . implode("\n", $results)]);
40 getTelegram()->addCommand(
41 new class extends Command
{
42 protected $name = 'chatid';
43 protected $description = 'Get the id for this chat.';
45 public function handle($arguments) {
46 $this->replyWithMessage([
47 'text' => $this->getUpdate()->get('message')->get('chat')->get('id')
53 getTelegram()->addCommand(
54 new class extends Command
{
55 protected $name = 'mybills';
56 protected $description = 'List my bills';
58 public function handle($arguments) {
59 $this->replyWithMessage(['text' => 'Fetching ' . getMessageSenderDisplayName($this->getUpdate()) . "'s unpaid bills. Just a sec ..."]);
60 $this->replyWithChatAction(['action' => Actions
::TYPING
]);
61 $this->replyWithMessage([
67 "%s (%s): $%s each due on the %s",
70 splitBill($bill['amount']),
71 $bill['due']->format('jS \of M')
76 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'
88 getTelegram()->addCommand(
89 new class extends Command
{
90 protected $name = 'paybill';
91 protected $description = 'Mark a bill as paid';
93 public function handle($arguments) {
95 $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..."]);
96 $this->triggerCommand('mybills');
99 $messages = array_values(array_filter(
100 getMessagesFromInbox(
102 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'
107 function($e) use ($arguments) {
108 return $e['id'] == $arguments;
112 if(!$messages ||
count($messages) !== 1) {
113 $this->replyWithMessage(['text' => "That doesn't look like a valid id. Use /mybills to list your bills."]);
116 imap_delete(getInbox('Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'), $messages[0]['uid'], FT_UID
);
117 $this->replyWithMessage(['text' => "I marked " . getMessageSenderDisplayName($this->getUpdate()) . " as having paid the " . strtolower($messages[0]['service']) . " bill, thanks!"]);
123 getTelegram()->commandsHandler(true
); //must come afterwards because lolzer