1 <?php
declare(strict_types
=1);
11 getMessageSenderDisplayName
,
14 use Telegram\Bot\Actions
;
15 use Telegram\Bot\Commands\Command
;
18 getTelegram()->addCommand(
19 new class extends Command
{
20 protected $name = 'searchmovies';
21 protected $description = 'Search through the movie collection';
23 public function handle($arguments) {
25 function($moviename) use ($arguments) {
26 similar_text($arguments, substr($moviename, 0, -7) ?
: '', $perc);
27 return ['title' => $moviename, 'similarity' => $perc];
29 scandir('/mnt/media/Movies')
32 uasort($results, function($a, $b) {
33 return $b['similarity'] <=> $a['similarity'];
36 $results = array_column(array_slice(array_values($results), 0, 5), 'title');
37 $this->replyWithMessage(['text' => "Here are the most similar movies titles I could find...\n\n" . implode("\n", $results)]);
42 getTelegram()->addCommand(
43 new class extends Command
{
44 protected $name = 'chatid';
45 protected $description = 'Get the id for this chat.';
47 public function handle($arguments) {
48 $this->replyWithMessage([
49 'text' => $this->getUpdate()->get('message')->get('chat')->get('id')
55 getTelegram()->addCommand(
56 new class extends Command
{
57 protected $name = 'mybills';
58 protected $description = 'List my bills';
60 public function handle($arguments) {
61 if (!canChatWith($this->getUpdate())) {
62 $this->replyWithMessage(['text' => "Sorry, Dad says I can't talk to you."]);
66 $this->replyWithMessage(['text' => 'Fetching ' . getMessageSenderDisplayName($this->getUpdate()) . "'s unpaid bills. Just a sec ..."]);
67 $this->replyWithChatAction(['action' => Actions
::TYPING
]);
68 $this->replyWithMessage([
74 "%s (%s): $%s each due on the %s",
77 splitBill($bill['amount']),
78 $bill['due']->format('jS \of M')
83 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'
95 getTelegram()->addCommand(
96 new class extends Command
{
97 protected $name = 'paybill';
98 protected $description = 'Mark a bill as paid';
100 public function handle($arguments) {
101 if (!canChatWith($this->getUpdate())) {
102 $this->replyWithMessage(['text' => "Sorry, Dad says I can't talk to you."]);
107 $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..."]);
108 $this->triggerCommand('mybills');
111 $messages = array_values(array_filter(
112 getMessagesFromInbox(
114 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'
119 function($e) use ($arguments) {
120 return $e['id'] == $arguments;
124 if(!$messages ||
count($messages) !== 1) {
125 $this->replyWithMessage(['text' => "That doesn't look like a valid id. Use /mybills to list your bills."]);
128 imap_delete(getInbox('Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'), $messages[0]['uid'], FT_UID
);
129 $this->replyWithMessage(['text' => "I marked " . getMessageSenderDisplayName($this->getUpdate()) . " as having paid the " . strtolower($messages[0]['service']) . " bill, thanks!"]);
135 getTelegram()->commandsHandler(true
); //must come afterwards because lolzer