/** * When the bot does a tick (every second), this is started */ public function onTick() { $check = true; foreach ($this->keys as $keyOwner => $api) { try { if ($check == false) { continue; } $keyID = $api["keyID"]; $vCode = $api["vCode"]; if (@$api["corpKey"] == true) { continue; } $characterID = $api["characterID"]; $lastChecked = $this->storage->get("notificationCheck{$keyID}{$keyOwner}{$characterID}"); if ($lastChecked <= time()) { $this->log->info("Checking API Key {$keyID} belonging to {$keyOwner} for new notifications"); $this->getNotifications($keyID, $vCode, $characterID); $this->storage->set("notificationCheck{$keyID}{$keyOwner}{$characterID}", time() + 1805); // Reschedule it's check for 30minutes from now (Plus 5s, ~CCP~) $check = false; } } catch (\Exception $e) { $this->log->err("Error with eve notification checker: " . $e->getMessage()); } } }
/** * When the bot does a tick (every second), this is started */ public function onTick() { // If there are no corp api keys, don't run.. if ($this->run == false) { return; } $check = true; foreach ($this->keys as $keyOwner => $api) { try { if ($check == false) { continue; } $keyID = $api["keyID"]; $vCode = $api["vCode"]; if ($api["corpKey"] == false) { continue; } $lastChecked = $this->storage->get("siphonCheck{$keyID}{$keyOwner}"); if ($lastChecked <= time()) { $this->log->info("Checking API Key {$keyID} belonging to {$keyOwner} for Siphons"); $this->checkForSiphons($keyID, $vCode); $this->storage->set("siphonCheck{$keyID}{$keyOwner}", time() + 21602); // Reschedule it's check for new data in 6 hours (plus 2 seconds) $check = false; } } catch (\Exception $e) { $this->log->err("Error with eve siphon checker: " . $e->getMessage()); } } }
/** * When the bot does a tick (every second), this is started */ public function onTick() { $check = true; foreach ($this->keys as $keyOwner => $api) { try { if ($check == false) { return; } $keyID = $api["keyID"]; $vCode = $api["vCode"]; if (@$api["corpKey"] == true) { continue; } $characterID = $api["characterID"]; $lastChecked = $this->storage->get("corpMailCheck{$keyID}{$keyOwner}{$characterID}"); if ($lastChecked <= time()) { $this->log->info("Checking API Key {$keyID} belonging to {$keyOwner} for new corp mails"); $this->checkMails($keyID, $vCode, $characterID); $this->storage->set("corpMailCheck{$keyID}{$keyOwner}{$characterID}", time() + 1807); // Reschedule it's check for 30minutes from now (plus 7 seconds, because CCP isn't known to adhere strictly to timeouts, lol) $check = false; } } catch (\Exception $e) { $this->log->err("Error with eve mail checker: " . $e->getMessage()); } } }
/** * */ public function createCCPDB() { $ccpDataURL = "https://www.fuzzwork.co.uk/dump/sqlite-latest.sqlite.bz2"; $ccpDataMD5URL = "https://www.fuzzwork.co.uk/dump/sqlite-latest.sqlite.bz2.md5"; $dbLocation = BASEDIR . "/config/database/"; $md5 = explode(" ", $this->curl->getData($ccpDataMD5URL))[0]; $lastSeenMd5 = $this->storage->get("ccpDataMd5"); // If the last seen md5, isn't equal the current seen md5, we'll update! if ($lastSeenMd5 !== $md5) { try { $this->log->notice("Updating CCP SQLite Database"); $this->log->notice("Downloading bz2 file, and writing it to {$dbLocation}ccpData.sqlite.bz2"); $downloadedData = $this->curl->getLargeData($ccpDataURL, "{$dbLocation}ccpData.sqlite.bz2"); if ($downloadedData == false) { $this->log->warn("Error: File not downloaded successfully!"); die; } $this->log->notice("Opening bz2 file"); $sqliteData = bzopen("{$dbLocation}ccpData.sqlite.bz2", "r"); $this->log->notice("Reading from bz2 file"); $data = ""; while (!feof($sqliteData)) { $data .= bzread($sqliteData, 4096); } $this->log->notice("Writing bz2 file contents into .sqlite file"); file_put_contents("{$dbLocation}ccpData.sqlite", $data); $this->log->notice("Deleting bz2 file"); unlink("{$dbLocation}ccpData.sqlite.bz2"); $this->log->notice("Creating mapCelestials view"); $this->ccpDB->execute("CREATE VIEW mapAllCelestials AS SELECT itemID, itemName, typeName, mapDenormalize.typeID, solarSystemName, mapDenormalize.solarSystemID, mapDenormalize.constellationID, mapDenormalize.regionID, mapRegions.regionName, orbitID, mapDenormalize.x, mapDenormalize.y, mapDenormalize.z FROM mapDenormalize JOIN invTypes ON (mapDenormalize.typeID = invTypes.typeID) JOIN mapSolarSystems ON (mapSolarSystems.solarSystemID = mapDenormalize.solarSystemID) JOIN mapRegions ON (mapDenormalize.regionID = mapRegions.regionID) JOIN mapConstellations ON (mapDenormalize.constellationID = mapConstellations.constellationID)"); $this->log->notice("CCP Database updated!"); $this->storage->set("ccpDataMd5", $md5); } catch (\Exception $e) { $this->log->warn("Error updating the CCPDatabase. Bot can't run"); die; } } }
/** * When the bot's tick hits a specified time, this is started * * Runtime is defined in $this->information(), timerFrequency */ public function onTimer() { $continue = false; $data = array(); // Fetch the last 5 twitter replies and/or searches try { $data = $this->twitter->load(Twitter::ME_AND_FRIENDS, 5); foreach ($data as $message) { $text = (array) $message->text; $createdAt = (array) $message->created_at; $postedBy = (array) $message->user->name; $screenName = (array) $message->user->screen_name; $id = (int) $message->id; $this->lastID = $this->storage->get("twitterLatestID"); // get the last posted ID if ($id <= $this->lastID) { continue; } $this->maxID = max($id, $this->maxID); $url = "https://twitter.com/" . $screenName[0] . "/status/" . $id; $message = array("message" => $text[0], "postedAt" => $createdAt[0], "postedBy" => $postedBy[0], "screenName" => $screenName[0], "url" => $url . $id[0]); $msg = "**@" . $screenName[0] . "** (" . $message["postedBy"] . ") / " . htmlspecialchars_decode($message["message"]); $messages[$id] = $msg; $continue = true; if (sizeof($data)) { $this->storage->set("twitterLatestID", $this->maxID); } } } catch (Exception $e) { $this->log->err("Twitter Error: " . $e->getMessage()); // Don't show there was an error, it's most likely just a rate limit } if ($continue == true) { ksort($messages); $channel = \Discord\Parts\Channel\Channel::find($this->channelID); foreach ($messages as $id => $msg) { $channel->sendMessage($msg); sleep(1); // Lets sleep for a second, so we don't rage spam } } }