1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: use Budabot\Core\AutoInject;
6: use \DateTimeZone;
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class TimezoneController extends AutoInject {
24:
25: 26: 27: 28:
29: public $moduleName;
30:
31: 32: 33:
34: public function setup() {
35:
36: }
37:
38: 39: 40: 41:
42: public function timezoneCommand($message, $channel, $sender, $sendto, $args) {
43: $timezoneAreas = $this->getTimezoneAreas();
44:
45: $blob = '';
46: forEach ($timezoneAreas as $area => $code) {
47: $blob .= $this->text->makeChatcmd($area, "/tell <myname> timezone $area") . "\n";
48: }
49: $msg = $this->text->makeBlob("Timezone Areas", $blob);
50: $sendto->reply($msg);
51: }
52:
53: 54: 55: 56:
57: public function timezoneSetCommand($message, $channel, $sender, $sendto, $args) {
58: $timezone = $args[1];
59:
60: $result = date_default_timezone_set($timezone);
61:
62: if ($result) {
63: $msg = "Timezone has been set to <highlight>$timezone<end>.";
64: } else {
65: $msg = "<highlight>$timezone<end> is not a valid timezone.";
66: }
67: $sendto->reply($msg);
68: }
69:
70: 71: 72: 73:
74: public function timezoneAreaCommand($message, $channel, $sender, $sendto, $args) {
75: $area = $args[1];
76:
77: $timezoneAreas = $this->getTimezoneAreas();
78: $code = $timezoneAreas[$area];
79: if (empty($code)) {
80: return false;
81: }
82:
83: $timezones = DateTimeZone::listIdentifiers($code);
84: $count = count($timezone);
85:
86: $blob = '';
87: forEach ($timezones as $timezone) {
88: $blob .= $this->text->makeChatcmd($timezone, "/tell <myname> timezone set $timezone") . "\n";
89: }
90: $msg = $this->text->makeBlob("Timezones for $area ($count)", $blob);
91: $sendto->reply($msg);
92: }
93:
94: public function getTimezoneAreas() {
95: return array(
96: 'Africa' => 1,
97: 'America' => 2,
98: 'Antarctica' => 4,
99: 'Arctic' => 8,
100: 'Asia' => 16,
101: 'Atlantic' => 32,
102: 'Australia' => 64,
103: 'Europe' => 128,
104: 'Indian' => 256,
105: 'Pacific' => 512,
106: 'UTC' => 1024);
107: }
108: }
109: