Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send a message to discord when stream is down #18

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/fruitbot/stream_monitor.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule Fruitbot.StreamMonitor do
@url "https://streampusher-relay.com/datafruits.mp3"
use HTTPoison.Base

def start_link(url) do
HTTPoison.start_link()
{:ok, %HTTPoison.Config{}} = HTTPoison.Config.default(%{})
interval = 60_000
spawn_link(fn -> loop(url, interval) end)
end

defp loop(url, interval) do
:timer.sleep(interval)
case HTTPoison.get(url) do
{:ok, %HTTPoison.Response{status_code: 200}} ->
IO.puts("Success: #{url}")
loop(url, interval)
{:ok, %HTTPoison.Response{status_code: status_code}} ->
IO.puts("Error (Status #{status_code}): #{url}")
# send to which discord channel ???
loop(url, interval)
{:error, reason} ->
IO.puts("Error: #{reason}")
loop(url, interval)
end
end
end
3 changes: 2 additions & 1 deletion lib/fruitbot/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ defmodule Fruitbot.Supervisor do
children = [
Plug.Cowboy.child_spec(scheme: :http, plug: Fruitbot.Router, options: [port: get_port()]),
{Fruitbot.Worker, uri: System.get_env("CHAT_URL")},
{Fruitbot.NostrumConsumer, name: Fruitbot.NostrumConsumer}
{Fruitbot.NostrumConsumer, name: Fruitbot.NostrumConsumer},
{Fruitbot.StreamMonitor, name: Fruitbot.StreamMonitor}
]

Supervisor.init(children, strategy: :one_for_one)
Expand Down