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 = 'chatid';
20 protected $description = 'Get the id for this chat.';
22 public function handle($arguments) {
23 $this->replyWithMessage([
24 'text' => $this->getUpdate()->get('message')->get('chat')->get('id')
30 getTelegram()->addCommand(
31 new class extends Command
{
32 protected $name = 'mybills';
33 protected $description = 'List my bills';
35 public function handle($arguments) {
36 if (!canChatWith($this->getUpdate())) {
37 $this->replyWithMessage(['text' => "Sorry, Dad says I can't talk to you."]);
41 $this->replyWithMessage(['text' => 'Fetching ' . getMessageSenderDisplayName($this->getUpdate()) . "'s unpaid bills. Just a sec ..."]);
42 $this->replyWithChatAction(['action' => Actions
::TYPING
]);
43 $this->replyWithMessage([
49 "%s (%s): $%s each due on the %s",
52 splitBill($bill['amount']),
53 $bill['due']->format('jS')
58 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'
70 getTelegram()->addCommand(
71 new class extends Command
{
72 protected $name = 'paybill';
73 protected $description = 'Mark a bill as paid';
75 public function handle($arguments) {
76 if (!canChatWith($this->getUpdate())) {
77 $this->replyWithMessage(['text' => "Sorry, Dad says I can't talk to you."]);
82 $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..."]);
83 $this->triggerCommand('mybills');
86 $messages = array_values(array_filter(
89 'Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'
94 function($e) use ($arguments) {
95 return $e['id'] == $arguments;
99 if(!$messages ||
count($messages) !== 1) {
100 $this->replyWithMessage(['text' => "That doesn't look like a valid id. Use /mybills to list your bills."]);
103 imap_delete(getInbox('Utilities/' . getMessageSender($this->getUpdate()) . ' To Pay'), $messages[0]['uid'], FT_UID
);
104 $this->replyWithMessage(['text' => "I marked " . getMessageSenderDisplayName($this->getUpdate()) . " as having paid the " . strtolower($messages[0]['service']) . " bill, thanks!"]);
110 getTelegram()->commandsHandler(true
); //must come afterwards because lolzer