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
194 changes: 17 additions & 177 deletions lib/fruitbot/commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,153 +37,22 @@ defmodule Fruitbot.Commands do
{:ok, msg}

"!advice" ->
:random.seed(:erlang.now)
advices = [
"Don't live like me Brendon. Don't get a tattoo of a cheese cow.",
"Next thing you know, you're in the circus, touring, making good money.",
"I've got trademark products all over my body because I was drunk one night. Don't live like me.",
"Your honor might I suggest a spanking on his tush tush?",
"Quarter for the bus, quarter for the bus. The end. Hey Brendon, the end.",
"What are you looking at?",
"It's Spaghetti Time!",
"Next time that thing comes near me, I'm gonna eat it. I'm serious!",
]
msg = Enum.random(advices)
{:ok, msg}

"!sorry" ->
# shell to mplayer
System.cmd("play", ["./sfx/onion_salad_dressing.mp3"])

msg =
"Must have been the onion salad dressing. Right, Brendon? :sorrymusthavebeentheonionsaladdressing:"

{:ok, msg}

"!thisisamazing" ->
# shell to mplayer
System.cmd("play", ["./sfx/thisisamazing.mp3"])
msg = "It's just a website"
{:ok, msg}

"!gohackyourself" ->
# shell to mplayer
System.cmd("play", ["./sfx/go_hack_yourself.wav"])
msg = "go hack yourself"
{:ok, msg}

"!pewpew" ->
# shell to mplayer
System.cmd("play", ["./sfx/PEWPEW.wav"])
msg = "pewpew"
{:ok, msg}

"!bass" ->
# shell to mplayer
System.cmd("play", ["./sfx/bass.mp3"])
msg = "BASS"
{:ok, msg}

"!scream" ->
# shell to mplayer
System.cmd("play", ["./sfx/somebody_scream.wav"])
msg = "c'mon ethel let's get outta here"
{:ok, msg}

"!internet" ->
# shell to mplayer
System.cmd("play", ["./sfx/internet.wav"])
msg = "https://www.youtube.com/watch?v=ip34OUo3IS0"
{:ok, msg}

"!penith" ->
# shell to mplayer
System.cmd("play", ["./sfx/penith.wav"])
msg = ":dizzy:"
{:ok, msg}

"!ballin" ->
# shell to mplayer
System.cmd("play", ["./sfx/ballin.wav"])
msg = ":lain_dad:"
{:ok, msg}

"!duck" ->
# shell to mplayer
System.cmd("play", ["./sfx/duck_rotate.wav"])
msg = ":duckle:"
{:ok, msg}

"!fries" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/greasy_fries.ogg"])
msg = ":greasyhotdogs:"
{:ok, msg}

"!hotdogs" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/greasy_hotd.ogg"])
msg = ":greasyhotdogs:"
{:ok, msg}

"!bug" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/bug.mp3"])
msg = "FIX THAT BUG"
{:ok, msg}

"!gj" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/gj.mp3"])
msg = ":goodbeverage:"
{:ok, msg}

"!false" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/false.mp3"])
msg = "it never happened"
{:ok, msg}
{:ok, model} = Markov.load("./coach_model", sanitize_tokens: true, store_log: [:train])
:ok = Markov.configure(model, shift_probabilities: true)

"!totalfabrication" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/total_fabrication.mp3"])
msg = "it's a total fabrication"
{:ok, msg}

"!boost" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/boostyrdesktoplifestyle.mp3"])
msg = ":marty:"
{:ok, msg}

"!computers" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/computers.mp3"])
msg = "I hope we all learned about computers"
{:ok, msg}

"!done" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/done.mp3"])
msg = "and yr done"
{:ok, msg}

"!onionrings" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/greasy_onion_rings.ogg"])
msg = ":greasyhotdogs:"
{:ok, msg}

"!awake" ->
# shell to mplayer
System.cmd("mplayer", ["./sfx/alive_alert_awake.mp3"])
msg = ":alive_alert_awake:"
{:ok, msg}
{:ok, msg} = Markov.generate_text(model)
Markov.unload(model)
{:ok, msg}

"!next" ->
next_show = Fruitbot.StreampusherApi.next_show()
{:ok, next_show}

"!np" ->
current_show = Fruitbot.StreampusherApi.current_show()
# return current show if exists or current archive playing
{:ok, current_show}

"!latest" ->
# return latest archive
latest = Fruitbot.StreampusherApi.latest_archive()
Expand All @@ -197,12 +66,12 @@ defmodule Fruitbot.Commands do
result = Fruitbot.StreampusherApi.tag_search(query)
{:ok, result}

"!datafruiter" ->
_ when command in ["!datafruiter", "!datafruit"] ->
{ url, username } = Fruitbot.StreampusherApi.user_search(query)
message = "Datafruit found: #{url}"
{:ok, message}

"!bigup" ->
_ when command in ["!bigup", "!bigups"] ->
query_stripped = String.replace_prefix(query, "@", "")
lookup = :ets.lookup(:user_bigups, query_stripped)
case lookup do
Expand All @@ -215,10 +84,6 @@ defmodule Fruitbot.Commands do
message = ":airhorn: big up #{user} :airhorn: 88888888888888888+++++++++ #{user} has #{count} bigups"
{ :ok, message }

# wait this is already a command...
# "!hotdogs" ->
# { :ok, message }

"!hack" ->
message = "hack the planet https://github.com/datafruits"
{ :ok, message }
Expand All @@ -227,43 +92,17 @@ defmodule Fruitbot.Commands do
message = "hack the planet https://github.com/datafruits"
{ :ok, message }

"!sfx" ->
# can we pull the list of sfx automatically somehow?
list = """
!sorry
!thisisamazing
!gohackyourself
!pewpew
!bass
!scream
!internet
!penith
!ballin
!duck
!fries
!hotdogs
!onionrings
!gj
!bug
!computers
!done
!false
!totalfabrication
!boost
"""

{:ok, list}

"!hydrate" ->
message = "hey everyone make sure youre drinking enough water and taking time for yourselves and eating some nutritious food and taking breaks from social media
coz i care abt you and i want you to be happy n healthy"
{ :ok, message }

"!commands" ->
# can we pull the list of commands automatically somehow?
list = """
!vr
!donate
!advice
!sorry
!thisisamazing
!gohackyourself
!next
!wiki
!tag
Expand All @@ -275,6 +114,7 @@ defmodule Fruitbot.Commands do

_ ->
IO.puts("unhandled command: #{command}")

# Elixir prefers two-element tuples esp. for :ok and :error
{:error, :bad_command}
end
Expand Down
37 changes: 37 additions & 0 deletions lib/fruitbot/streampusher_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,43 @@ defmodule Fruitbot.StreampusherApi do
end
end

@spec current_show() :: String.t()
def current_show do
response =
case HTTPoison.get!("https://datafruits.streampusher.com/scheduled_shows/current.json") do
%HTTPoison.Response{status_code: 200, body: body} ->
Jason.decode!(body)

# not sure it seems the API doesn't return a 404 when search result not found, just an empty list
%HTTPoison.Response{status_code: 404} ->
"Not found"

_ ->
"Whoops must have eaten a bad fruit"

# %HTTPoison.Error{reason: reason} ->
# IO.inspect(reason)
end

data = response["data"]
start = Kernel.get_in(data, ["attributes", "start"])
{:ok, now} = DateTime.now("Etc/UTC")
{:ok, then, 0} = DateTime.from_iso8601(start)
IO.puts now
IO.puts then
countdown = DateTime.diff(then, now) |> Kernel./(60) |> Kernel.trunc()
IO.puts countdown

title = Kernel.get_in(data, ["attributes", "title"])
host = Kernel.get_in(data, ["attributes", "hosted_by"])
description = Kernel.get_in(data, ["attributes", "description"])
slug = Kernel.get_in(data, ["attributes", "slug"])
show_series_slug = Kernel.get_in(data, ["attributes", "show_series_slug"])
url = "https://datafruits.fm/shows/#{show_series_slug}/episodes/#{slug}"
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

@spec next_show() :: String.t()
def next_show do
response =
Expand Down
9 changes: 9 additions & 0 deletions lib/fruitbot/worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,21 @@ defmodule Fruitbot.Worker do

if Map.has_key?(message, "body") do
IO.puts("message body: #{message["body"]}")
IO.puts("message role: #{message["role"]}")

# save message for markov chain thingies

case Fruitbot.Commands.handle_message(message["body"]) do
{:ok, message} ->
send_message(socket, message)

{:error, :bad_command} ->
# don't rain coach on himself
if(message["role"] != "bot") do
{:ok, model} = Markov.load("./coach_model", sanitize_tokens: true, store_log: [:train])
:ok = Markov.train(model, message["body"])
Markov.unload(model)
end
# noop
IO.puts("Coach doesn't understand this command. Try another!")
:ignore
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ defmodule Fruitbot.MixProject do
{:httpoison, "~> 2.0"},
{:tmi, git: "https://github.com/mcfiredrill/tmi.ex" },
{:castore, "~> 1.0"},
{:persistent_ets, "~> 0.1.0"}
{:persistent_ets, "~> 0.1.0"},
{:markov, "~> 4.0"}
]
end
end
Loading