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: class NanoController {
35:
36: 37: 38: 39:
40: public $moduleName;
41:
42:
43: public $db;
44:
45:
46: public $settingManager;
47:
48:
49: public $text;
50:
51:
52: public $util;
53:
54: 55: 56: 57:
58: public function setup() {
59: $this->db->loadSQLFile($this->moduleName, 'nanos');
60: $this->db->loadSQLFile($this->moduleName, 'nanolines');
61: $this->db->loadSQLFile($this->moduleName, 'nanos_nanolines_ref');
62:
63: $this->settingManager->add($this->moduleName, 'maxnano', 'Number of Nanos shown on the list', 'edit', "number", '40', '30;40;50;60', "", "mod");
64: $this->settingManager->add($this->moduleName, "shownanolineicons", "Show icons for the nanolines", "edit", "options", "0", "true;false", "1;0");
65: }
66:
67: 68: 69: 70:
71: public function nanoCommand($message, $channel, $sender, $sendto, $args) {
72: $search = $args[1];
73:
74: $search = htmlspecialchars_decode($search);
75: $tmp = explode(" ", $search);
76: list($query, $params) = $this->util->generateQueryFromParams($tmp, 'n1.`name`');
77: array_push($params, intval($this->settingManager->get("maxnano")));
78:
79: $sql =
80: "SELECT
81: n1.lowid,
82: n1.lowql,
83: n1.name,
84: n1.location,
85: n1.profession,
86: n3.id AS nanoline_id,
87: n3.name AS nanoline_name
88: FROM
89: nanos n1
90: LEFT JOIN nanos_nanolines_ref n2 ON n1.lowid = n2.lowid
91: LEFT JOIN nanolines n3 ON n2.nanolines_id = n3.id
92: WHERE
93: $query
94: ORDER BY
95: n1.profession, n3.name, n1.lowql DESC, n1.name ASC
96: LIMIT
97: ?";
98:
99: $data = $this->db->query($sql, $params);
100:
101: $count = count($data);
102: if ($count == 0) {
103: $msg = "No nanos found.";
104: } else {
105: $blob = '';
106: $currentNanoline = -1;
107: forEach ($data as $row) {
108: if ($currentNanoline != $row->nanoline_id) {
109: if (!empty($row->nanoline_name)) {
110: $nanolineLink = $this->text->makeChatcmd($row->nanoline_name, "/tell <myname> nanolines $row->nanoline_id");
111: $blob .= "\n<header2>$row->profession<end> - $nanolineLink\n";
112: } else {
113: $blob .= "\n<header2>Unknown/General<end>\n";
114: }
115: $currentNanoline = $row->nanoline_id;
116: }
117: $blob .= $this->text->makeItem($row->lowid, $row->lowid, $row->lowql, $row->name);
118: $blob .= " [$row->lowql] $row->location";
119: $blob .= "\n";
120: }
121: $blob .= $this->getFooter();
122: $msg = $this->text->makeBlob("Nano Search Results ($count)", $blob);
123: }
124:
125: $sendto->reply($msg);
126: }
127:
128: 129: 130: 131:
132: public function nanolinesListProfsCommand($message, $channel, $sender, $sendto, $args) {
133: $sql = "SELECT DISTINCT profession FROM nanolines ORDER BY profession ASC";
134: $data = $this->db->query($sql);
135:
136: $blob = '';
137: forEach ($data as $row) {
138: $blob .= $this->text->makeChatcmd($row->profession, "/tell <myname> nanolines $row->profession");
139: $blob .= "\n";
140: }
141: $blob .= $this->getFooter();
142: $msg = $this->text->makeBlob('Nanolines', $blob);
143:
144: $sendto->reply($msg);
145: }
146:
147: 148: 149: 150:
151: public function nanolinesListCommand($message, $channel, $sender, $sendto, $args) {
152: if (preg_match("/^[0-9]+$/", $args[1])) {
153: $this->nanolinesShow($args[1], $sendto);
154: } else {
155: $this->nanolinesList($args[1], $sendto);
156: }
157: }
158:
159: private function nanolinesShow($nanolineId, $sendto) {
160: $sql = "SELECT * FROM nanolines WHERE id = ?";
161: $nanoline = $this->db->queryRow($sql, $nanolineId);
162:
163: $msg = '';
164: if ($nanoline !== null) {
165: $blob = '';
166:
167: $sql = "
168: SELECT
169: n1.lowid,
170: lowql,
171: n1.name,
172: location
173: FROM
174: nanos n1
175: JOIN nanos_nanolines_ref n2
176: ON (n1.lowid = n2.lowid)
177: WHERE
178: n2.nanolines_id = ?
179: ORDER BY
180: lowql DESC, name ASC";
181: $data = $this->db->query($sql, $nanolineId);
182:
183: forEach ($data as $nano) {
184: $blob .= $this->text->makeItem($nano->lowid, $nano->lowid, $nano->lowql, $nano->name);
185: $blob .= " [$nano->lowql] $nano->location\n";
186: }
187: $blob .= $this->getFooter();
188: $msg = $this->text->makeBlob("$nanoline->profession $nanoline->name Nanos", $blob);
189: } else {
190: $msg = "No nanoline found.";
191: }
192:
193: $sendto->reply($msg);
194: }
195:
196: private function nanolinesList($profession, $sendto) {
197: $profession = $this->util->getProfessionName($profession);
198: if ($profession == '') {
199: $msg = "Please choose one of these professions: adv, agent, crat, doc, enf, eng, fix, keep, ma, mp, nt, sol, shade, or trader";
200: $sendto->reply($msg);
201: return;
202: }
203:
204: $sql = "SELECT * FROM nanolines WHERE profession LIKE ? ORDER BY name ASC";
205: $data = $this->db->query($sql, $profession);
206:
207: $blob = '';
208: forEach ($data as $row) {
209: if ($this->settingManager->get("shownanolineicons") == "1") {
210: $blob .= $this->text->makeImage($row->image_id) . "\n";
211: }
212: $blob .= $this->text->makeChatcmd("$row->name", "/tell <myname> nanolines $row->id");
213: $blob .= "\n";
214: }
215: $blob .= $this->getFooter();
216: $msg = $this->text->makeBlob("$profession Nanolines", $blob);
217:
218: $sendto->reply($msg);
219: }
220:
221: 222: 223: 224:
225: public function nanolocListCommand($message, $channel, $sender, $sendto, $args) {
226: $data = $this->db->query("SELECT location, count(location) AS count FROM nanos GROUP BY location ORDER BY location ASC");
227:
228: $blob = '';
229: forEach ($data as $row) {
230: $blob .= $this->text->makeChatcmd($row->location, "/tell <myname> nanoloc $row->location") . " ($row->count) \n";
231: }
232: $blob .= $this->getFooter();
233: $msg = $this->text->makeBlob("Nano Locations", $blob);
234: $sendto->reply($msg);
235: }
236:
237: 238: 239: 240:
241: public function nanolocViewCommand($message, $channel, $sender, $sendto, $args) {
242: $location = $args[1];
243:
244: $sql =
245: "SELECT
246: n1.lowid,
247: n1.lowql,
248: n1.name,
249: n1.location,
250: n3.profession
251: FROM
252: nanos n1
253: LEFT JOIN nanos_nanolines_ref n2 ON n1.lowid = n2.lowid
254: LEFT JOIN nanolines n3 ON n2.nanolines_id = n3.id
255: WHERE
256: n1.location LIKE ?
257: ORDER BY
258: n1.profession ASC,
259: n1.name ASC";
260:
261: $data = $this->db->query($sql, $location);
262:
263: $count = count($data);
264: if ($count == 0) {
265: $msg = "No nanos found.";
266: } else {
267: $blob = '';
268: forEach ($data as $row) {
269: $blob .= $this->text->makeItem($row->lowid, $row->lowid, $row->lowql, $row->name);
270: $blob .= " [$row->lowql] $row->location";
271: if ($row->profession) {
272: $blob .= " - <highlight>$row->profession<end>";
273: }
274: $blob .= "\n";
275: }
276:
277: $msg = $this->text->makeBlob("Nanos for Location '$location' ($count)", $blob);
278: }
279:
280: $sendto->reply($msg);
281: }
282:
283: private function getFooter() {
284: return "\n\nNanos DB provided by Saavick & Lucier";
285: }
286: }
287: