Skip to content

Commit

Permalink
more info for reddit posts
Browse files Browse the repository at this point in the history
  • Loading branch information
adamzaninovich committed Apr 21, 2016
1 parent eeb6290 commit a353d98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion lib/alice/handlers/reddit.ex
Expand Up @@ -11,7 +11,8 @@ defmodule Alice.Handlers.Reddit do
def random_image_from_subreddit(conn) do
conn
|> get_term
|> Readit.random_image_from_sub
|> get_post
|> build_reply
|> reply(conn)
end

Expand All @@ -22,4 +23,18 @@ defmodule Alice.Handlers.Reddit do
|> String.replace(~r/[_\s]+/, "")
|> String.strip
end

defp get_post(name) do
name
|> Sub.new
|> Sub.recent_images
|> Enum.random
end

defp build_reply(post) do
["> *#{post.title} • /r/#{post.subreddit}*",
"> #{post.score} points and #{post.num_comments} comments so far on reddit",
"> #{post.url}"]
|> Enum.join("\n")
end
end
2 changes: 1 addition & 1 deletion mix.exs
Expand Up @@ -3,7 +3,7 @@ defmodule AliceReddit.Mixfile do

def project do
[app: :alice_reddit,
version: "0.0.1",
version: "0.0.2",
elixir: "~> 1.2",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand Down

0 comments on commit a353d98

Please sign in to comment.