1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: class ChatRallyController {
23:
24: public $settingManager;
25:
26:
27: public $text;
28:
29:
30: public $playfieldController;
31:
32:
33: public $chatBot;
34:
35:
36: public $chatLeaderController;
37:
38: 39: 40: 41: 42: 43:
44: public $defaultRally = "";
45:
46: 47: 48: 49: 50:
51: public function rallyCommand($message, $channel, $sender, $sendto, $args) {
52: $this->replyCurrentRally($channel, $sendto);
53: }
54:
55: 56: 57: 58: 59:
60: public function rallyClearCommand($message, $channel, $sender, $sendto, $args) {
61: if (!$this->chatLeaderController->checkLeaderAccess($sender)) {
62: $sendto->reply("You must be Raid Leader to use this command.");
63: return;
64: }
65:
66: $this->clear();
67: $msg = "Rally has been cleared.";
68: $sendto->reply($msg);
69: }
70:
71: 72: 73: 74: 75: 76: 77: 78: 79: 80:
81: public function rallySet2Command($message, $channel, $sender, $sendto, $args) {
82: if (!$this->chatLeaderController->checkLeaderAccess($sender)) {
83: $sendto->reply("You must be Raid Leader to use this command.");
84: return;
85: }
86:
87: $xCoords = $args[1];
88: $yCoords = $args[3];
89:
90: if (is_numeric($args[5])) {
91: $playfieldId = $args[5];
92: $playfieldName = $playfieldId;
93:
94: $playfield = $this->playfieldController->getPlayfieldById($playfieldId);
95: if ($playfield !== null) {
96: $playfieldName = $playfield->short_name;
97: }
98: } else {
99: $playfieldName = $args[5];
100: $playfield = $this->playfieldController->getPlayfieldByName($playfieldName);
101: if ($playfield === null) {
102: $sendto->reply("Could not find playfield '$playfieldName'");
103: return;
104: }
105: $playfieldId = $playfield->id;
106: }
107: $this->set($playfieldName, $playfieldId, $xCoords, $yCoords);
108:
109: $this->replyCurrentRally($channel, $sendto);
110: }
111:
112: 113: 114: 115: 116: 117: 118:
119: public function rallySet1Command($message, $channel, $sender, $sendto, $args) {
120: if (!$this->chatLeaderController->checkLeaderAccess($sender)) {
121: $sendto->reply("You must be Raid Leader to use this command.");
122: return;
123: }
124:
125: if (preg_match("/(\d+\.\d) (\d+\.\d) y \d+\.\d (\d+)/", $args[1], $matches)) {
126: $xCoords = $matches[1];
127: $yCoords = $matches[2];
128: $playfieldId = $matches[3];
129: } else {
130: return false;
131: }
132:
133: $name = $playfieldId;
134: $playfield = $this->playfieldController->getPlayfieldById($playfieldId);
135: if ($playfield !== null) {
136: $name = $playfield->short_name;
137: }
138: $this->set($name, $playfieldId, $xCoords, $yCoords);
139:
140: $this->replyCurrentRally($channel, $sendto);
141: }
142:
143: 144: 145: 146:
147: public function sendRally($eventObj) {
148: $sender = $eventObj->sender;
149:
150: $rally = $this->get();
151: if ('' != $rally) {
152: $this->chatBot->sendTell($rally, $sender);
153: }
154: }
155:
156: public function set($name, $playfieldId, $xCoords, $yCoords) {
157: $link = $this->text->makeChatcmd("Rally: {$xCoords}x{$yCoords} {$name}", "/waypoint {$xCoords} {$yCoords} {$playfieldId}");
158: $blob = "Click here to use rally: $link";
159: $rally = $this->text->makeBlob("Rally: {$xCoords}x{$yCoords} {$name}", $blob);
160:
161: $this->settingManager->save("rally", $rally);
162:
163: return $rally;
164: }
165:
166: public function get() {
167: return $this->settingManager->get("rally");
168: }
169:
170: public function clear() {
171: $this->settingManager->save("rally", '');
172: }
173:
174: public function replyCurrentRally($channel, $sendto) {
175: $rally = $this->get();
176: if ('' == $rally) {
177: $msg = "No rally set.";
178: $sendto->reply($msg);
179: return;
180: }
181: $sendto->reply($rally);
182: }
183: }
184: