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: class KillOnSightController {
32:
33: 34: 35: 36:
37: public $moduleName;
38:
39:
40: public $db;
41:
42:
43: public $chatBot;
44:
45:
46: public $text;
47:
48:
49: public $util;
50:
51: 52: 53:
54: public function setup() {
55: $this->db->loadSQLFile($this->moduleName, 'kos');
56: }
57:
58: 59: 60: 61:
62: public function kosListCommand($message, $channel, $sender, $sendto, $args) {
63: $sql = "SELECT * FROM kos";
64:
65: $data = $this->db->query($sql);
66: $count = count($data);
67:
68: if ($count == 0) {
69: $msg = "There are no characters on the KOS list.";
70: } else {
71: $blob = '';
72: forEach ($data as $row) {
73: $comment = "";
74: if (!empty($row->comment)) {
75: $comment = " - $row->comment";
76: }
77:
78: $blob .= "<highlight>$row->name<end>$comment (added by $row->submitter <highlight>" . $this->util->unixtimeToReadable(time() - $row->dt) . "<end> ago)\n";
79: }
80: $msg = $this->text->makeBlob("Kill-On-Sight List ($count)", $blob);
81: }
82: $sendto->reply($msg);
83: }
84:
85: 86: 87: 88: 89:
90: public function kosAddCommand($message, $channel, $sender, $sendto, $args) {
91: $name = ucfirst(strtolower($args[1]));
92: $charid = $this->chatBot->get_uid($name);
93:
94: if ($charid == false) {
95: $sendto->reply("Character <highlight>$name<end> does not exist.");
96: return;
97: }
98:
99: $sql = "SELECT * FROM kos WHERE name = ?";
100: $row = $this->db->queryRow($sql, $name);
101:
102: if ($row !== null) {
103: $msg = "Character <highlight>$name<end> is already on the Kill-On-Sight list.";
104: } else {
105: $comment = "";
106: if (isset($args[2])) {
107: $comment = trim($args[2]);
108: }
109:
110: $sql = "INSERT INTO kos (name, comment, submitter, dt) VALUES (?, ?, ?, ?)";
111: $this->db->exec($sql, $name, $comment, $sender, time());
112: $msg = "Character <highlight>$name<end> has been added to the Kill-On-Sight list.";
113: }
114: $sendto->reply($msg);
115: }
116:
117: 118: 119: 120:
121: public function kosRemCommand($message, $channel, $sender, $sendto, $args) {
122: $name = ucfirst(strtolower($args[1]));
123: $sql = "SELECT * FROM kos WHERE name = ?";
124:
125: $row = $this->db->queryRow($sql, $name);
126:
127: if ($row === null) {
128: $msg = "Character <highlight>$name<end> is not on the Kill-On-Sight list.";
129: } else {
130: $sql = "DELETE FROM kos WHERE name = ?";
131: $this->db->exec($sql, $name);
132: $msg = "Character <highlight>$name<end> has been removed from the Kill-On-Sight list.";
133: }
134: $sendto->reply($msg);
135: }
136: }