Пример #1
0
 /**
  * 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());
         }
     }
 }
Пример #2
0
 /**
  * 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());
         }
     }
 }
Пример #3
0
 /**
  * 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());
         }
     }
 }
Пример #4
0
 /**
  * When the bot's tick hits a specified time, this is started
  *
  * Runtime is defined in $this->information(), timerFrequency
  */
 public function onTimer()
 {
     // Fetch all the characterIDs from the database
     $users = $this->sluggardDB->query("SELECT * FROM authentications");
     foreach ($users as $user) {
         $discordID = $user["discordID"];
         $guildID = $user["guildID"];
         $characterID = $user["characterID"];
         $corporationID = $user["corporationID"];
         $allianceID = $user["allianceID"];
         // Get the information for this user from CCP
         try {
             $ccpData = json_decode(json_encode(new SimpleXMLElement($this->curl->getData("https://api.eveonline.com/eve/CharacterAffiliation.xml.aspx?ids={$characterID}"))), true);
             $data = $ccpData["result"]["rowset"]["row"]["@attributes"];
             $currentCharacterID = $data["characterID"];
             $currentCorporationID = $data["corporationID"];
             $currentAllianceID = $data["allianceID"];
             // Lets just be sure we're doing this for the correct character.. CCP is weird sometimes
             if ($currentCharacterID == $characterID) {
                 $remove = false;
                 // Remove if the guy switched corp
                 if ($currentCorporationID != $corporationID) {
                     $remove = true;
                 }
                 // Remove if the guy switched alliance
                 if ($currentAllianceID != $allianceID) {
                     $remove = true;
                 }
                 // Lets remove the groups from this user (Every single role!)
                 if ($remove == true) {
                     $guild = $this->discord->guilds->first();
                     $guildName = $guild->name;
                     $member = $guild->members->get("id", $discordID);
                     $memberName = $member->user->username;
                     $roles = $member->roles;
                     // Remove all roles, we don't care what roles they are, remove them all..
                     // Can't remove server owner tho, so.. mehe..
                     foreach ($roles as $role) {
                         $member->removeRole($role);
                     }
                     // Delete the auth info from the db
                     $this->sluggardDB->execute("DELETE FROM authentications WHERE discordID = :discordID", array(":discordID" => $discordID));
                     $this->log->info("Deleted all roles for {$memberName} on {$guildName}");
                 }
             }
         } catch (\Exception $e) {
             $this->log->err("Error with character check: " . $e->getMessage());
         }
     }
 }
Пример #5
0
 /**
  * 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
         }
     }
 }