diff --git a/app/Http/Controllers/DiscordContoller.php b/app/Http/Controllers/DiscordContoller.php index 5abcaf5..6a008c1 100644 --- a/app/Http/Controllers/DiscordContoller.php +++ b/app/Http/Controllers/DiscordContoller.php @@ -37,10 +37,10 @@ public function push_github(Request $request) public function description(Request $request) { $text = $request->body; - if($request->link != null){ - return "Type:".$request->labels." \n\n". $text .= "\n\n Link direct github: [Issue](" . $request->link . ")"; - }else{ - return "Type:".$request->labels." \n\n". $text; + if ($request->link != null) { + return "Type:" . $request->labels . " \n\n" . $text .= "\n\n Link direct github: [Issue](" . $request->link . ")"; + } else { + return "Type:" . $request->labels . " \n\n" . $text; } } @@ -54,37 +54,56 @@ public function send_feedback(Request $request) "body" => $request->body, "user_id" => $request->user_id, "labels" => $request->labels, - "link"=> $request->link, + "link" => $request->link, ]); $usersController = new UsersController(); $user = $usersController->get_info_user($request->user_id); - if(!$user){ - $user = [ - "name" => "Anonymous", - "vid" => "0000000", - ]; - } - $push = Http::post($this->url_webhooks(), [ - "avatar_url" => "https://i.pinimg.com/originals/99/1e/53/991e534b8f6038f4bdf67a97a7984822.jpg", - "embeds" => [ - [ - "title" => "Feedback from: " . $user->name . " (VID: " . $user->vid . ")", - "description" => $this->description($request), - "url" => $request->link ?? null, - "color" => "16711680", - "footer" => [ - "text" => "Feedback Form the website", - ], - "timestamp" => date("Y-m-d H:i:s") + if (!$user) { + $user = [ + "name" => "Anonymous", + "vid" => "0000000", + ]; + $push = Http::post($this->url_webhooks(), [ + "avatar_url" => "https://i.pinimg.com/originals/99/1e/53/991e534b8f6038f4bdf67a97a7984822.jpg", + "embeds" => [ + [ + "title" => "Feedback from: " . $user["name"], + "description" => $this->description($request), + "url" => $request->link ?? null, + "color" => "16711680", + "footer" => [ + "text" => "Feedback Form the website", + ], + "timestamp" => date("Y-m-d H:i:s") + ] ] - ] - ]); - return $push; + ]); + return $push; + } else { + $push = Http::post($this->url_webhooks(), [ + "avatar_url" => "https://i.pinimg.com/originals/99/1e/53/991e534b8f6038f4bdf67a97a7984822.jpg", + "embeds" => [ + [ + "title" => "Feedback from: " . $user->name . " (VID: " . $user->vid . ")", + "description" => $this->description($request), + "url" => $request->link ?? null, + "color" => "16711680", + "footer" => [ + "text" => "Feedback Form the website", + ], + "timestamp" => date("Y-m-d H:i:s") + ] + ] + + ]); + return $push; + } } - public function url_discord_for_code(Request $request){ - $url = "https://discord.com/api/oauth2/authorize?client_id=".env("discord_client_id")."&redirect_uri=http%3A%2F%2F127.0.0.1%3A8000%2Ftest2&response_type=code&scope=identify"; + public function url_discord_for_code(Request $request) + { + $url = "https://discord.com/api/oauth2/authorize?client_id=" . env("discord_client_id") . "&redirect_uri=http%3A%2F%2F127.0.0.1%3A8000%2Ftest2&response_type=code&scope=identify"; $request->merge([ "code" => $request->code, ]); @@ -94,6 +113,4 @@ public function url_discord_for_code(Request $request){ ]; return $url["code"]; } - - } diff --git a/app/Http/Controllers/GithubController.php b/app/Http/Controllers/GithubController.php index f3dd43b..45cc8e5 100644 --- a/app/Http/Controllers/GithubController.php +++ b/app/Http/Controllers/GithubController.php @@ -3,55 +3,79 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Http; +use App\Http\Controllers\DiscordContoller; + class GithubController extends Controller { - public function url_issue(){ - $url = "https://api.github.com/repos/alexcaussades/L10/issues"; + public function url_issue() + { + $url = "https://api.github.com/repos/alexcaussades/Ivatrac/issues"; return $url; } - public function token(){ + public function token() + { $token = env('Github_token_issue'); return $token; } - public function call_API(){ + public function call_API() + { $f = http::withToken($this->token())->post($this->url_issue()); return $f; - } - public function send_issue(Request $request){ + public function send_issue(Request $request) + { /** Send issue to github on the repo alexcaussades/l10 is token is valid*/ $users = new UsersController(); - + $user = $users->get_info_user($request->user_id); - if(!$user){ - $users = [ + if (!$user) { + $user = []; + $user = [ "name" => "Anonymous", "vid" => "Anonymous" ]; + $issue = Http::withToken($this->token())->post($this->url_issue(), [ + "title" => "Feedback from: " . $user["name"], + "body" => $request->body, + "labels" => [ + $request->labels + ] + ]); + /** header location de l'issue */ + $url = $this->return_url($issue); + return $url["html_url"]; + } else { + $issue = Http::withToken($this->token())->post($this->url_issue(), [ + "title" => "Feedback from: " . $user->name . " (VID: " . $user->vid . ")", + "body" => $request->body, + "labels" => [ + $request->labels + ] + ]); + /** header location de l'issue */ + $url = $this->return_url($issue); + return $url["html_url"]; } - $issue = Http::withToken($this->token())->post($this->url_issue(), [ - "title" => "Feedback from: " . $user->name . " (VID: ".$user->vid.")", - "body" => $request->body, - "labels" => [ - $request->labels - ] - ]); - /** header location de l'issue */ - $url = $this->return_url($issue->header('location')); - return $url; } - public function return_url($url){ - $url = explode("/", $url); - $new_url = "https://github.com/alexcaussades/L10/issues/" . $url[7]; - return $new_url; - + public function return_url($url) + { + $issue = $url->json(); + $issue_post = []; + $issue_post = [ + "url" => $issue["url"], + "html_url" => $issue["html_url"], + "repository_url" => $issue["repository_url"], + "labels" => $issue["labels"], + "title" => $issue["title"], + ]; + return $issue_post; } } - diff --git a/routes/web.php b/routes/web.php index 3bec35f..50fa3dd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -80,7 +80,7 @@ $whaz = new whazzupController(); $online = $whaz->online_me(); $users_me = $whaz->user_me(); - + //dd($online->json(), $users_me); $online = json_decode($online, true); return response()->view('welcome', ["whazzup" => $whazzup, "online" => $online]); } @@ -618,8 +618,31 @@ })->middleware(["auth:web"]); Route::get("test", function (Request $request) { - $event = new eventController("LFMT"); - $r = $event->get_general(); - return $r; + $w = new whazzupController(); + $u = $w->get_rwys("LFBO"); + $g = json_decode($u, true); + $unit_pi = "ft"; + $unit_km = "km"; + $rwy = []; + for ($i = 0; $i < count($g); $i++) { + $rwy[$i]["runway"] = $g[$i]["runway"]; + $rwy[$i]["length_pi"] = $g[$i]["length"]; + $rwy[$i]["length_KM"] = $g[$i]["length"] / 3281; + $rwy[$i]["length_KM"] = round($rwy[$i]["length_KM"], 2); + } + $data = [ + "rwy" => $rwy, + "unit_pi" => $unit_pi, + "unit_km" => $unit_km + ]; + $data = json_encode($data); + return $data; }); + +Route::get("test2", function (Request $request) { + $w = new whazzupController(); + $u = $w->event_ivao(); + $g = json_decode($u); + return $g; +});