コード例 #1
0
ファイル: eveCharInfo.php プロジェクト: karbowiak/Sluggard
 /**
  * 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;
         // Most EVE players on Discord use their ingame name, so lets support @highlights
         $messageString = stristr($data["messageString"], "@") ? str_replace("<@", "", str_replace(">", "", $data["messageString"])) : $data["messageString"];
         if (is_numeric($messageString)) {
             // The person used @highlighting, so now we got a discord id, lets map that to a name
             $messageString = $this->sluggardDB->queryField("SELECT name FROM usersSeen WHERE id = :id", "name", array(":id" => $messageString));
         }
         $url = "http://rena.karbowiak.dk/api/search/character/{$messageString}/";
         $data = @json_decode($this->curl->getData($url), true)["character"];
         if (empty($msgData)) {
             return $msgData->user->reply("**Error:** no results was returned.");
         }
         if (count($msgData) > 1) {
             $results = array();
             foreach ($msgData as $char) {
                 $results[] = $char["characterName"];
             }
             return $msgData->user->reply("**Error:** more than one result was returned: " . implode(", ", $results));
         }
         // Get stats
         $characterID = $data[0]["characterID"];
         $statsURL = "https://beta.eve-kill.net/api/charInfo/characterID/" . urlencode($characterID) . "/";
         $stats = json_decode($this->curl->getData($statsURL), true);
         if (empty($stats)) {
             return $msgData->user->reply("**Error:** no data available");
         }
         $characterName = @$stats["characterName"];
         $corporationName = @$stats["corporationName"];
         $allianceName = isset($stats["allianceName"]) ? $stats["allianceName"] : "None";
         $factionName = isset($stats["factionName"]) ? $stats["factionName"] : "None";
         $securityStatus = @$stats["securityStatus"];
         $lastSeenSystem = @$stats["lastSeenSystem"];
         $lastSeenRegion = @$stats["lastSeenRegion"];
         $lastSeenShip = @$stats["lastSeenShip"];
         $lastSeenDate = @$stats["lastSeenDate"];
         $corporationActiveArea = @$stats["corporationActiveArea"];
         $allianceActiveArea = @$stats["allianceActiveArea"];
         $soloKills = @$stats["soloKills"];
         $blobKills = @$stats["blobKills"];
         $lifeTimeKills = @$stats["lifeTimeKills"];
         $lifeTimeLosses = @$stats["lifeTimeLosses"];
         $amountOfSoloPVPer = @$stats["percentageSoloPVPer"];
         $ePeenSize = @$stats["ePeenSize"];
         $facepalms = @$stats["facepalms"];
         $lastUpdated = @$stats["lastUpdatedOnBackend"];
         $url = "https://beta.eve-kill.net/character/" . $stats["characterID"] . "/";
         $msg = "```characterName: {$characterName}\r\ncorporationName: {$corporationName}\r\nallianceName: {$allianceName}\r\nfactionName: {$factionName}\r\nsecurityStatus: {$securityStatus}\r\nlastSeenSystem: {$lastSeenSystem}\r\nlastSeenRegion: {$lastSeenRegion}\r\nlastSeenShip: {$lastSeenShip}\r\nlastSeenDate: {$lastSeenDate}\r\ncorporationActiveArea: {$corporationActiveArea}\r\nallianceActiveArea: {$allianceActiveArea}\r\nsoloKills: {$soloKills}\r\nblobKills: {$blobKills}\r\nlifeTimeKills: {$lifeTimeKills}\r\nlifeTimeLosses: {$lifeTimeLosses}\r\npercentageSoloPVPer: {$amountOfSoloPVPer}\r\nePeenSize: {$ePeenSize}\r\nfacepalms: {$facepalms}\r\nlastUpdated: {$lastUpdated}```\r\nFor more info, visit: {$url}";
         $this->log->info("Sending char info to {$channelName} on {$guildName}");
         $msgData->user->reply($msg);
     }
 }
コード例 #2
0
ファイル: composeMsgData.php プロジェクト: karbowiak/Sluggard
 public function data($msgData, $botData)
 {
     $channelData = Channel::find($msgData["channel_id"]);
     if ($channelData->is_private == true) {
         $channelData->setAttribute("name", $msgData->author->username);
     }
     $msgData = (object) array("isBotOwner" => false, "user" => $msgData, "message" => (object) array("lastSeen" => $this->db->queryField("SELECT lastSeen FROM usersSeen WHERE id = :id", "lastSeen", array(":id" => $msgData->author->id)), "lastSpoke" => $this->db->queryField("SELECT lastSpoke FROM usersSeen WHERE id = :id", "lastSpoke", array(":id" => $msgData->author->id)), "timestamp" => $msgData->timestamp->toDateTimeString(), "id" => $msgData->author->id, "message" => $msgData->content, "channelID" => $msgData->channel_id, "from" => $msgData->author->username, "fromID" => $msgData->author->id, "fromDiscriminator" => $msgData->author->discriminator, "fromAvatar" => $msgData->author->avatar), "channel" => $channelData, "guild" => $channelData->is_private ? (object) array("name" => "private conversation") : Guild::find($channelData->guild_id), "botData" => $botData);
     return $msgData;
 }
コード例 #3
0
ファイル: eveFitting.php プロジェクト: karbowiak/Sluggard
 /**
  * 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;
         $guildID = $msgData->guild->id;
         $switch = $data["messageArray"][0];
         switch ($switch) {
             case "save":
                 $fittingURL = $data["messageArray"][1];
                 unset($data["messageArray"][0]);
                 unset($data["messageArray"][1]);
                 $fittingName = implode(" ", $data["messageArray"]);
                 $this->sluggardDB->execute("REPLACE INTO fittings (guildID, fittingName, fittingURL) VALUES (:guildID, :fittingName, :fittingURL)", array(":guildID" => $guildID, ":fittingName" => $fittingName, ":fittingURL" => $fittingURL));
                 $this->log->info("Saved fitting ({$fittingName}) on {$guildName}");
                 $msg = "Fitting saved, you can now call upon it by using !fit {$fittingName}";
                 $msgData->user->reply($msg);
                 break;
             case "delete":
                 unset($data["messageArray"][0]);
                 $fittingName = implode(" ", $data["messageArray"]);
                 if (strlen($fittingName) > 1) {
                     $fittingData = $this->sluggardDB->queryField("SELECT fittingURL FROM fittings WHERE fittingName = :fittingName AND guildID = :guildID", "fittingURL", array(":fittingName" => $fittingName, ":guildID" => $guildID));
                     if ($fittingData) {
                         $this->sluggardDB->execute("DELETE FROM fittings WHERE fittingName = :fittingName AND guildID = :guildID", array(":fittingName" => $fittingName, ":guildID" => $guildID));
                         $msg = "Fitting {$fittingName} was deleted";
                     } else {
                         $msg = "Fitting {$fittingName} not found for this server";
                     }
                 } else {
                     $msg = "Error with your search";
                 }
                 $msgData->user->reply($msg);
                 break;
             default:
                 $search = $data["messageString"];
                 if (strlen($search) > 1) {
                     $fittingData = $this->sluggardDB->queryField("SELECT fittingURL FROM fittings WHERE fittingName = :fittingName AND guildID = :guildID", "fittingURL", array(":fittingName" => $search, ":guildID" => $guildID));
                     if ($fittingData) {
                         $msg = "Fitting {$search} can be seen here: {$fittingData}";
                     } else {
                         $msg = "Fitting {$search} not found for this server";
                     }
                 } else {
                     $msg = "Error with your search";
                 }
                 $msgData->user->reply($msg);
                 break;
         }
     }
 }
コード例 #4
0
 /**
  *
  */
 public function createSluggardDB()
 {
     $tables = array("users", "usersSeen", "storage", "authentications");
     $tableCreateCode = array("users" => "\r\n            BEGIN;\r\n            CREATE TABLE IF NOT EXISTS `users` (\r\n                `id` INTEGER PRIMARY KEY AUTOINCREMENT,\r\n                `serverID` BIGINT(20) NOT NULL,\r\n                `userID` BIGINT(20) NOT NULL,\r\n                `discordID` BIGINT(20) NOT NULL,\r\n                `characterID` INT(16) NOT NULL,\r\n                `corporationID` VARCHAR(255) NOT NULL,\r\n                `allianceID` VARCHAR(255) NOT NULL,\r\n                `authString` VARCHAR(255) NOT NULL,\r\n                `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP\r\n            );\r\n            CREATE UNIQUE INDEX userID ON users (userID);\r\n            CREATE INDEX serverID ON users (serverID);\r\n            CREATE INDEX corporationID ON users (corporationID);\r\n            CREATE INDEX allianceID ON users (allianceID);\r\n            COMMIT;", "usersSeen" => "\r\n            BEGIN;\r\n            CREATE TABLE IF NOT EXISTS `usersSeen` (\r\n                `id` INTEGER PRIMARY KEY,\r\n                `name` VARCHAR(255) NOT NULL,\r\n                `isAdmin` TINYINT(1) NOT NULL DEFAULT '0',\r\n                `lastSeen` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\r\n                `lastSpoke` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n                `lastStatus` VARCHAR(50) NULL DEFAULT NULL,\r\n                `lastWritten` TEXT NULL\r\n            );\r\n            CREATE INDEX name ON usersSeen (name);\r\n            COMMIT;", "storage" => "\r\n            BEGIN;\r\n            CREATE TABLE IF NOT EXISTS `storage` (\r\n                `id` INTEGER PRIMARY KEY AUTOINCREMENT,\r\n                `key` VARCHAR(255) NOT NULL,\r\n                `value` VARCHAR(255) NOT NULL\r\n            );\r\n            CREATE UNIQUE INDEX key ON storage (key);\r\n            COMMIT;", "authentications" => "\r\n            BEGIN;\r\n            CREATE TABLE IF NOT EXISTS `authentications` (\r\n                `discordID` INTEGER PRIMARY KEY,\r\n                `characterID` BIGINT(40) NOT NULL,\r\n                `corporationID` BIGINT(40) NOT NULL,\r\n                `allianceID` BIGINT(40) NOT NULL,\r\n                `guildID` BIGINT(128) DEFAULT 0 NOT NULL\r\n            );\r\n            CREATE UNIQUE INDEX discordID ON authentications (discordID);\r\n            COMMIT;\r\n            ", "fittings" => "\r\n            BEGIN;\r\n            CREATE TABLE `fittings` (\r\n                `guildID` INTEGER PRIMARY KEY,\r\n                `fittingName` VARCHAR(255) NOT NULL,\r\n                `fittingURL` VARCHAR(255) NOT NULL\r\n            );\r\n            CREATE UNIQUE INDEX fittingName ON fittings (guildID, fittingName);\r\n            COMMIT;");
     $dbName = $this->config->get("botName", "bot");
     // Does the file exist?
     if (!file_exists(BASEDIR . "/config/database/{$dbName}.sqlite")) {
         touch(BASEDIR . "/config/database/{$dbName}.sqlite");
     }
     // Check if the tables exist, if not, create them
     foreach ($tables as $table) {
         $exists = $this->sluggardDB->queryField("SELECT name FROM sqlite_master WHERE type = 'table' AND name = :name", "name", array(":name" => $table));
         if (!$exists) {
             $this->log->warn("Creating {$table} in {$dbName}.sqlite, since it does not exist");
             $this->sluggardDB->execute(trim($tableCreateCode[$table]));
         }
     }
 }
コード例 #5
0
ファイル: user.php プロジェクト: karbowiak/Sluggard
 /**
  * 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;
         $user = stristr($data["messageString"], "@") ? str_replace("<@", "", str_replace(">", "", $data["messageString"])) : $data["messageString"];
         // Get data for user
         $userData = $this->sluggardDB->queryRow("SELECT * FROM usersSeen WHERE (name = :name COLLATE NOCASE OR id = :name)", array(":name" => $user));
         if ($userData) {
             $msg = "```ID: {$userData["id"]}\nName: {$userData["name"]}\nisAdmin: {$userData["isAdmin"]}\nLast Seen: {$userData["lastSeen"]}\nLast Spoken: {$userData["lastSpoke"]}\nLast Status: {$userData["lastStatus"]}```";
             $this->log->info("Sending time info to {$channelName} on {$guildName}");
             $msgData->user->reply($msg);
         } else {
             $msgData->user->reply("**Error:** no such user in the users table");
         }
     }
 }
コード例 #6
0
ファイル: checkCharacter.php プロジェクト: karbowiak/Sluggard
 /**
  * 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());
         }
     }
 }
コード例 #7
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;
         $authString = trim($data["messageString"]);
         $private = (bool) $msgData->channel->is_private;
         $authData = $this->authData->queryRow("SELECT * FROM registrations WHERE authString = :authString AND active = 1", array(":authString" => $authString));
         if ($private) {
             return $msgData->user->reply("**Error:** you are trying to send your auth token in private. This won't work because i need Guild information. Post it in a channel on the server where you want to be authed");
         }
         // Someone had a valid auth string, amazing
         if (!empty($authData)) {
             $groups = json_decode($authData["groups"], true);
             $roles = $msgData->guild->roles;
             $guild = $this->discord->guilds->first();
             //$guild = $this->discord->guilds->get("id", $msgData->guild->id);
             $member = $guild->members->get("id", $msgData->user->author->id);
             $username = $msgData->user->author->username;
             $discordID = $msgData->user->author->id;
             $characterID = $authData["characterID"];
             $corporationID = $authData["corporationID"];
             $allianceID = $authData["allianceID"];
             foreach ($roles as $role) {
                 $roleName = $role->name;
                 if (in_array($roleName, $groups)) {
                     // Add user to group
                     $member->addRole($role);
                     $member->save();
                 }
             }
             // Add the user data to the local database so we can recheck it
             $this->sluggardDB->execute("REPLACE INTO authentications (discordID, characterID, corporationID, allianceID) VALUES (:discordID, :characterID, :corporationID, :allianceID)", array("discordID" => $discordID, ":characterID" => $characterID, ":corporationID" => $corporationID, ":allianceID" => $allianceID));
             // Now set the auth to inactive, and we'll be golden
             $this->authData->execute("UPDATE registrations SET active = 0 WHERE authString = :authString", array(":authString" => $authString));
             $this->log->info("Authenticating {$username} in {$channelName} on {$guildName}");
             $msgData->user->reply("You have now been added to the following groups: " . implode(", ", $groups));
         } else {
             $msgData->user->reply("**Error:** you are trying to use an already used auth code, or a non-existing auth code. Either way, prepare to get #rekt");
         }
     }
 }
コード例 #8
0
ファイル: Storage.php プロジェクト: karbowiak/Sluggard
 /**
  * Get a permanent storage object from the database
  *
  * @param $key
  * @return null|string
  */
 public function get($key)
 {
     return $this->db->queryField("SELECT value FROM storage WHERE `key` = :key COLLATE NOCASE", "value", array(":key" => $key));
 }