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 SpiritsController {
23:
24: 25: 26: 27:
28: public $moduleName;
29:
30:
31: public $db;
32:
33:
34: public $text;
35:
36: 37: 38:
39: public function setup() {
40: $this->db->loadSQLFile($this->moduleName, 'spirits');
41: }
42:
43: 44: 45: 46:
47: public function spiritsCommand($message, $channel, $sender, $sendto, $args) {
48: if (preg_match("/^spirits ([^0-9,]+)$/i", $message, $arr)) {
49: $name = $arr[1];
50: $name = ucwords(strtolower($name));
51: $title = "Spirits Database for $name";
52: $data = $this->db->query("SELECT * FROM spiritsdb WHERE name LIKE ? OR spot LIKE ? ORDER BY level", '%'.$name.'%', '%'.$name.'%');
53: if (count($data) == 0) {
54: $spirits .= "There were no matches found for $name.\nTry putting a comma between search values.\n\n";
55: $spirits .= $this->getValidSlotTypes();
56: } else {
57: $spirits .= $this->formatSpiritOutput($data);
58: }
59: }
60:
61: else if (preg_match("/^spirits ([^0-9]+),([^0-9]+)$/i", $message, $arr)) {
62: if (preg_match("/(chest|ear|eye|feet|head|larm|legs|lhand|lwrist|rarm|rhand|rwrist|waist)/i", $arr[1])) {
63: $slot = $arr[1];
64: $name = $arr[2];
65: $title = "Spirits Database for $name $slot";
66: } else if (preg_match("/(chest|ear|eye|feet|head|larm|legs|lhand|lwrist|rarm|rhand|rwrist|waist)/i", $arr[2])) {
67: $name = $arr[1];
68: $slot = $arr[2];
69: $title = "Spirits Database for $name $slot";
70: } else {
71: $spirits .= "No matches were found for $name $slot\n\n";
72: $spirits .= $this->getValidSlotTypes();
73: }
74: $name = ucwords(strtolower($name));
75: $name = trim($name);
76: $slot = ucwords(strtolower($slot));
77: $slot = trim($slot);
78: $data = $this->db->query("SELECT * FROM spiritsdb WHERE name LIKE ? AND spot = ? ORDER BY level", '%'.$name.'%', $slot);
79: $spirits .= $this->formatSpiritOutput($data);
80: }
81:
82: else if (preg_match("/^spirits ([0-9]+)$/i", $message, $arr)) {
83: $ql = $arr[1];
84: if ($ql <= 1 OR $ql >= 300) {
85: $msg = "Invalid Ql specified.";
86: $sendto->reply($msg);
87: return;
88: }
89: $title = "Spirits QL $ql";
90: $data = $this->db->query("SELECT * FROM spiritsdb where ql = ? ORDER BY ql", $ql);
91: $spirits .= $this->formatSpiritOutput($data);
92: }
93:
94: else if (preg_match("/^spirits ([0-9]+)-([0-9]+)$/i", $message, $arr)) {
95: $qllorange = $arr[1];
96: $qlhirange = $arr[2];
97: if ($qllorange < 1 OR $qlhirange > 219 OR $qllorange >= $qlhirange) {
98: $msg = "Invalid Ql range specified.";
99: $sendto->reply($msg);
100: return;
101: }
102: $title = "Spirits QL $qllorange to $qlhirange";
103: $data = $this->db->query("SELECT * FROM spiritsdb where ql >= ? AND ql <= ? ORDER BY ql", $qllorange, $qlhirange);
104: $spirits .= $this->formatSpiritOutput($data);
105: }
106:
107: else if (preg_match("/^spirits ([0-9]+) (.+)$/i", $message, $arr)) {
108: $ql = $arr[1];
109: $slot = ucwords(strtolower($arr[2]));
110: $title = "$slot Spirits QL $ql";
111: if ($ql < 1 OR $ql > 300) {
112: $msg = "Invalid Ql specified.";
113: $sendto->reply($msg);
114: return;
115: } else if (preg_match("/[^chest|ear|eye|feet|head|larm|legs|lhand|lwrist|rarm|rhand|rwrist|waist]/i", $slot)) {
116: $spirits .= "Invalid Input\n\n";
117: $spirits .= $this->getValidSlotTypes();
118: } else {
119: $data = $this->db->query("SELECT * FROM spiritsdb where spot = ? AND ql = ? ORDER BY ql", $slot, $ql);
120: $spirits .= $this->formatSpiritOutput($data);
121: }
122: }
123:
124: else if (preg_match("/^spirits ([0-9]+)-([0-9]+) (.+)$/i", $message, $arr)) {
125: $qllorange = $arr[1];
126: $qlhirange = $arr[2];
127: $slot = ucwords(strtolower($arr[3]));
128: $title = "$slot Spirits QL $qllorange to $qlhirange";
129: if ($qllorange < 1 OR $qlhirange > 300 OR $qllorange >= $qlhirange) {
130: $msg = "Invalid Ql range specified.";
131: $sendto->reply($msg);
132: return;
133: } else if (preg_match("/[^chest|ear|eye|feet|head|larm|legs|lhand|lwrist|rarm|rhand|rwrist|waist]/i", $slot)) {
134: $spirits .= "Invalid Input\n\n";
135: $spirits .= $this->getValidSlotTypes();
136: } else {
137: $data = $this->db->query("SELECT * FROM spiritsdb where spot = ? AND ql >= ? AND ql <= ? ORDER BY ql", $slot, $qllorange, $qlhirange);
138: $spirits .= $this->formatSpiritOutput($data);
139: }
140: }
141: if ($spirits) {
142: $spirits = $this->text->makeBlob("Spirits", $spirits, $title);
143: $sendto->reply($spirits);
144: } else {
145: return false;
146: }
147: }
148:
149: public function formatSpiritOutput($data) {
150: if (count($data) == 0) {
151: return "No matches found.";
152: }
153:
154: $msg = '';
155: forEach ($data as $row) {
156: $slot = $row->spot;
157: $lvl = $row->level;
158: $lowid = $row->id;
159: $agi = $row->agility;
160:
161: $data2 = $this->db->query("SELECT * FROM aodb WHERE lowid = ?", $lowid);
162: forEach ($data2 as $row); {
163: $highid = $row->highid;
164: $icon = $row->icon;
165: $name = $row->name;
166: $ql = $row->highql;
167: }
168: $msg .= $this->text->makeImage($icon) . ' ';
169: $msg .= $this->text->makeItem($lowid, $highid, $ql, $name) . "\n";
170: $msg .= "Minimum Level=$lvl Slot=$slot Agility/Sense Needed=$agi\n\n";
171: }
172: return $msg;
173: }
174:
175: public function getValidSlotTypes() {
176: $output = "Valid slot types are:\n";
177: $output .= "Head\n";
178: $output .= "Eye\n";
179: $output .= "Ear\n";
180: $output .= "Chest\n";
181: $output .= "Larm\n";
182: $output .= "Rarm\n";
183: $output .= "Waist\n";
184: $output .= "Lwrist\n";
185: $output .= "Rwrist\n";
186: $output .= "Legs\n";
187: $output .= "Lhand\n";
188: $output .= "Rhand\n";
189: $output .= "Feet\n";
190:
191: return $output;
192: }
193: }
194: