From ee1f96889c9bd52ddcdd91e6fea342db67cd2500 Mon Sep 17 00:00:00 2001 From: Samar Dhwoj Acharya Date: Sat, 10 Dec 2016 00:45:58 -0600 Subject: [PATCH] Slap responder (#15) * add slap responder * update readme --- README.md | 13 +++++---- config/config.exs | 3 +- lib/ex_mustang/responders/slap.ex | 47 +++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 lib/ex_mustang/responders/slap.ex diff --git a/README.md b/README.md index 7237e78..f7c9e02 100644 --- a/README.md +++ b/README.md @@ -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 - Displays all help commands that match . gmap - Replies with the information from google places/maps. -quote - Displays random quote +quote - Replies with a random quote. +slap - Slaps the user. Format: slap | me ``` ### About Mustang diff --git a/config/config.exs b/config/config.exs index 06de4aa..c2c20ea 100644 --- a/config/config.exs +++ b/config/config.exs @@ -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" diff --git a/lib/ex_mustang/responders/slap.ex b/lib/ex_mustang/responders/slap.ex new file mode 100644 index 0000000..c3343c0 --- /dev/null +++ b/lib/ex_mustang/responders/slap.ex @@ -0,0 +1,47 @@ +defmodule ExMustang.Responders.Slap do + @moduledoc """ + Slap user on slack around a bit with a large trout + + `slap | 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 | 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*<@(?\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