Skip to content

Commit

Permalink
Slap responder (#15)
Browse files Browse the repository at this point in the history
* add slap responder

* update readme
  • Loading branch information
techgaun authored Dec 10, 2016
1 parent d8a7d6e commit ee1f968
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,20 @@ The standup reminder reminds us when its standup time. Our nature is that we eit

### Responders

Currently, there are two responders:
Currently, there are three responders and these should ideally work with any Hedwig adapters:

One is `ExMustang.Responders.GMap` which gives you search result for your search queries.
Other is `ExMustang.Responders.Quote` which gives you random quote.
- `ExMustang.Responders.GMap` - gives you google maps search result for your search queries.
- `ExMustang.Responders.Quote` - gives you random funny quote
- `ExMustang.Responders.Slap` - slaps another user

For Google Maps search, you have to set `GOOGLE_API_KEY` which has access to call google places api.

```shell
mustang help - Displays help message
mustang help - Displays all of the help commands that mustang knows about.
mustang help <query> - Displays all help commands that match <query>.
gmap <search_term> - Replies with the information from google places/maps.
quote - Displays random quote
quote - Replies with a random quote.
slap - Slaps the user. Format: slap <username> | me
```

### About Mustang
Expand Down
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ config :ex_mustang, ExMustang.Robot,
responders: [
{Hedwig.Responders.Help, []},
{ExMustang.Responders.GMap, []},
{ExMustang.Responders.Quote, []}
{ExMustang.Responders.Quote, []},
{ExMustang.Responders.Slap, []}
]

config :quantum, timezone: System.get_env("SYSTEM_TIME") || "America/Chicago"
Expand Down
47 changes: 47 additions & 0 deletions lib/ex_mustang/responders/slap.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule ExMustang.Responders.Slap do
@moduledoc """
Slap user on slack around a bit with a large trout
`slap <username> | me
"""
use Hedwig.Responder

@emoticon ":fish:"
# banters copied from https://github.com/spfr/slapbot/blob/master/helpers.js#L2-L19
@banters [
"Ouch! That must hurt!",
"That should teach you a lesson!",
"Ha ha ha ha!",
"Damn milenial!",
"Take that, you fool!",
"Feel the pain!",
"You probably still use Notepad++...",
"Your pull request is horrible.",
"Your JIRA ticket sucks.",
"Your Trello card is lame. Do you even Markdown bro?",
"Ooooh snap!",
"Get slapped, son!",
"Your bloody hipster!",
"Now go back to work!",
"Go buy us some Ice Cream!",
"Why don’t you go back to your desk and tail call yourself?",
"Are you a priest? Your code is running on pure faith and no logic…",
"Your code, just like C, has no class!"
]

@usage """
slap - Slaps the user. Format: slap <username> | me
"""
hear ~r/^slap\s*me/i, msg do
emote msg, build_msg(msg.user.id)
emote msg, random(@banters)
end
hear ~r/^slap\s*<@(?<user>\w+)>.*$/i, msg do
emote msg, build_msg(msg.matches["user"])
emote msg, random(@banters)
end

defp build_msg(user) do
"slaps <@#{user}> around a bit with a large trout #{@emoticon}"
end
end

0 comments on commit ee1f968

Please sign in to comment.