Пример #1
0
 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;
 }
Пример #2
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;
         // 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);
     }
 }
 /**
  *
  */
 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]));
         }
     }
 }
Пример #4
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;
         $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;
         }
     }
 }
Пример #5
0
 /**
  * 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));
 }