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: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75:
76: class PrivateChannelController {
77:
78: 79: 80: 81:
82: public $moduleName;
83:
84:
85: public $db;
86:
87:
88: public $chatBot;
89:
90:
91: public $settingManager;
92:
93:
94: public $buddylistManager;
95:
96:
97: public $text;
98:
99:
100: public $util;
101:
102:
103: public $altsController;
104:
105:
106: public $accessManager;
107:
108:
109: public $onlineController;
110:
111:
112: public $relayController;
113:
114:
115: public $timer;
116:
117:
118: public $playerManager;
119:
120: 121: 122:
123: public function setup() {
124: $this->db->loadSQLFile($this->moduleName, "private_chat");
125:
126: $this->settingManager->add($this->moduleName, "guest_color_channel", "Color for Private Channel relay(ChannelName)", "edit", "color", "<font color=#C3C3C3>");
127: $this->settingManager->add($this->moduleName, "guest_color_guild", "Private Channel relay color in guild channel", "edit", "color", "<font color=#C3C3C3>");
128: $this->settingManager->add($this->moduleName, "guest_color_guest", "Private Channel relay color in private channel", "edit", "color", "<font color=#C3C3C3>");
129: $this->settingManager->add($this->moduleName, "guest_relay", "Relay the Private Channel with the Guild Channel", "edit", "options", "1", "true;false", "1;0");
130: $this->settingManager->add($this->moduleName, "guest_relay_commands", "Relay commands and results from/to Private Channel", "edit", "options", "1", "true;false", "1;0");
131: $this->settingManager->add($this->moduleName, "add_member_on_join", "Automatically add player as member when they join", "edit", "options", "0", "true;false", "1;0");
132: }
133:
134: 135: 136: 137:
138: public function membersCommand($message, $channel, $sender, $sendto, $args) {
139: $data = $this->db->query("SELECT * FROM members_<myname> ORDER BY `name`");
140: $count = count($data);
141: if ($count != 0) {
142: $list = '';
143: forEach ($data as $row) {
144: $online = $this->buddylistManager->isOnline($row->name);
145: if (isset($this->chatBot->chatlist[$row->name])) {
146: $status = "(<green>Online and in channel<end>)";
147: } else if ($online === 1) {
148: $status = "(<green>Online<end>)";
149: } else if ($online === 0) {
150: $status = "(<red>Offline<end>)";
151: } else {
152: $status = "(<orange>Unknown<end>)";
153: }
154:
155: $list .= "$row->name {$status}\n";
156: }
157:
158: $msg = $this->text->makeBlob("Members ($count)", $list);
159: $sendto->reply($msg);
160: } else {
161: $sendto->reply("There are no members of this bot.");
162: }
163: }
164:
165: 166: 167: 168:
169: public function adduserCommand($message, $channel, $sender, $sendto, $args) {
170: $msg = $this->addUser($args[1]);
171:
172: $sendto->reply($msg);
173: }
174:
175: 176: 177: 178:
179: public function remuserCommand($message, $channel, $sender, $sendto, $args) {
180: $msg = $this->removeUser($args[1]);
181:
182: $sendto->reply($msg);
183: }
184:
185: 186: 187: 188:
189: public function inviteCommand($message, $channel, $sender, $sendto, $args) {
190: $name = ucfirst(strtolower($args[1]));
191: $uid = $this->chatBot->get_uid($name);
192: if ($this->chatBot->vars["name"] == $name) {
193: $msg = "You cannot invite the bot to its own private channel.";
194: } else if ($uid) {
195: if (isset($this->chatBot->chatlist[$name])) {
196: $msg = "<highlight>$name<end> is already in the private channel.";
197: } else {
198: $msg = "Invited <highlight>$name<end> to this channel.";
199:
200: $this->chatBot->privategroup_invite($name);
201: $msg2 = "You have been invited to the <highlight><myname><end> channel by <highlight>$sender<end>.";
202: $this->chatBot->sendTell($msg2, $name);
203: }
204: } else {
205: $msg = "Character <highlight>{$name}<end> does not exist.";
206: }
207:
208: $sendto->reply($msg);
209: }
210:
211: 212: 213: 214:
215: public function kickCommand($message, $channel, $sender, $sendto, $args) {
216: $name = ucfirst(strtolower($args[1]));
217: $uid = $this->chatBot->get_uid($name);
218: if (!$uid) {
219: $msg = "Character <highlight>{$name}<end> does not exist.";
220: } else if (!isset($this->chatBot->chatlist[$name])) {
221: $msg = "Character <highlight>{$name}<end> is not in the private channel.";
222: } else {
223: if ($this->accessManager->compareCharacterAccessLevels($sender, $name) > 0) {
224: $msg = "<highlight>$name<end> has been kicked from the private channel.";
225: $this->chatBot->privategroup_kick($name);
226: } else {
227: $msg = "You do not have the required access level to kick <highlight>$name<end>.";
228: }
229: }
230: $sendto->reply($msg);
231: }
232:
233: 234: 235: 236:
237: public function autoinviteCommand($message, $channel, $sender, $sendto, $args) {
238: if ($args[1] == 'on') {
239: $onOrOff = 1;
240: $this->buddylistManager->add($sender, 'member');
241: } else {
242: $onOrOff = 0;
243: $this->buddylistManager->remove($sender, 'member');
244: }
245:
246: $data = $this->db->query("SELECT * FROM members_<myname> WHERE `name` = ?", $sender);
247: if (count($data) == 0) {
248: $this->db->exec("INSERT INTO members_<myname> (`name`, `autoinv`) VALUES (?, ?)", $sender, $onOrOff);
249: $msg = "You have been added as a member of this bot. Use <highlight><symbol>autoinvite<end> to control your auto invite preference.";
250: } else {
251: $this->db->exec("UPDATE members_<myname> SET autoinv = ? WHERE name = ?", $onOrOff, $sender);
252: $msg = "Your auto invite preference has been updated.";
253: }
254:
255: $sendto->reply($msg);
256: }
257:
258: 259: 260: 261:
262: public function countLevelCommand($message, $channel, $sender, $sendto, $args) {
263: $tl1 = 0;
264: $tl2 = 0;
265: $tl3 = 0;
266: $tl4 = 0;
267: $tl5 = 0;
268: $tl6 = 0;
269: $tl7 = 0;
270:
271: $data = $this->db->query("SELECT * FROM online o LEFT JOIN players p ON (o.name = p.name AND p.dimension = '<dim>') WHERE added_by = '<myname>' AND channel_type = 'priv'");
272: $numonline = count($data);
273: forEach ($data as $row) {
274: if ($row->level > 1 && $row->level <= 14) {
275: $tl1++;
276: } else if ($row->level >= 15 && $row->level <= 49) {
277: $tl2++;
278: } else if ($row->level >= 50 && $row->level <= 99) {
279: $tl3++;
280: } else if ($row->level >= 100 && $row->level <= 149) {
281: $tl4++;
282: } else if ($row->level >= 150 && $row->level <= 189) {
283: $tl5++;
284: } else if ($row->level >= 190 && $row->level <= 204) {
285: $tl6++;
286: } else if ($row->level >= 205 && $row->level <= 220) {
287: $tl7++;
288: }
289: }
290: $msg = "<highlight>$numonline<end> in total: TL1 <highlight>$tl1<end>, TL2 <highlight>$tl2<end>, TL3 <highlight>$tl3<end>, TL4 <highlight>$tl4<end>, TL5 <highlight>$tl5<end>, TL6 <highlight>$tl6<end>, TL7 <highlight>$tl7<end>";
291: $sendto->reply($msg);
292: }
293:
294: 295: 296: 297:
298: public function countProfessionCommand($message, $channel, $sender, $sendto, $args) {
299: $online["Adventurer"] = 0;
300: $online["Agent"] = 0;
301: $online["Bureaucrat"] = 0;
302: $online["Doctor"] = 0;
303: $online["Enforcer"] = 0;
304: $online["Engineer"] = 0;
305: $online["Fixer"] = 0;
306: $online["Keeper"] = 0;
307: $online["Martial Artist"] = 0;
308: $online["Meta-Physicist"] = 0;
309: $online["Nano-Technician"] = 0;
310: $online["Soldier"] = 0;
311: $online["Trader"] = 0;
312: $online["Shade"] = 0;
313:
314: $data = $this->db->query("SELECT count(*) AS count, profession FROM online o LEFT JOIN players p ON (o.name = p.name AND p.dimension = '<dim>') WHERE added_by = '<myname>' AND channel_type = 'priv' GROUP BY `profession`");
315: $numonline = count($data);
316: $msg = "<highlight>$numonline<end> in total: ";
317:
318: forEach ($data as $row) {
319: $online[$row->profession] = $row->count;
320: }
321:
322: $msg .= "<highlight>".$online['Adventurer']."<end> Adv, "
323: . "<highlight>".$online['Agent']."<end> Agent, "
324: . "<highlight>".$online['Bureaucrat']."<end> Crat, "
325: . "<highlight>".$online['Doctor']."<end> Doc, "
326: . "<highlight>".$online['Enforcer']."<end> Enf, "
327: . "<highlight>".$online['Engineer']."<end> Eng, "
328: . "<highlight>".$online['Fixer']."<end> Fix, "
329: . "<highlight>".$online['Keeper']."<end> Keeper, "
330: . "<highlight>".$online['Martial Artist']."<end> MA, "
331: . "<highlight>".$online['Meta-Physicist']."<end> MP, "
332: . "<highlight>".$online['Nano-Technician']."<end> NT, "
333: . "<highlight>".$online['Soldier']."<end> Sol, "
334: . "<highlight>".$online['Shade']."<end> Shade, "
335: . "<highlight>".$online['Trader']."<end> Trader";
336:
337: $sendto->reply($msg);
338: }
339:
340: 341: 342: 343:
344: public function countOrganizationCommand($message, $channel, $sender, $sendto, $args) {
345: $sql = "SELECT * FROM online WHERE added_by = '<myname>' AND channel_type = 'priv'";
346: $data = $this->db->query($sql);
347: $numonline = count($data);
348:
349: if ($numonline == 0) {
350: $msg = "No characters in channel.";
351: } else {
352: $sql = "SELECT `guild`, count(*) AS cnt, AVG(level) AS avg_level FROM online o LEFT JOIN players p ON (o.name = p.name AND p.dimension = '<dim>') WHERE added_by = '<myname>' AND channel_type = 'priv' GROUP BY `guild` ORDER BY `cnt` DESC, `avg_level` DESC";
353: $data = $this->db->query($sql);
354: $numorgs = count($data);
355:
356: $blob = '';
357: forEach ($data as $row) {
358: $guild = '(none)';
359: if ($row->guild != '') {
360: $guild = $row->guild;
361: }
362: $percent = round($row->cnt / $numonline, 2) * 100;
363: $avg_level = round($row->avg_level, 1);
364: $blob .= "{$percent}% {$guild} - {$row->cnt} member(s), average level {$avg_level}\n";
365: }
366:
367: $msg = $this->text->makeBlob("Organizations ($numorgs)", $blob);
368: }
369: $sendto->reply($msg);
370: }
371:
372: 373: 374: 375:
376: public function countCommand($message, $channel, $sender, $sendto, $args) {
377: $prof = $this->util->getProfessionName($args[1]);
378: if ($prof == '') {
379: $msg = "Please choose one of these professions: adv, agent, crat, doc, enf, eng, fix, keep, ma, mp, nt, sol, shade, trader or all";
380: } else {
381: $data = $this->db->query("SELECT * FROM online o LEFT JOIN players p ON (o.name = p.name AND p.dimension = '<dim>') WHERE added_by = '<myname>' AND channel_type = 'priv' AND `profession` = ? ORDER BY `level`", $prof);
382: $numonline = count($data);
383: $msg = "<highlight>$numonline<end> $prof:";
384:
385: forEach ($data as $row) {
386: if ($row->afk != "") {
387: $afk = "<red>*AFK*<end>";
388: } else {
389: $afk = "";
390: }
391: $msg .= " [<highlight>$row->name<end> - ".$row->level.$afk."]";
392: }
393: }
394: $sendto->reply($msg);
395: }
396:
397: 398: 399: 400:
401: public function kickallCommand($message, $channel, $sender, $sendto, $args) {
402: $msg = "Everyone will be kicked from this channel in 10 seconds. [by <highlight>$sender<end>]";
403: $this->chatBot->sendPrivate($msg);
404: $this->timer->callLater(10, array($this->chatBot, 'privategroup_kick_all'));
405: }
406:
407: 408: 409: 410:
411: public function joinCommand($message, $channel, $sender, $sendto, $args) {
412: if (isset($this->chatBot->chatlist[$sender])) {
413: $msg = "You are already in the private channel.";
414: } else {
415: if ($this->settingManager->get('add_member_on_join') == 1) {
416: $row = $this->db->queryRow("SELECT * FROM members_<myname> WHERE `name` = ?", $sender);
417: if ($row === null) {
418: $this->db->exec("INSERT INTO members_<myname> (`name`, `autoinv`) VALUES (?, ?)", $sender, '1');
419: $msg = "You have been added as a member of this bot. Use <highlight><symbol>autoinvite<end> to control your auto invite preference.";
420: }
421: }
422: $this->chatBot->privategroup_invite($sender);
423: }
424:
425: if (isset($msg)) {
426: $sendto->reply($msg);
427: }
428: }
429:
430: 431: 432: 433:
434: public function leaveCommand($message, $channel, $sender, $sendto, $args) {
435: $this->chatBot->privategroup_kick($sender);
436: }
437:
438: 439: 440: 441:
442: public function connectEvent($eventObj) {
443: $sql = "SELECT name FROM members_<myname> WHERE autoinv = 1";
444: $data = $this->db->query($sql);
445: forEach ($data as $row) {
446: $this->buddylistManager->add($row->name, 'member');
447: }
448: }
449:
450: 451: 452: 453:
454: public function relayPrivateChannelEvent($eventObj) {
455: $sender = $eventObj->sender;
456: $message = $eventObj->message;
457:
458:
459: if ($this->settingManager->get("guest_relay") != 1) {
460: return;
461: }
462:
463:
464: if ($message[0] == $this->settingManager->get("symbol") && $this->settingManager->get("guest_relay_commands") != 1) {
465: return;
466: }
467:
468: $guest_color_channel = $this->settingManager->get("guest_color_channel");
469: $guest_color_guest = $this->settingManager->get("guest_color_guest");
470: $guest_color_guild = $this->settingManager->get("guest_color_guild");
471:
472: if (count($this->chatBot->chatlist) > 0) {
473:
474: $guildNameForRelay = $this->relayController->getGuildAbbreviation();
475: if (!$this->util->isValidSender($sender)) {
476:
477: $msg = "<end>{$guest_color_channel}[$guildNameForRelay]<end> {$guest_color_guest}{$message}<end>";
478: } else {
479: $msg = "<end>{$guest_color_channel}[$guildNameForRelay]<end> ".$this->text->makeUserlink($sender).": {$guest_color_guest}{$message}<end>";
480: }
481: $this->chatBot->sendPrivate($msg, true);
482: }
483: }
484:
485: 486: 487: 488:
489: public function relayGuildChannelEvent($eventObj) {
490: $sender = $eventObj->sender;
491: $message = $eventObj->message;
492:
493:
494: if ($this->settingManager->get("guest_relay") != 1) {
495: return;
496: }
497:
498:
499: if ($message[0] == $this->settingManager->get("symbol") && $this->settingManager->get("guest_relay_commands") != 1) {
500: return;
501: }
502:
503: $guest_color_channel = $this->settingManager->get("guest_color_channel");
504: $guest_color_guest = $this->settingManager->get("guest_color_guest");
505: $guest_color_guild = $this->settingManager->get("guest_color_guild");
506:
507:
508: $msg = "<end>{$guest_color_channel}[Guest]<end> ".$this->text->makeUserlink($sender).": {$guest_color_guild}{$message}<end>";
509: $this->chatBot->sendGuild($msg, true);
510: }
511:
512: 513: 514: 515:
516: public function logonAutoinviteEvent($eventObj) {
517: $sender = $eventObj->sender;
518: $data = $this->db->query("SELECT * FROM members_<myname> WHERE name = ? AND autoinv = ?", $sender, '1');
519: if (count($data) != 0) {
520: $msg = "You have been auto invited to the <highlight><myname><end> channel. Use <highlight><symbol>autoinvite<end> to control your auto invite preference.";
521: $this->chatBot->privategroup_invite($sender);
522: $this->chatBot->sendTell($msg, $sender);
523: }
524: }
525:
526: 527: 528: 529:
530: public function joinPrivateChannelMessageEvent($eventObj) {
531: $sender = $eventObj->sender;
532: $whois = $this->playerManager->getByName($sender);
533:
534: $altInfo = $this->altsController->getAltInfo($sender);
535:
536: if ($whois !== null) {
537: if (count($altInfo->alts) > 0) {
538: $msg = $this->playerManager->getInfo($whois) . " has joined the private channel. " . $altInfo->getAltsBlob(false, true);
539: } else {
540: $msg = $this->playerManager->getInfo($whois) . " has joined the private channel.";
541: }
542: } else {
543: if (count($altInfo->alts) > 0) {
544: $msg .= "$sender has joined the private channel. " . $altInfo->getAltsBlob(false, true);
545: } else {
546: $msg = "$sender has joined the private channel.";
547: }
548: }
549:
550: if ($this->settingManager->get("guest_relay") == 1) {
551: $this->chatBot->sendGuild($msg, true);
552: }
553: $this->chatBot->sendPrivate($msg, true);
554: }
555:
556: 557: 558: 559:
560: public function leavePrivateChannelMessageEvent($eventObj) {
561: $sender = $eventObj->sender;
562: $msg = "$sender has left the private channel.";
563:
564: if ($this->settingManager->get("guest_relay") == 1) {
565: $this->chatBot->sendGuild($msg, true);
566: }
567: }
568:
569: 570: 571: 572:
573: public function joinPrivateChannelRecordEvent($eventObj) {
574: $sender = $eventObj->sender;
575: $this->onlineController->addPlayerToOnlineList($sender, $this->chatBot->vars['guild'] . ' Guests', 'priv');
576: }
577:
578: 579: 580: 581:
582: public function leavePrivateChannelRecordEvent($eventObj) {
583: $sender = $eventObj->sender;
584: $this->onlineController->removePlayerFromOnlineList($sender, 'priv');
585: }
586:
587: 588: 589: 590:
591: public function joinPrivateChannelShowOnlineEvent($eventObj) {
592: $sender = $eventObj->sender;
593: $msg = "";
594: $msg = $this->onlineController->getOnlineList();
595: $this->chatBot->sendTell($msg, $sender);
596: }
597:
598: public function addUser($name, $autoInvite = 1) {
599: $name = ucfirst(strtolower($name));
600: $uid = $this->chatBot->get_uid($name);
601: if ($this->chatBot->vars["name"] == $name) {
602: $msg = "You cannot add the bot as a member of itself.";
603: } else if (!$uid) {
604: $msg = "Character <highlight>$name<end> does not exist.";
605: } else {
606: $data = $this->db->query("SELECT * FROM members_<myname> WHERE `name` = ?", $name);
607: if (count($data) != 0) {
608: $msg = "<highlight>$name<end> is already a member of this bot.";
609: } else {
610: $this->db->exec("INSERT INTO members_<myname> (`name`, `autoinv`) VALUES (?, ?)", $name, $autoInvite);
611: $msg = "<highlight>$name<end> has been added as a member of this bot.";
612: }
613:
614:
615: $this->buddylistManager->add($name, 'member');
616: }
617: return $msg;
618: }
619:
620: public function removeUser($name) {
621: $name = ucfirst(strtolower($name));
622:
623: $data = $this->db->query("SELECT * FROM members_<myname> WHERE `name` = ?", $name);
624: if (count($data) == 0) {
625: $msg = "<highlight>$name<end> is not a member of this bot.";
626: } else {
627: $this->db->exec("DELETE FROM members_<myname> WHERE `name` = ?", $name);
628: $msg = "<highlight>$name<end> has been removed as a member of this bot.";
629: $this->buddylistManager->remove($name, 'member');
630: }
631:
632: return $msg;
633: }
634: }
635:
636: