From 346cd59e66ada91ed0b7bc5996cdaedabdfe80f8 Mon Sep 17 00:00:00 2001 From: Einar Engstrom Date: Wed, 25 Oct 2023 02:07:42 -0400 Subject: [PATCH] by logic should work --- lib/fruitbot/commands.ex | 19 ++++++++++++++----- lib/fruitbot/streampusher_api.ex | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/fruitbot/commands.ex b/lib/fruitbot/commands.ex index ed70740..9bf645e 100644 --- a/lib/fruitbot/commands.ex +++ b/lib/fruitbot/commands.ex @@ -177,9 +177,9 @@ defmodule Fruitbot.Commands do {:ok, result} "!datafruiter" -> - { url, username } = Fruitbot.StreampusherApi.user_search(query) - message = "Datafruit found: #{url}" - {:ok, message} + {url, username} = Fruitbot.StreampusherApi.user_search(query) + msg = "Datafruit found: #{url}" + {:ok, msg} "!bigup" -> query_stripped = String.replace_prefix(query, "@", "") @@ -191,8 +191,17 @@ defmodule Fruitbot.Commands do :ets.insert(:user_bigups, {query_stripped, count + 1}) end [{user, count}] = :ets.lookup(:user_bigups, query_stripped) - message = ":airhorn: big up #{user} :airhorn: 88888888888888888+++++++++ #{user} has #{count} bigups" - { :ok, message } + msg = ":airhorn: big up #{user} :airhorn: 88888888888888888+++++++++ #{user} has #{count} bigups" + {:ok, msg} + + "!stream" -> + case Fruitbot.StreampusherApi.stream_ping() do + true -> + msg = "The stream is up :arrow_up:" + _ -> + msg = "The stream is down :arrow_down:" + end + {:ok, msg} "!commands" -> # can we pull the list of commands automatically somehow? diff --git a/lib/fruitbot/streampusher_api.ex b/lib/fruitbot/streampusher_api.ex index 0f7957a..8874ab1 100644 --- a/lib/fruitbot/streampusher_api.ex +++ b/lib/fruitbot/streampusher_api.ex @@ -1,4 +1,5 @@ defmodule Fruitbot.StreampusherApi do + @moduledoc """ Functions called by user commands from the Datafruits chat. """ @@ -107,4 +108,17 @@ defmodule Fruitbot.StreampusherApi do image_url = Kernel.get_in(data, ["attributes", "thumb_image_url"]) "Next show is #{title}, hosted by #{host}! Beginning in #{countdown} minutes. Description: #{description}. :link: #{url} #{image_url}" end + + def stream_ping do + case HTTPoison.get!("https://streampusher-relay.club") do + %HTTPoison.Response{status_code: 200, body: body} -> + body + |> Floki.find("td.streamdata") + |> Enum.empty?() + |> Kernel.! + + _ -> + "not now" + end + end end