1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19: class StopwatchController {
20:
21: 22: 23: 24:
25: public $moduleName;
26:
27:
28: public $chatBot;
29:
30:
31: public $util;
32:
33: private $time = 0;
34:
35: 36: 37: 38:
39: public function stopwatchStartCommand($message, $channel, $sender, $sendto, $args) {
40: if ($this->time != 0) {
41: $msg = "The stopwatch is already running.";
42: } else {
43: $this->time = time();
44: $msg = "Stopwatch has been started.";
45: }
46: $sendto->reply($msg);
47: }
48:
49: 50: 51: 52:
53: public function stopwatchStopCommand($message, $channel, $sender, $sendto, $args) {
54: if ($this->time == 0) {
55: $msg = "The stopwatch is not running.";
56: } else {
57: $time = time() - $this->time;
58: $this->time = 0;
59:
60: $timeString = $this->util->unixtimeToReadable($time);
61:
62: $msg = "Stopwatch has been stopped. Duration: <highlight>$timeString<end>.";
63: }
64: $sendto->reply($msg);
65: }
66:
67: 68: 69: 70:
71: public function stopwatchViewCommand($message, $channel, $sender, $sendto, $args) {
72: if ($this->time == 0) {
73: $msg = "The stopwatch is not running.";
74: } else {
75: $time = time() - $this->time;
76:
77: $timeString = $this->util->unixtimeToReadable($time);
78:
79: $msg = "Elapsed time: <highlight>$timeString<end>.";
80: }
81: $sendto->reply($msg);
82: }
83: }
84: