示例#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
 /**
  * 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);
         }
     }
 }