Created
January 11, 2016 08:50
-
-
Save docteurklein/791fdc5921d3ef838e64 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| defmodule Edgar.Brain do | |
| def start_link do | |
| Agent.start_link(fn -> Map.new end, name: __MODULE__) | |
| end | |
| @doc "memorize something" | |
| def memorize(key, info) do | |
| Agent.update(__MODULE__, &Map.put(&1, key, info)) | |
| end | |
| @doc "remember" | |
| def remember(key) do | |
| Agent.get(__MODULE__, &Map.get(&1, key)) | |
| end | |
| @doc "forget" | |
| def forget(key) do | |
| Agent.update(__MODULE__, &Map.pop(&1, key)) | |
| end | |
| end |
This file contains hidden or 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
| defmodule Edgar.Responder.NotNot do | |
| @moduledoc """ | |
| resays what has been said | |
| """ | |
| use Hedwig.Responder | |
| @usage """ | |
| <text> (!!) - resays what has been said | |
| """ | |
| respond ~r/(.*)/i, msg do | |
| case msg.matches[1] do | |
| "!!" -> "" | |
| _ -> | |
| Edgar.Brain.memorize(:lastmsg, msg.matches[1]) | |
| end | |
| end | |
| respond ~r/!!/i, msg do | |
| send msg, Edgar.Brain.remember(:lastmsg) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment