bot -> db -> define_tablename("sws", "true"); $sql .= " (name VARCHAR(25) PRIMARY KEY, duration INT(6) NOT NULL DEFAULT 0)"; $this -> bot -> db -> query($sql); $this -> register_command("all", "sws", "GUEST"); $this -> register_event("timer", "sws"); $this -> register_event("buddy"); $this -> register_event("connect"); $classid = $this -> bot -> core("timer") -> create_timer_class('SWS', 'Timer for notifications about the runtime of your Shadowweb Spinner.'); $nextid = $this -> bot -> core("timer") -> create_timer_class_entry($classid, -2, 0, 'Your SWS has run out', '!'); $nextid = $this -> bot -> core("timer") -> create_timer_class_entry($classid, $nextid, 30, 'Your SWS has 30 seconds left', '!'); $nextid = $this -> bot -> core("timer") -> create_timer_class_entry($classid, $nextid, 60, 'Your SWS has one minute left', '!'); $nextid = $this -> bot -> core("timer") -> create_timer_class_entry($classid, $nextid, 300, 'Your SWS has five minutes left', '!'); $nextid = $this -> bot -> core("timer") -> create_timer_class_entry($classid, $nextid, 900, 'Your SWS has 15 minutes left', '!'); $nextid = $this -> bot -> core("timer") -> create_timer_class_entry($classid, $nextid, 1800, 'Your SWS has 30 minutes left', '!'); $nextid = $this -> bot -> core("timer") -> create_timer_class_entry($classid, $nextid, 3600, 'Your SWS has one hour left', '!'); $this -> help['description'] = 'Keeps track of the time left on the SWS of the caller.'; $this -> help['command']['sws'] = "Shows the time left on your SWS."; $this -> help['command']['sws (refresh|set)'] = "Resets your SWS timer to six hours."; $this -> help['command']['sws clear'] = "Deletes your SWS timer."; $this -> help['notes'] = 'The output is just an approximation, due to bot and buddy lag it will most likely be off a couple of minutes in the end.'; $this -> startup = time() + 300; } function command_handler($name, $msg, $origin) { $com = $this -> parse_com($msg); switch ($com["com"]) { case "sws": $who = $this -> bot -> core("whois") -> lookup($name); if ($who["profession"] != "Fixer") { return false; } if (empty($com["sub"])) { return $this -> get_time_remaining($name); } switch (strtolower($com["sub"])) { case "refresh": case "set": return $this -> set_sws_timer($name); case "clear": return $this -> clear_sws_timer($name); } break; } return false; } function connect() { $this -> startup = time() + 30; } function buddy($name, $msg) { if (time() < $this -> startup) { return; } $who = $this -> bot -> core("whois") -> lookup($name); if ($who['profession'] != "Fixer") { return; } // On logon check for entry, if yes set timer if ($msg == 1) { $ret = $this -> bot -> db -> select("SELECT duration FROM #___sws WHERE name = '" . $name . "'", MYSQL_ASSOC); if (!empty($ret)) { $this -> bot -> db -> query("DELETE FROM #___sws WHERE name = '" . $name . "'"); $this -> set_sws_timer($name, $ret[0]['duration']); } } else { // On logoff check for timer, save remaining duration to table $timer = $this -> get_timer($name); if ($timer != NULL) { $remaining = $timer['endtime'] - time(); $this -> bot -> db -> query("INSERT INTO #___sws (name, duration) VALUES ('" . $name . "', " . $remaining . ")"); $this -> bot -> core("timer") -> del_timer("sws", $timer['id']); } } } function get_timer($name) { $events = $this -> bot -> core("timer") -> list_timed_events("sws"); if (!empty($events)) { foreach ($events AS $event) { if ($event['name'] == $name) { return $this -> bot -> core("timer") -> get_timer($event['id']); } } } return NULL; } function timer($name, $prefix, $suffix, $delay) { $this -> bot -> send_tell($name, $prefix . $suffix); } function get_time_remaining($name) { $timer = $this -> get_timer($name); if ($timer != NULL) { $msg = "Your SWS has##highlight## " . $this -> bot -> core("time") -> format_seconds($timer['endtime'] - time()) . "##end## left,##highlight## " . $name . "##end##!"; } else { $msg = "No SWS timer found for you,##highlight## " . $name . "##end##!"; } return $msg; } function set_sws_timer($name, $time = 21600) { if ($time > 21600) { $time = 21600; } if ($time <= 0) { return "Time too short!"; } $this -> clear_sws_timer($name); $this -> bot -> core("timer") -> add_timer(false, "sws", $time, $name, "internal", 0, "SWS"); return "Timer for your SWS started,##highlight## " . $name . "##end##! Remaining duration:##highlight## " . $this -> bot -> core("time") -> format_seconds($time) . "##end##"; } function clear_sws_timer($name) { $timer = $this -> get_timer($name); if ($timer != NULL) { $ret = $this -> bot -> core("timer") -> del_timer("sws", $timer['id']); return "Your SWS timer was deleted,##highlight## " . $name . "##end##!"; } return "No SWS timer found for you,##highlight## " . $name . "##end##!"; } } ?>