Skip to content
Open
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
19 changes: 14 additions & 5 deletions lib/fruitbot/commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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, "@", "")
Expand All @@ -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?
Expand Down
14 changes: 14 additions & 0 deletions lib/fruitbot/streampusher_api.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Fruitbot.StreampusherApi do

@moduledoc """
Functions called by user commands from the Datafruits chat.
"""
Expand Down Expand Up @@ -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