From 111b5179896b2bdfe89dc3c90ba8a643ade5ea9f Mon Sep 17 00:00:00 2001 From: alexbcberio Date: Wed, 13 May 2020 15:29:57 +0200 Subject: [PATCH] Changed used avatar url + added actions when app is ran in development enviroment --- app/Http/Controllers/WebhookController.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/WebhookController.php b/app/Http/Controllers/WebhookController.php index 9a4eddb..74b82cc 100644 --- a/app/Http/Controllers/WebhookController.php +++ b/app/Http/Controllers/WebhookController.php @@ -126,13 +126,19 @@ class WebhookController extends Controller $twitchWebhook->save(); $twitchWebhook->callback .= "?hook_id=" . $twitchWebhook->id; $subscription = Twitch::subscribeWebhook($twitchWebhook->callback, $topic, $lease); + + } else if (config("app.env") !== "production") { + $subscription = Twitch::subscribeWebhook($twitchWebhook->callback, $topic, $lease); + $twitchWebhook->expires_at = Carbon::now()->addSeconds($lease); } $twitchWebhook->save(); - if ((isset($subscription) && $subscription->success) || true) { + if (isset($subscription) && $subscription->success) { return response("Ok"); } else { + $twitchWebhook->disabled = true; + $twitchWebhook->save(); return response()->json($subscription, $subscription->status); } } @@ -197,7 +203,10 @@ class WebhookController extends Controller $twitchWebhook->save(); } - if ($eventType === "start" && $twitchWebhook->webhookActions) { + if ( + ($eventType === "start" && $twitchWebhook->webhookActions) || + (config("app.env") !== "production" && $twitchWebhook->webhookActions && $eventType !== "end") + ) { // TODO: move this (generation of the message embed) to a separate method $userInfo = Twitch::getUserById(intval($data["user_id"]))->data[0]; $gameInfo = null; @@ -208,7 +217,7 @@ class WebhookController extends Controller $embed = new DiscordEmbedMessage(); $embed->setUsername(config("app.name")) - ->setAvatar("https://tse1.mm.bing.net/th?id=OIP.kncd96A4OjouPDpT8ymkIAHaHa&pid=Api&f=1") + ->setAvatar(asset("img/twitch-icon.png")) ->setContent("¡Hola @everyone! " . $data["user_name"] . " está ahora en directo https://twitch.tv/" . $userInfo->login . " ! Ven a verle :wink:!") // embed ->setColor(hexdec(substr("#9147ff", 1))) @@ -222,11 +231,8 @@ class WebhookController extends Controller ->addField("Espectadores", $data["viewer_count"], true); foreach($twitchWebhook->webhookActions as $hookAction) { - - // TODO: change the url with the appropiate one $webhook = new DiscordWebhook($hookAction->discord_hook_url); $webhook->send($embed); - } }