1
0

Changed used avatar url + added actions when app is ran in development enviroment

This commit is contained in:
2020-05-13 15:29:57 +02:00
parent 9dfdc24af6
commit 111b517989

View File

@@ -126,13 +126,19 @@ class WebhookController extends Controller
$twitchWebhook->save(); $twitchWebhook->save();
$twitchWebhook->callback .= "?hook_id=" . $twitchWebhook->id; $twitchWebhook->callback .= "?hook_id=" . $twitchWebhook->id;
$subscription = Twitch::subscribeWebhook($twitchWebhook->callback, $topic, $lease); $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(); $twitchWebhook->save();
if ((isset($subscription) && $subscription->success) || true) { if (isset($subscription) && $subscription->success) {
return response("Ok"); return response("Ok");
} else { } else {
$twitchWebhook->disabled = true;
$twitchWebhook->save();
return response()->json($subscription, $subscription->status); return response()->json($subscription, $subscription->status);
} }
} }
@@ -197,7 +203,10 @@ class WebhookController extends Controller
$twitchWebhook->save(); $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 // TODO: move this (generation of the message embed) to a separate method
$userInfo = Twitch::getUserById(intval($data["user_id"]))->data[0]; $userInfo = Twitch::getUserById(intval($data["user_id"]))->data[0];
$gameInfo = null; $gameInfo = null;
@@ -208,7 +217,7 @@ class WebhookController extends Controller
$embed = new DiscordEmbedMessage(); $embed = new DiscordEmbedMessage();
$embed->setUsername(config("app.name")) $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:!") ->setContent("¡Hola @everyone! " . $data["user_name"] . " está ahora en directo https://twitch.tv/" . $userInfo->login . " ! Ven a verle :wink:!")
// embed // embed
->setColor(hexdec(substr("#9147ff", 1))) ->setColor(hexdec(substr("#9147ff", 1)))
@@ -222,11 +231,8 @@ class WebhookController extends Controller
->addField("Espectadores", $data["viewer_count"], true); ->addField("Espectadores", $data["viewer_count"], true);
foreach($twitchWebhook->webhookActions as $hookAction) { foreach($twitchWebhook->webhookActions as $hookAction) {
// TODO: change the url with the appropiate one
$webhook = new DiscordWebhook($hookAction->discord_hook_url); $webhook = new DiscordWebhook($hookAction->discord_hook_url);
$webhook->send($embed); $webhook->send($embed);
} }
} }