예제 #1
0
 /**
  * When a message arrives that contains a trigger, this is started
  *
  * @param $msgData
  */
 public function onMessage(stdClass $msgData)
 {
     $message = $msgData->message->message;
     $data = $this->trigger->trigger($message, $this->information()["trigger"]);
     if (isset($data["trigger"])) {
         $channelName = $msgData->channel->name;
         $guildName = $msgData->guild->name;
         $systemName = $data["trigger"];
         $itemName = $data["messageString"];
         if ($itemName) {
             // Quick lookups
             if (isset($this->quickLookUps[$itemName])) {
                 $single = $this->quickLookUps[$itemName];
                 $multiple = null;
             } else {
                 $single = $this->ccpDB->queryRow("SELECT typeID, typeName FROM invTypes WHERE typeName = :item COLLATE NOCASE", array(":item" => ucfirst($itemName)));
                 $multiple = $this->ccpDB->query("SELECT typeID, typeName FROM invTypes WHERE typeName LIKE :item COLLATE NOCASE LIMIT 5", array(":item" => "%" . ucfirst($itemName) . "%"));
             }
             // Sometimes the multiple lookup is returning just one
             if (count($multiple) == 1) {
                 $single = $multiple[0];
             }
             // If there are multiple results, and not a single result, it's an error
             if (empty($single) && !empty($multiple)) {
                 $items = array();
                 foreach ($multiple as $item) {
                     $items[] = $item["typeName"];
                 }
                 $items = implode(", ", $items);
                 return $msgData->user->reply("**Multiple results found:** {$items}");
             }
             // If there is a single result, we'll get data now!
             if ($single) {
                 $typeID = $single["typeID"];
                 $typeName = $single["typeName"];
                 $solarSystemID = $systemName == "pc" ? "global" : $this->solarSystems[$systemName];
                 // Get pricing data
                 if ($solarSystemID == "global") {
                     $data = new SimpleXMLElement($this->curl->getData("https://api.eve-central.com/api/marketstat?typeid={$typeID}"));
                 } else {
                     $data = new SimpleXMLElement($this->curl->getData("https://api.eve-central.com/api/marketstat?usesystem={$solarSystemID}&typeid={$typeID}"));
                 }
                 $lowBuy = number_format((double) $data->marketstat->type->buy->min, 2);
                 $avgBuy = number_format((double) $data->marketstat->type->buy->avg, 2);
                 $highBuy = number_format((double) $data->marketstat->type->buy->max, 2);
                 $lowSell = number_format((double) $data->marketstat->type->sell->min, 2);
                 $avgSell = number_format((double) $data->marketstat->type->sell->avg, 2);
                 $highSell = number_format((double) $data->marketstat->type->sell->max, 2);
                 $this->log->info("Sending pricing info to {$channelName} on {$guildName}");
                 $solarSystemName = $systemName == "pc" ? "Global" : ucfirst($systemName);
                 $messageData = "```\r\ntypeName: {$typeName}\r\nsolarSystemName: {$solarSystemName}\r\nBuy:\r\n  Low: {$lowBuy}\r\n  Avg: {$avgBuy}\r\n  High: {$highBuy}\r\nSell:\r\n  Low: {$lowSell}\r\n  Avg: {$avgSell}\r\n  High: {$highSell}```";
                 $msgData->user->reply($messageData);
             } else {
                 $msgData->user->reply("**Error:** ***{$itemName}*** not found");
             }
         } else {
             $msgData->user->reply("**Error:** No itemName set..");
         }
     }
 }
예제 #2
0
 /**
  *
  */
 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;
         }
     }
 }
예제 #3
0
 /**
  * When a message arrives that contains a trigger, this is started
  *
  * @param $msgData
  */
 public function onMessage($msgData)
 {
     $message = $msgData->message->message;
     $data = $this->trigger->trigger($message, $this->information()["trigger"]);
     if (isset($data["trigger"])) {
         $channelName = $msgData->channel->name;
         $guildName = $msgData->guild->name;
         $item = $data["messageString"];
         if (is_numeric($item)) {
             $data = $this->ccpDB->queryRow("SELECT * FROM invTypes WHERE typeID = :item", array(":item" => $item));
         } else {
             $data = $this->ccpDB->queryRow("SELECT * FROM invTypes WHERE typeName = :item COLLATE NOCASE", array(":item" => $item));
         }
         if ($data) {
             $msg = "```";
             foreach ($data as $key => $value) {
                 $msg .= $key . ": " . $value . "\n";
             }
             $msg .= "```";
             $this->log->info("Sending item info to {$channelName} on {$guildName}");
             $msgData->user->reply($msg);
         }
     }
 }
예제 #4
0
 /**
  * @param $keyID
  * @param $vCode
  */
 private function checkForSiphons($keyID, $vCode)
 {
     try {
         // Seriously CCP.. *sigh*
         $url = "https://api.eveonline.com/corp/AssetList.xml.aspx?keyID={$keyID}&vCode={$vCode}";
         $data = json_decode(json_encode(simplexml_load_string($this->curl->getData($url), "SimpleXMLElement", LIBXML_NOCDATA)), true);
         $data = $data["result"]["rowset"]["row"];
         // If there is no data, just quit..
         if (empty($data)) {
             return;
         }
         $fixedData = array();
         foreach ($data as $key => $getFuckedCCP) {
             if ($getFuckedCCP["@attributes"]["typeID"] == 14343) {
                 $fixedData[$key] = $getFuckedCCP["@attributes"];
                 $fixedData[$key]["siloContents"] = @$getFuckedCCP["rowset"]["row"]["@attributes"];
             }
         }
         foreach ($fixedData as $silos) {
             $locationID = $silos["locationID"];
             $locationName = $this->ccpDB->queryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $locationID));
             $siloContents = $silos["siloContents"];
             $quantity = $siloContents["quantity"];
             $siloHarvesting = $siloContents["typeID"];
             $siloHarvestingName = $this->ccpDB->queryField("SELECT typeName FROM invTypes WHERE typeID = :id", "typeName", array(":id" => $siloHarvesting));
             // Skip this silo if it has no data
             if ($siloContents == null || empty($siloContents)) {
                 continue;
             }
             // If we're being siphoned
             if ($quantity % 100 != 0) {
                 $msg = "**Alert:** Possible Siphon detected in {$locationName}.. What is being siphoned: {$siloHarvestingName}";
                 $channel = \Discord\Parts\Channel\Channel::find($this->toDiscordChannel);
                 $channel->sendMessage($msg);
             }
         }
     } catch (Exception $e) {
         $this->log->debug("Error: " . $e->getMessage());
     }
 }
예제 #5
0
 /**
  * @param $keyID
  * @param $vCode
  * @param $characterID
  */
 private function getNotifications($keyID, $vCode, $characterID)
 {
     try {
         // Seriously CCP.. *sigh*
         // Ignore notifications from these douchebags..
         $ignoreNames = array("CCP");
         $url = "https://api.eveonline.com/char/Notifications.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}";
         $data = json_decode(json_encode(simplexml_load_string($this->curl->getData($url), "SimpleXMLElement", LIBXML_NOCDATA)), true);
         $data = $data["result"]["rowset"]["row"];
         // If there is no data, just quit..
         if (empty($data)) {
             return;
         }
         $fixedData = array();
         // Sometimes there is only ONE notification, so.. yeah..
         if (count($data) > 1) {
             foreach ($data as $getFuckedCCP) {
                 $fixedData[] = $getFuckedCCP["@attributes"];
             }
         } else {
             $fixedData[] = $data["@attributes"];
         }
         foreach ($fixedData as $notification) {
             $notificationID = $notification["notificationID"];
             $typeID = $notification["typeID"];
             //$senderID = $notification["senderID"];
             $senderName = $notification["senderName"];
             $sentDate = $notification["sentDate"];
             //$read = $notification["read"];
             // If the senderName is in the list of ignores names, then continue and ignore it..
             if (in_array($senderName, $ignoreNames)) {
                 continue;
             }
             if ($notificationID > $this->newestNotificationID) {
                 $notificationString = explode("\n", $this->getNotificationText($keyID, $vCode, $characterID, $notificationID));
                 $msg = null;
                 // Seriously, get f****d CCP
                 switch ($typeID) {
                     case 5:
                         // War Declared
                         $aggressorAllianceID = trim(explode(": ", $notificationString[2])[1]);
                         $aggressorAllianceName = $this->apiData("alli", $aggressorAllianceID)["allianceName"];
                         $delayHours = trim(explode(": ", $notificationString[3])[1]);
                         $msg = "War declared by {$aggressorAllianceName}. Fighting begins in roughly {$delayHours} hours.";
                         break;
                     case 8:
                         // Alliance war invalidated by CONCORD
                         $aggressorAllianceID = trim(explode(": ", $notificationString[2])[1]);
                         $aggressorAllianceName = $this->apiData("alli", $aggressorAllianceID)["allianceName"];
                         $msg = "War declared by {$aggressorAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
                         break;
                     case 75:
                         // POS / POS Module under attack
                         $aggressorAllianceID = trim(explode(": ", $notificationString[0])[1]);
                         $aggressorAllianceName = $this->apiData("alli", $aggressorAllianceID)["allianceName"];
                         $aggressorCorpID = trim(explode(": ", $notificationString[1])[1]);
                         $aggressorCorpName = $this->apiData("corp", $aggressorCorpID)["corporationName"];
                         $aggressorID = trim(explode(": ", $notificationString[2])[1]);
                         $aggressorCharacterName = $this->apiData("char", $aggressorID)["characterName"];
                         $armorValue = trim(explode(": ", $notificationString[3])[1]);
                         $hullValue = trim(explode(": ", $notificationString[4])[1]);
                         $moonID = trim(explode(": ", $notificationString[5])[1]);
                         $moonName = $this - $this->ccpDB->queryField("SELECT itemName FROM mapAllCelestials WHERE itemID = :id", "itemName", array(":id" => $moonID));
                         $shieldValue = trim(explode(": ", $notificationString[6])[1]);
                         $solarSystemID = trim(explode(": ", $notificationString[7])[1]);
                         $systemName = $this->ccpDB->queryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $solarSystemID));
                         $msg = "POS under attack in **{$systemName} - {$moonName}** by {$aggressorCharacterName} ({$aggressorCorpName} / {$aggressorAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}";
                         break;
                     case 76:
                         // Tower resource alert
                         $moonID = trim(explode(": ", $notificationString[2])[1]);
                         $moonName = $this->ccpDB->queryField("SELECT itemName FROM mapAllCelestials WHERE itemID = :id", "itemName", array(":id" => $moonID));
                         $solarSystemID = trim(explode(": ", $notificationString[3])[1]);
                         $systemName = $this->ccpDB->queryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $solarSystemID));
                         $blocksRemaining = trim(explode(": ", $notificationString[6])[1]);
                         $typeID = trim(explode(": ", $notificationString[7])[1]);
                         $typeName = $this->ccpDB->queryField("SELECT typeName FROM invTypes WHERE typeID = :id", "typeName", array(":id" => $typeID));
                         $msg = "POS in {$systemName} - {$moonName} needs fuel. Only {$blocksRemaining} {$typeName}'s remaining.";
                         break;
                     case 88:
                         // IHUB is being attacked
                         $aggressorAllianceID = trim(explode(": ", $notificationString[0])[1]);
                         $aggressorAllianceName = $this->apiData("alli", $aggressorAllianceID)["allianceName"];
                         $aggressorCorpID = trim(explode(": ", $notificationString[0])[1]);
                         $aggressorCorpName = $this->apiData("corp", $aggressorCorpID)["corporationName"];
                         $aggressorID = trim(explode(": ", $notificationString[1])[1]);
                         $aggressorCharacterName = $this->apiData("char", $aggressorID)["characterName"];
                         $armorValue = trim(explode(": ", $notificationString[3])[1]);
                         $hullValue = trim(explode(": ", $notificationString[4])[1]);
                         $shieldValue = trim(explode(": ", $notificationString[5])[1]);
                         $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
                         $systemName = $this->ccpDB->queryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $solarSystemID));
                         $msg = "IHUB under attack in **{$systemName}** by {$aggressorCharacterName} ({$aggressorCorpName} / {$aggressorAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}";
                         break;
                     case 93:
                         // Customs office is being attacked
                         $aggressorAllianceID = trim(explode(": ", $notificationString[0])[1]);
                         $aggressorAllianceName = $this->apiData("alli", $aggressorAllianceID)["allianceName"];
                         $aggressorCorpID = trim(explode(": ", $notificationString[0])[1]);
                         $aggressorCorpName = $this->apiData("corp", $aggressorCorpID)["corporationName"];
                         $aggressorID = trim(explode(": ", $notificationString[2])[1]);
                         $aggressorCharacterName = $this->apiData("char", $aggressorID)["characterName"];
                         $planetID = trim(explode(": ", $notificationString[3])[1]);
                         $planetName = $this->ccpDB->queryField("SELECT itemName FROM mapAllCelestials WHERE itemID = :id", "itemName", array(":id" => $planetID));
                         $shieldValue = trim(explode(": ", $notificationString[5])[1]);
                         $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
                         $systemName = $this->ccpDB->queryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $solarSystemID));
                         $typeID = trim(explode(": ", $notificationString[7])[1]);
                         $typeName = $this->ccpDB->queryField("SELECT typeName FROM invTypes WHERE typeID = :id", "typeName", array(":id" => $typeID));
                         $msg = "Customs Office under attack in **{$systemName}** ({$planetName}) by {$aggressorCharacterName} ({$aggressorCorpName} / {$aggressorAllianceName}). Shield Status: {$shieldValue}";
                         break;
                     case 147:
                         // Entosis has stated
                         $systemID = trim(explode(": ", $notificationString[0])[1]);
                         $systemName = $this->ccpDB->queryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $systemID));
                         $typeID = trim(explode(": ", $notificationString[1])[1]);
                         $typeName = $this->ccpDB->queryField("SELECT typeName FROM invTypes WHERE typeID = :id", "typeName", array(":id" => $typeID));
                         $msg = "Entosis has started in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
                         break;
                     case 148:
                         // Entosis enabled a module ??????
                         $systemID = trim(explode(": ", $notificationString[0])[1]);
                         $systemName = $this->ccpDB->queryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $systemID));
                         $typeID = trim(explode(": ", $notificationString[1])[1]);
                         $typeName = $this->ccpDB->queryField("SELECT typeName FROM invTypes WHERE typeID = :id", "typeName", array(":id" => $typeID));
                         $msg = "Entosis has enabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
                         break;
                     case 149:
                         // Entosis disabled a module
                         $systemID = trim(explode(": ", $notificationString[0])[1]);
                         $systemName = $this->ccpDB->queryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $systemID));
                         $typeID = trim(explode(": ", $notificationString[1])[1]);
                         $typeName = $this->ccpDB->queryField("SELECT typeName FROM invTypes WHERE typeID = :id", "typeName", array(":id" => $typeID));
                         $msg = "Entosis has disabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
                         break;
                     case 160:
                         // Entosis successful
                         $systemID = trim(explode(": ", $notificationString[2])[1]);
                         $systemName = dbQueryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $systemID), "ccp");
                         $msg = "Hostile entosis successful. A structure in **{$systemName}** has entered reinforced mode.";
                         break;
                     case 161:
                         // Command Nodes Decloaking
                         $systemID = trim(explode(": ", $notificationString[2])[1]);
                         $systemName = $this->ccpDB->queryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $systemID));
                         $msg = "Command nodes decloaking for **{$systemName}**";
                         break;
                     case 163:
                         //  Freeport
                         $systemID = trim(explode(": ", $notificationString[1])[1]);
                         $systemName = dbQueryField("SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id", "solarSystemName", array(":id" => $systemID), "ccp");
                         $msg = "Station in **{$systemName}** has entered freeport mode.";
                         break;
                 }
                 if ($msg) {
                     $channel = \Discord\Parts\Channel\Channel::find($this->toDiscordChannel);
                     $channel->sendMessage($msg);
                 }
                 // Find the maxID so we don't output this message again in the future
                 $this->maxID = max($notificationID, $this->maxID);
                 $this->newestNotificationID = $this->maxID;
                 $this->storage->set("newestNotificationID", $this->maxID);
             }
         }
     } catch (Exception $e) {
         $this->log->debug("Error: " . $e->getMessage());
     }
 }