Update modules to be more egonomic, add command macro

Modules are now defined using on_{msg,channel_msg,join,part,kick}.
Additionally, commands can be defined using a convenient macro.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-06-13 15:20:00 -04:00
parent afd8f8c667
commit ed22d1bf0f
3 changed files with 101 additions and 55 deletions

View File

@@ -17,20 +17,15 @@ defmodule Omnibot.Contrib.Fortune do
"Godly Luck",
]
## Client API
def privmsg(module, channel, nick, line) do
GenServer.cast(module, {:privmsg, {channel, nick, line}})
command "!fortune", [to] do
fortune = Enum.random(@fortunes)
reply = "#{to}: #{fortune}"
Irc.send_to(channel, reply)
end
## Server callbacks
@impl true
def on_channel_msg(channel, nick, line) do
if line == "!fortune" do
fortune = Enum.random(@fortunes)
reply = "#{nick}: #{fortune}"
Irc.send_to(channel, reply)
end
command "!fortune" do
fortune = Enum.random(@fortunes)
reply = "#{nick}: #{fortune}"
Irc.send_to(channel, reply)
end
end