1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Transmissor\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Transmissor\Services\TransmissorService; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
|
8
|
|
|
class SendRemindersCommand extends Command |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
protected $signature = 'reminders:send'; |
12
|
|
|
|
13
|
|
|
protected $description = 'Send the reminders for the current day and time'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var \Transmissor\Services\TransmissorService |
17
|
|
|
*/ |
18
|
|
|
protected $transmissorService; |
19
|
|
|
|
20
|
|
|
// /** @var \BotMan\BotMan\BotMan */ |
21
|
|
|
// protected $botman; |
22
|
|
|
|
23
|
|
|
public function __construct(TransmissorService $transmissorService) |
24
|
|
|
{ |
25
|
|
|
parent::__construct(); |
26
|
|
|
$this->transmissorService = $transmissorService; |
27
|
|
|
// $this->botman = resolve('botman'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function handle() |
31
|
|
|
{ |
32
|
|
|
// $reminders = $this->getReminders(); |
33
|
|
|
|
34
|
|
|
// if (! $reminders->count()) { |
35
|
|
|
// return; |
36
|
|
|
// } |
37
|
|
|
|
38
|
|
|
// $reminders->each(function (Reminder $reminder) { |
39
|
|
|
|
40
|
|
|
// $user = $reminder->user; |
41
|
|
|
// $station = $this->transmissorService->find($reminder->station_id); |
42
|
|
|
|
43
|
|
|
// if (! $station || ! $reminder->user) { |
44
|
|
|
// return; // corrupted reminder, we need to do something about it |
45
|
|
|
// } |
46
|
|
|
|
47
|
|
|
// $this->sayTo($this->getGreetings($user->name), $user->telegram_id); |
48
|
|
|
// $this->sayTo($station->getVenueMessage(), $user->telegram_id, $station->getVenuePayload()); |
49
|
|
|
|
50
|
|
|
// if ($station->bikes == 0) { |
51
|
|
|
// $this->sayTo("Ja pots anar a la següent estació, aquí no hi ha cap bici 🏃", $reminder->user->telegram_id); |
52
|
|
|
// } |
53
|
|
|
|
54
|
|
|
// if ($station->bikes == 1) { |
55
|
|
|
// $this->sayTo("Ep! Només en queda una! És possible que estigui defectuosa... 🤔", $reminder->user->telegram_id); |
56
|
|
|
// } |
57
|
|
|
|
58
|
|
|
// }); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function getGreetings($name) |
62
|
|
|
{ |
63
|
|
|
return "🕐 {$this->getSalute()} {$name}, aquí tens la informació del teu recordatori 👇"; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function getSalute() |
67
|
|
|
{ |
68
|
|
|
$hour = date('H'); |
69
|
|
|
|
70
|
|
|
if ($hour <= 5) { |
71
|
|
|
return 'Bona nit'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if ($hour <= 12) { |
75
|
|
|
return 'Bon dia'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if ($hour <= 20) { |
79
|
|
|
return 'Bona tarda'; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return 'Bona nit'; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function sayTo($message, $userId, $params = []) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
// $this->botman->say($message, $userId, TelegramDriver::class, $params); |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
private function getReminders() |
92
|
|
|
{ |
93
|
|
|
// return Reminder::where('active', true) |
94
|
|
|
// ->where(date('l'), true) |
95
|
|
|
// ->where('time', date('H:i')) |
96
|
|
|
// ->where('date_begin', '<=', date('Y-m-d H:i:s')) |
97
|
|
|
// ->where(function ($dateEnd) { |
98
|
|
|
// return $dateEnd->whereNull('date_end') |
99
|
|
|
// ->orWhere('date_end', '>=', date('Y-m-d H:i:s')); |
100
|
|
|
// }); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.