From b7a8416ebeb1954219891ca28dc7b84b283b0b3b Mon Sep 17 00:00:00 2001 From: Slivo Date: Mon, 15 Jan 2018 20:44:14 +0100 Subject: [PATCH] fix coporation endpoint v4 --- .gitignore | 1 + Killbot.php | 12 +- Settings.php | 145 ++++++++++++----------- composer.lock | 311 ++++++++++++++++++++++++++++++++++++++++++++++++++ cron.php | 19 ++- 5 files changed, 406 insertions(+), 82 deletions(-) create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index 1ddcf91..87fc47f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ /vendor/ +logs/* diff --git a/Killbot.php b/Killbot.php index 265ddb1..f563708 100644 --- a/Killbot.php +++ b/Killbot.php @@ -201,7 +201,7 @@ private function getShipName($victimShipId) { return $this->knownShips[$victimShipId]; } - $json = $this->curlRequest(Settings::$ESI_URL . "/universe/types/$victimShipId/"); + $json = $this->curlRequest(Settings::$ESI_URL . "v1/universe/types/$victimShipId/"); $data = json_decode($json); $shipName = $data->{'name'}; @@ -216,7 +216,7 @@ private function getCharacterName($characterId) { return $this->knownCharacters[$characterId]; } - $json = $this->curlRequest(Settings::$ESI_URL . "/characters/$characterId/"); + $json = $this->curlRequest(Settings::$ESI_URL . "v4/characters/$characterId/"); $data = json_decode($json); $characterName = $data->{'name'}; @@ -231,10 +231,10 @@ private function getCorporationName($corporationId) { return $this->knownCorporations[$corporationId]; } - $json = $this->curlRequest(Settings::$ESI_URL . "/corporations/$corporationId/"); + $json = $this->curlRequest(Settings::$ESI_URL . "v4/corporations/$corporationId/"); $data = json_decode($json); - $corporationName = $data->{'corporation_name'}; + $corporationName = $data->{'name'}; $this->knownCorporations[$corporationId] = $corporationName; return $corporationName; @@ -258,6 +258,10 @@ private function curlRequest($url) { private function pushToSlack($killData) { + if (Settings::$DEBUG) { + print_r($killData); + } + $data = "payload=" .json_encode($killData); $ch = curl_init(Settings::$SLACK_HOOK); diff --git a/Settings.php b/Settings.php index bfb0df0..b331900 100644 --- a/Settings.php +++ b/Settings.php @@ -1,73 +1,72 @@ - [ - 123456, - 1324567 - ], - 'alliances' => [ - 13245678 - ], - 'systems' => [ - 30003504 - ] - ]; - - /******************************************************************************************************************* - * Mail settings - * Allow script to send mail alert when something goes wrong - ******************************************************************************************************************/ - - // Enable sending mails - public static $SEND_MAIL = true; - - // Server configuration - public static $SMTP_SERVER = 'smtp.example.com'; - public static $SMTP_PORT = '465'; - public static $SMTP_USER = 'user@example.com'; - public static $SMTP_PASSWORD = 'my_password'; - - // Use null or ssl if required - public static $SECURITY = 'ssl'; - - // Mail addresses - public static $MAIL_RECIPIENT = 'recipient@example.com'; - public static $MAIL_SENDER = 'sender@example.com'; - - /******************************************************************************************************************* - * Advanced configuration - * Do not edit unless you know what you are doing - ******************************************************************************************************************/ - - // HTTP header sent with each bot request - public static $HTTP_HEADER = 'RedisQ-Slack-Bot https://github.com/Slivo-fr/RedisQ-Slack-Bot'; - - // URL to redisQ - public static $REDISQ_URL = 'https://redisq.zkillboard.com/listen.php?ttw=1'; - - // Enable debugging behaviors - public static $DEBUG = false; - - // Folder name for json logs - public static $KILL_LOG_FOLDER = 'logs'; - - // ESI base URL - public static $ESI_URL = 'https://esi.tech.ccp.is/latest'; -} + [ + 123456, + 1324567 + ], + 'alliances' => [ + 13245678 + ], + 'systems' => [ + 30003504 + ] + ]; + + /******************************************************************************************************************* + * Mail settings + * Allow script to send mail alert when something goes wrong + ******************************************************************************************************************/ + + // Enable sending mails + public static $SEND_MAIL = true; + + // Server configuration + public static $SMTP_SERVER = 'smtp.example.com'; + public static $SMTP_PORT = '465'; + public static $SMTP_USER = 'user@example.com'; + public static $SMTP_PASSWORD = 'my_password'; + + // Use null or ssl if required + public static $SECURITY = 'ssl'; + + // Mail addresses + public static $MAIL_RECIPIENT = 'recipient@example.com'; + public static $MAIL_SENDER = 'sender@example.com'; + + /******************************************************************************************************************* + * Advanced configuration + * Do not edit unless you know what you are doing + ******************************************************************************************************************/ + + // HTTP header sent with each bot request + public static $HTTP_HEADER = 'RedisQ-Slack-Bot https://github.com/Slivo-fr/RedisQ-Slack-Bot'; + + // URL to redisQ + public static $REDISQ_URL = 'https://redisq.zkillboard.com/listen.php?ttw=1'; + + // Enable debugging behaviors + public static $DEBUG = false; + + // Folder name for json logs + public static $KILL_LOG_FOLDER = 'logs'; + + // ESI base URL + public static $ESI_URL = 'https://esi.tech.ccp.is/';} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..ef667e3 --- /dev/null +++ b/composer.lock @@ -0,0 +1,311 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "295bf42019aa268bd19165b3ae129b5e", + "packages": [ + { + "name": "doctrine/lexer", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09T13:34:57+00:00" + }, + { + "name": "egulias/email-validator", + "version": "2.1.2", + "source": { + "type": "git", + "url": "https://github.com/egulias/EmailValidator.git", + "reference": "bc31baa11ea2883e017f0a10d9722ef9d50eac1c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/bc31baa11ea2883e017f0a10d9722ef9d50eac1c", + "reference": "bc31baa11ea2883e017f0a10d9722ef9d50eac1c", + "shasum": "" + }, + "require": { + "doctrine/lexer": "^1.0.1", + "php": ">= 5.5" + }, + "require-dev": { + "dominicsayers/isemail": "dev-master", + "phpunit/phpunit": "^4.8.0", + "satooshi/php-coveralls": "dev-master" + }, + "suggest": { + "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Egulias\\EmailValidator\\": "EmailValidator" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Eduardo Gulias Davis" + } + ], + "description": "A library for validating emails against several RFCs", + "homepage": "https://github.com/egulias/EmailValidator", + "keywords": [ + "email", + "emailvalidation", + "emailvalidator", + "validation", + "validator" + ], + "time": "2017-01-30T22:07:36+00:00" + }, + { + "name": "swiftmailer/swiftmailer", + "version": "v6.0.2", + "source": { + "type": "git", + "url": "https://github.com/swiftmailer/swiftmailer.git", + "reference": "412333372fb6c8ffb65496a2bbd7321af75733fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/412333372fb6c8ffb65496a2bbd7321af75733fc", + "reference": "412333372fb6c8ffb65496a2bbd7321af75733fc", + "shasum": "" + }, + "require": { + "egulias/email-validator": "~2.0", + "php": ">=7.0.0" + }, + "require-dev": { + "mockery/mockery": "~0.9.1", + "symfony/phpunit-bridge": "~3.3@dev" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.0-dev" + } + }, + "autoload": { + "files": [ + "lib/swift_required.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Corbyn" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Swiftmailer, free feature-rich PHP mailer", + "homepage": "http://swiftmailer.symfony.com", + "keywords": [ + "email", + "mail", + "mailer" + ], + "time": "2017-09-30T22:39:41+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", + "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2017-10-11T12:05:26+00:00" + }, + { + "name": "twig/twig", + "version": "v2.4.4", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "eddb97148ad779f27e670e1e3f19fb323aedafeb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/eddb97148ad779f27e670e1e3f19fb323aedafeb", + "reference": "eddb97148ad779f27e670e1e3f19fb323aedafeb", + "shasum": "" + }, + "require": { + "php": "^7.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "psr/container": "^1.0", + "symfony/debug": "~2.7", + "symfony/phpunit-bridge": "~3.3@dev" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Twig_": "lib/" + }, + "psr-4": { + "Twig\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + }, + { + "name": "Twig Team", + "homepage": "http://twig.sensiolabs.org/contributors", + "role": "Contributors" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "http://twig.sensiolabs.org", + "keywords": [ + "templating" + ], + "time": "2017-09-27T18:10:31+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": "^7.0" + }, + "platform-dev": [] +} diff --git a/cron.php b/cron.php index 7d8d719..970ad4e 100644 --- a/cron.php +++ b/cron.php @@ -11,14 +11,23 @@ use Killbot\Killbot; use Killbot\Settings; -try { - +function runBot() { $killbot = new Killbot(); $killbot->run(); } -catch (Exception $e) { - if (Settings::$SEND_MAIL) { - AlertHandler::sendAlertMail($e); +if (!Settings::$DEBUG) { + + try { + + runBot(); + } + catch (Exception $e) { + + if (Settings::$SEND_MAIL) { + AlertHandler::sendAlertMail($e); + } } +} else { + runBot(); }