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 ChatTopicController {
23:
24: 25: 26: 27:
28: public $moduleName;
29:
30:
31: public $chatBot;
32:
33:
34: public $settingManager;
35:
36:
37: public $util;
38:
39:
40: public $chatRallyController;
41:
42:
43: public $chatLeaderController;
44:
45: 46: 47: 48: 49: 50:
51: public $defaultTopic = '';
52:
53: 54: 55: 56: 57: 58:
59: public $defaultTopicSetBy = '';
60:
61: 62: 63: 64: 65: 66:
67: public $defaultTopicTime = '';
68:
69: 70: 71: 72: 73:
74: public function topicCommand($message, $channel, $sender, $sendto, $args) {
75: if ($this->settingManager->get('topic') == '') {
76: $msg = 'No topic set.';
77: } else {
78: $msg = $this->buildTopicMessage();
79: }
80:
81: $sendto->reply($msg);
82: }
83:
84: 85: 86: 87: 88:
89: public function topicClearCommand($message, $channel, $sender, $sendto, $args) {
90: if (!$this->chatLeaderController->checkLeaderAccess($sender)) {
91: $sendto->reply("You must be Raid Leader to use this command.");
92: return;
93: }
94:
95: $this->setTopic($sender, "");
96: $msg = "Topic has been cleared.";
97: $sendto->reply($msg);
98: }
99:
100: 101: 102: 103: 104:
105: public function topicSetCommand($message, $channel, $sender, $sendto, $args) {
106: if (!$this->chatLeaderController->checkLeaderAccess($sender)) {
107: $sendto->reply("You must be Raid Leader to use this command.");
108: return;
109: }
110:
111: $this->setTopic($sender, $args[1]);
112: $msg = "Topic has been updated.";
113: $sendto->reply($msg);
114: }
115:
116: 117: 118: 119:
120: public function logonEvent($eventObj) {
121: if ($this->settingManager->get('topic') == '') {
122: return;
123: }
124: if (isset($this->chatBot->guildmembers[$eventObj->sender]) && $this->chatBot->isReady()) {
125: $msg = $this->buildTopicMessage();
126: $this->chatBot->sendTell($msg, $eventObj->sender);
127: }
128: }
129:
130: 131: 132: 133:
134: public function joinPrivEvent($eventObj) {
135: if ($this->settingManager->get('topic') == '') {
136: return;
137: }
138: $msg = $this->buildTopicMessage();
139: $this->chatBot->sendTell($msg, $eventObj->sender);
140: }
141:
142: public function setTopic($name, $msg) {
143: $this->settingManager->save("topic_time", time());
144: $this->settingManager->save("topic_setby", $name);
145: $this->settingManager->save("topic", $msg);
146:
147: if (empty($msg)) {
148: $this->chatRallyController->clear();
149: }
150: }
151:
152: 153: 154:
155: public function buildTopicMessage() {
156: $date_string = $this->util->unixtimeToReadable(time() - $this->settingManager->get('topic_time'), false);
157: $topic = $this->settingManager->get('topic');
158: $set_by = $this->settingManager->get('topic_setby');
159: $msg = "Topic: <highlight>{$topic}<end> [set by <highlight>{$set_by}<end>][<highlight>{$date_string} ago<end>]";
160: return $msg;
161: }
162: }
163: