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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user