Verified Commit 3f97e621 authored by Connor Tumbleson's avatar Connor Tumbleson

Merge branch 'master' of github.com:iBotPeaches/PandaLove

parents 198d1085 a5ba9293
Pipeline #1334 passed with stages
in 2 minutes and 31 seconds
......@@ -118,11 +118,9 @@ class Account extends Model
{
$h5 = $this->h5();
if (! empty($h5)) {
if (!empty($h5)) {
return $h5->select('id', 'account_id');
}
return null;
}
/**
......
......@@ -13,6 +13,7 @@ class Client extends Http
/**
* @param string $name
*
* @return array
*/
public function getTicker(string $name): array
......@@ -25,4 +26,4 @@ class Client extends Http
return [];
}
}
}
\ No newline at end of file
}
......@@ -5,4 +5,4 @@ namespace Onyx\Coinmarket;
class Constants
{
public static $ticket = 'https://api.coinmarketcap.com/v1/ticker/%s';
}
\ No newline at end of file
}
<?php
declare(strict_types=1);
namespace Onyx\Coinmarket\Helpers\Bot;
......@@ -7,13 +8,14 @@ class MessageGenerator
{
/**
* @param array $data
*
* @return string
*/
public static function generateTickerMessage(array $data): string
{
$output = $data['name'] . ' (' . $data['symbol'] . ') <br />';
$output .= '<strong>$' . $data['price_usd'] . '</strong>';
$output = $data['name'].' ('.$data['symbol'].') <br />';
$output .= '<strong>$'.$data['price_usd'].'</strong>';
return $output;
}
}
\ No newline at end of file
}
<?php
declare(strict_types=1);
namespace Onyx\Coinmarket\Helpers\String;
/**
* Class Symbols
* @package Onyx\Coinmarket\Helpers\String
* Class Symbols.
*/
class Symbols
{
/**
* @param string $name
*
* @return string
*/
public static function getTickerId(string $name): string
......@@ -40,4 +41,4 @@ class Symbols
return $name;
}
}
}
\ No newline at end of file
}
......@@ -20,11 +20,13 @@ class Client extends Http
/**
* @param Account $account
* @param string $id
* @return Stats
* @param string $id
*
* @throws FortniteApiNetworkException
* @throws \Exception
* @throws \Throwable
*
* @return Stats
*/
public function getAccountRoyaleStats(Account $account, string $id): Stats
{
......@@ -53,10 +55,12 @@ class Client extends Http
/**
* @param Account $account
* @return Stats
*
* @throws FortniteApiNetworkException
* @throws \Exception
* @throws \Throwable
*
* @return Stats
*/
public function updateAccount(Account $account): Stats
{
......@@ -65,24 +69,29 @@ class Client extends Http
/**
* @param string $id
* @return string
*
* @throws \Exception
*
* @return string
*/
public function getPlatformViaEndpoint(string $id): string
{
$url = sprintf(Constants::$PvP, $id);
$data = $this->getJson($url);
return $this->getPlatformType($data);
}
/**
* @param string $name
* @param string $platform
* @return array
*
* @throws FortniteApiNetworkException
* @throws \Exception
* @throws \Throwable
*
* @return array
*/
public function getAccountByTag(string $name, string $platform): array
{
......@@ -100,8 +109,8 @@ class Client extends Http
->firstOrFail();
} catch (ModelNotFoundException $ex) {
$account = new Account([
'gamertag' => $data['displayName'],
'accountType' => $platform
'gamertag' => $data['displayName'],
'accountType' => $platform,
]);
$account->saveOrFail();
......@@ -118,6 +127,7 @@ class Client extends Http
/**
* @param string $expected
* @param string $obtained
*
* @throws FortniteApiNetworkException
*/
private function checkPlatforms(string $expected, string $obtained): void
......@@ -128,8 +138,9 @@ class Client extends Http
}
/**
* @param string $id
* @param string $id
* @param Account|null $account
*
* @return Stats
*/
private function getStatsModel(string $id, Account $account = null): Stats
......@@ -138,7 +149,7 @@ class Client extends Http
$stats = Stats::where('epic_id', $id)->firstOrFail();
} catch (ModelNotFoundException $ex) {
$stats = new Stats([
'epic_id' => $id
'epic_id' => $id,
]);
if ($account !== null) {
......@@ -150,26 +161,28 @@ class Client extends Http
}
/**
* @param Stats $statModel
* @param array $normalized
* @param Stats $statModel
* @param array $normalized
* @param string $platform
* @return bool
*
* @throws \Throwable
*
* @return bool
*/
private function updateStatsModel(Stats $statModel, array $normalized, string $platform): bool
{
$allowedAttributes = ['kills', 'matchesplayed', 'score', 'minutesplayed', 'lastmodified', 'top1', 'top3', 'top5',
'top6', 'top10', 'top12', 'top25'];
'top6', 'top10', 'top12', 'top25', ];
$oldMatches = $statModel->getMatchesSum();
foreach ($normalized[$platform] as $group => $stats) {
foreach ($stats as $key => $item) {
if (! in_array($key, $allowedAttributes)) {
if (!in_array($key, $allowedAttributes)) {
continue;
}
$key = $group . '_' . $key;
$key = $group.'_'.$key;
$statModel->setAttribute($key, $item['alltime']);
}
}
......@@ -192,8 +205,10 @@ class Client extends Http
/**
* @param array $data
* @return string
*
* @throws \Exception
*
* @return string
*/
private function getPlatformType(array $data): string
{
......@@ -202,7 +217,7 @@ class Client extends Http
$activeType = null;
foreach ($data as $item) {
foreach ($types as $type) {
if ($item['name'] === 'br_kills_' . $type . '_m0_p2') {
if ($item['name'] === 'br_kills_'.$type.'_m0_p2') {
return $type;
}
}
......@@ -212,10 +227,12 @@ class Client extends Http
}
/**
* @param array $data
* @param array $data
* @param string $platform
* @return array
*
* @throws \Exception
*
* @return array
*/
private function statNormalizer(array $data, string $platform): array
{
......@@ -234,6 +251,7 @@ class Client extends Http
/**
* @param string $type
*
* @return string
*/
private function getSquadType(string $type): string
......@@ -250,8 +268,10 @@ class Client extends Http
/**
* @param string $type
* @return string
*
* @throws \Exception
*
* @return string
*/
private function getStatType(string $type): string
{
......@@ -283,8 +303,7 @@ class Client extends Http
return 'top1';
default:
throw new \Exception('Unknown new stat - ' . $type);
throw new \Exception('Unknown new stat - '.$type);
}
}
}
......@@ -3,8 +3,7 @@
namespace Onyx\Fortnite;
/**
* Class Constants
* @package Onyx\Fortnite
* Class Constants.
*/
class Constants
{
......
......@@ -11,12 +11,13 @@ class MessageGenerator
* @var array
*/
private static $ignoredAttributes = ['id', 'epic_id', 'account_id', 'user_id', 'solo_lastmodified',
'duo_lastmodified', 'squad_lastmodified', 'created_at', 'updated_at', 'inactiveCounter'];
'duo_lastmodified', 'squad_lastmodified', 'created_at', 'updated_at', 'inactiveCounter', ];
/**
* @param Account $account
* @param Stats $old
* @param Stats $new
* @param Stats $old
* @param Stats $new
*
* @return string
*/
public static function buildOverwatchUpdateMessage(Account $account, Stats $old, Stats $new)
......@@ -49,18 +50,18 @@ class MessageGenerator
$gameDifference = $new->getMatchesSum() - $old->getMatchesSum();
$msg .= '<strong>'.$account->gamertag.'</strong> stats have been updated in <strong>' . $gameDifference . '</strong> games.<br />';
$msg .= '<strong>'.$account->gamertag.'</strong> stats have been updated in <strong>'.$gameDifference.'</strong> games.<br />';
if ($old->solo_top1 < $new->solo_top1) {
$msg .= 'Holy shit. We have a new SOLO TOP 1 (#1) FIRST PLACE' . '<br />';
$msg .= 'Holy shit. We have a new SOLO TOP 1 (#1) FIRST PLACE'.'<br />';
}
if ($old->duo_top1 < $new->duo_top1) {
$msg .= 'Wow. 1st place in DUOS. NICE!!!!' . '<br />';
$msg .= 'Wow. 1st place in DUOS. NICE!!!!'.'<br />';
}
if ($old->squad_top1 < $new->squad_top1) {
$msg .= 'PANDAS GETTING ANOTHER SQUAD WIN. #PNDA' . '<br />';
$msg .= 'PANDAS GETTING ANOTHER SQUAD WIN. #PNDA'.'<br />';
}
$msg .= '<br />Random Stats:<br />';
......
......@@ -52,8 +52,8 @@ class Http
try {
$response = $this->guzzle->get($url, [
'headers' => [
'Authorization' => 'Bearer ' . $this->accessToken,
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$this->accessToken,
'Accept' => 'application/json',
],
]);
......@@ -66,6 +66,7 @@ class Http
if ($minutes > 0) {
\Cache::put($key, $data, $minutes);
}
return $data;
} catch (\Exception $ex) {
return null;
......@@ -77,12 +78,14 @@ class Http
// 1) We have a valid access token still
if (\Cache::has($this->accessKeyCacheKey)) {
$this->accessToken = \Cache::get($this->accessKeyCacheKey);
return;
}
// 2) We have a valid refresh token
if (\Cache::has($this->refreshKeyCacheKey)) {
$this->oAuthRefresh(\Cache::get($this->refreshKeyCacheKey));
return;
}
......@@ -92,22 +95,22 @@ class Http
private function oAuthLogin()
{
$payload = [
'grant_type' => 'password',
'username' => $this->config['email'],
'password' => $this->config['password'],
'includePerms' => true
'grant_type' => 'password',
'username' => $this->config['email'],
'password' => $this->config['password'],
'includePerms' => true,
];
if (! $this->guzzle instanceof Guzzle) {
if (!$this->guzzle instanceof Guzzle) {
$this->setupGuzzle();
}
$response = $this->guzzle->post(Constants::$oAuthToken, [
'headers' => [
'Authorization' => 'Basic ' . $this->config['launcher'],
'Accept' => 'application/json',
'Authorization' => 'Basic '.$this->config['launcher'],
'Accept' => 'application/json',
],
'form_params' => $payload
'form_params' => $payload,
]);
if ($response->getStatusCode() !== 200) {
......@@ -125,9 +128,9 @@ class Http
{
$response = $this->guzzle->get(Constants::$oAuthExchange, [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'Accept' => 'application/json'
]
'Authorization' => 'Bearer '.$accessToken,
'Accept' => 'application/json',
],
]);
if ($response->getStatusCode() !== 200) {
......@@ -144,18 +147,18 @@ class Http
private function oAuthEglToken(string $exchangeCode): array
{
$payload = [
'grant_type' => 'exchange_code',
'grant_type' => 'exchange_code',
'exchange_code' => $exchangeCode,
'includePerms' => true,
'token_type' => 'egl'
'includePerms' => true,
'token_type' => 'egl',
];
$response = $this->guzzle->post(Constants::$oAuthToken, [
'headers' => [
'Authorization' => 'Basic ' . $this->config['client'],
'Accept' => 'application/json',
'Authorization' => 'Basic '.$this->config['client'],
'Accept' => 'application/json',
],
'form_params' => $payload
'form_params' => $payload,
]);
if ($response->getStatusCode() !== 200) {
......@@ -164,21 +167,22 @@ class Http
$data = json_decode($response->getBody(), true);
$this->parseoAuthIntoCache($data);
return $data;
}
private function oAuthRefresh(string $refreshToken): array
{
$payload = [
'grant_type' => 'refresh_token',
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken,
'includePerms' => true
'includePerms' => true,
];
$response = $this->guzzle->post(Constants::$oAuthToken, [
'headers' => [
'Authorization' => 'Basic ' . $this->config['client'],
'Accept' => 'application/json',
'Authorization' => 'Basic '.$this->config['client'],
'Accept' => 'application/json',
],
'form_params' => $payload,
]);
......@@ -189,11 +193,13 @@ class Http
$data = json_decode($response->getBody(), true);
$this->parseoAuthIntoCache($data);
return $data;
}
/**
* @param array $data
*
* @throws FortniteApiNetworkException
*/
private function parseoAuthIntoCache(array $data): void
......
......@@ -8,8 +8,8 @@ use Onyx\Account;
use Onyx\User;
/**
* Class Stats
* @package Onyx\Fortnite\Objects
* Class Stats.
*
* @property int $id
* @property string $epic_id
* @property int $account_id
......@@ -77,7 +77,7 @@ class Stats extends Model
'duo_lastmodified',
'squad_lastmodified',
'updated_at',
'created_at'
'created_at',
];
public static function boot()
......
......@@ -15,12 +15,12 @@ use Onyx\Destiny\Objects\Game;
use Onyx\Destiny\PlayerNotFoundException;
use Onyx\Destiny2\Client as Destiny2Client;
use Onyx\Destiny2\Helpers\Network\Bungie2OfflineException;
use Onyx\Fortnite\Client as FortniteClient;
use Onyx\Fortnite\Helpers\Network\FortniteApiNetworkException;
use Onyx\Halo5\Client as Halo5Client;
use Onyx\Halo5\H5PlayerNotFoundException;
use Onyx\Overwatch\Client as OverwatchClient;
use Onyx\Overwatch\Helpers\Network\OWApiNetworkException;
use Onyx\Fortnite\Client as FortniteClient;
use Onyx\User;
use Onyx\XboxLive\Client as XboxClient;
......
......@@ -41,13 +41,13 @@ class Season
'season' => 6,
],
7 => [
'start' => 'November 1, 2017',
'end' => 'December 29, 2017',
'start' => 'November 1, 2017',
'end' => 'December 29, 2017',
'season' => 7,
],
8 => [
'start' => 'December 31, 2017',
'end' => 'February 25, 2018',
'start' => 'December 31, 2017',
'end' => 'February 25, 2018',
'season' => 8,
],
];
......
......@@ -51,6 +51,7 @@ abstract class Console
/**
* @param string $platform
*
* @return int
*/
public static function idFromString(string $platform): int
......@@ -71,8 +72,10 @@ abstract class Console
/**
* @param int $id
* @return string
*
* @throws \Exception
*
* @return string
*/
public static function getFortniteTag(int $id)
{
......
......@@ -6,11 +6,11 @@ use Illuminate\Contracts\Auth\Guard;
use Onyx\Account;
use Onyx\Destiny\Client as DestinyClient;
use Onyx\Destiny2\Client as Destiny2Client;
use Onyx\Fortnite\Client as FortniteClient;
use Onyx\Halo5\Client as Halo5Client;
use Onyx\Halo5\H5PlayerNotFoundException;
use Onyx\Halo5\Objects\Data as Halo5Data;
use Onyx\Overwatch\Client as OverwatchClient;
use Onyx\Fortnite\Client as FortniteClient;
use PandaLove\Commands\UpdateDestinyAccount;
use PandaLove\Commands\UpdateHalo5Account;
use PandaLove\Http\Requests\AddDestiny2GamertagRequest;
......
......@@ -36,12 +36,12 @@ class ApiV1Controller extends Controller
$data = $client->getTicker($name);
if (empty($data)) {
return $this->_error('Could not find symbol: ' . $name);
return $this->_error('Could not find symbol: '.$name);
}
return Response::json([
'error' => false,
'message' => MessageGenerator::generateTickerMessage($data)
'error' => false,
'message' => MessageGenerator::generateTickerMessage($data),
], 200);
}
......
......@@ -110,7 +110,7 @@ class ApiV1Controller extends Controller
$msg = 'Stats for: <strong>'.$user->account->gamertag.'</strong> have been updated. <br /><br />';
foreach ($user->account->destiny2->characters() as $character) {
if (! empty($character)) {
if (!empty($character)) {
$msg .= $character->name().' - '.$character->max_light.'<br />';
}
}
......
......@@ -50,7 +50,7 @@ class ApiV1Controller extends Controller
->firstOrFail();
// With the user, we need gamertag and platform.
if (! isset($all['platform'])) {
if (!isset($all['platform'])) {
$all['platform'] = Console::Xbox;
} else {
$all['platform'] = Console::idFromString($all['platform']);
......@@ -63,7 +63,8 @@ class ApiV1Controller extends Controller
return $this->_error('This username could not be found. We need EPIC username + platform of system (xbl/psn/pc');
}
$msg = 'Account (' . $id . ') was found. Added into system. `/bot fn` will work.';
$msg = 'Account ('.$id.') was found. Added into system. `/bot fn` will work.';
$client->setPandaAuth($user);
$client->getAccountRoyaleStats($account, $id);
......@@ -71,7 +72,6 @@ class ApiV1Controller extends Controller
'error' => false,
'msg' => $msg,
], 200);
} catch (\Exception $e) {
return $this->_error($e->getMessage());
}
......@@ -106,7 +106,6 @@ class ApiV1Controller extends Controller
'error' => false,
'msg' => $msg,
], 200);
} catch (\Exception $e) {
return $this->_error($e->getMessage());
}
......
......@@ -5,7 +5,6 @@ namespace PandaLove\Http\Controllers\Fortnite;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Onyx\Fortnite\Objects\Stats;
use Onyx\XboxLive\Enums\Console;
use PandaLove\Commands\UpdateFortniteAccount;
use PandaLove\Http\Controllers\Controller;
......@@ -32,14 +31,14 @@ class ProfileController extends Controller
return view('fortnite.profile', [
'account' => $stats->account,
'stats' => $stats
'stats' => $stats,
]);
} catch (ModelNotFoundException $e) {
\App::abort(404, 'We could not find this Fortnite Profile.');
}
}
public function checkForUpdate(string $id = "")
public function checkForUpdate(string $id = '')
{
if ($this->request->ajax() && !\Agent::isRobot()) {
try {
......@@ -84,7 +83,7 @@ class ProfileController extends Controller
}
}
public function manualUpdate(string $id = "")
public function manualUpdate(string $id = '')
{
if (\Auth::check()) {
try {
......
......@@ -3,8 +3,7 @@
namespace PandaLove\Http\Requests;
/**
* Class AddFortniteRequest
* @package PandaLove\Http\Requests
* Class AddFortniteRequest.
*/
class AddFortniteRequest extends Request
{
......
......@@ -103,7 +103,7 @@ return [
'key' => env('APP_KEY', 'JtLvQ2J5r51gJf3b9tr1Ctxcq3xpsBPV'),
'cipher' => "AES-256-CBC",
'cipher' => 'AES-256-CBC',
/*
|--------------------------------------------------------------------------
......
......@@ -53,10 +53,10 @@ return [
],
'fortnite' => [
'email' => env('FORTNITE_USER_EMAIL'),
'email' => env('FORTNITE_USER_EMAIL'),
'password' => env('FORTNITE_USER_PASSWORD'),
'launcher' => env('FORTNITE_LAUNCHER_TOKEN'),
'client' => env('FORTNITE_CLIENT_TOKEN'),
'client' => env('FORTNITE_CLIENT_TOKEN'),
],
];
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddFortniteTables extends Migration
{
......@@ -46,21 +46,21 @@ class AddFortniteTables extends Migration
private function types(Blueprint $table, string $type)
{
$table->timestamp($type . '_lastmodified');
$table->integer($type . '_kills', false, true);
$table->integer($type . '_matchesplayed', false, true);
$table->integer($type . '_score', false, true);
$table->integer($type . '_minutesplayed', false, true);
$table->timestamp($type.'_lastmodified');
$table->integer($type.'_kills', false, true);
$table->integer($type.'_matchesplayed', false, true);
$table->integer($type.'_score', false, true);
$table->integer($type.'_minutesplayed', false, true);
}
private function places(Blueprint $table, string $type)
{
$table->integer($type . '_top1', false, true);
$table->integer($type . '_top3', false, true);
$table->integer($type . '_top5', false, true);
$table->integer($type . '_top6', false, true);