-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* do a random insult and add default ua * update config * update readme and add insult me
- Loading branch information
Showing
7 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule ExMustang.Responders.RandomInsult do | ||
@moduledoc """ | ||
Sends random insult to a user | ||
""" | ||
use Hedwig.Responder | ||
import ExMustang.Utils, only: [useragent: 0] | ||
|
||
@base_url "http://www.randominsults.net/" | ||
|
||
@usage """ | ||
insult me|<username> - insults given username with random insults | ||
""" | ||
|
||
hear ~r/^insult\s*me/i, msg do | ||
emote msg, insult(msg.user.id) | ||
end | ||
|
||
hear ~r/^insult\s?+<@(?<user>\w+)>.*$/i, msg do | ||
emote msg, insult(msg.matches["user"]) | ||
end | ||
|
||
defp insult(user) do | ||
case HTTPoison.get(@base_url, [useragent]) do | ||
{:ok, %HTTPoison.Response{status_code: 200, body: body}} -> | ||
parse_body(body, user) | ||
_ -> | ||
"I can not insult #{user} right now" | ||
end | ||
end | ||
|
||
defp parse_body(body, user) do | ||
case Floki.find(body, "i") do | ||
[{"i", _, [msg]} | _] -> | ||
"<@#{user}> : #{msg}" | ||
_ -> | ||
"I am unable to parse insult data. Please let the author know his shit is broken!" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters