Add Omnibot.Module
Modules can easily be defined with `use Omnibot.Module`. Omnibot.Contrib.Fortune has been updated to use this. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
defmodule Omnibot.Contrib.Fortune do
|
||||
use GenServer
|
||||
alias Omnibot.Irc
|
||||
require Logger
|
||||
use Omnibot.Module
|
||||
|
||||
@fortunes [
|
||||
"Reply hazy, try again",
|
||||
@@ -21,10 +19,6 @@ defmodule Omnibot.Contrib.Fortune do
|
||||
|
||||
## Client API
|
||||
|
||||
def start_link(opts) do
|
||||
GenServer.start_link(__MODULE__, opts[:cfg], opts)
|
||||
end
|
||||
|
||||
def privmsg(module, channel, nick, line) do
|
||||
GenServer.cast(module, {:privmsg, {channel, nick, line}})
|
||||
end
|
||||
@@ -32,26 +26,11 @@ defmodule Omnibot.Contrib.Fortune do
|
||||
## Server callbacks
|
||||
|
||||
@impl true
|
||||
def init(cfg) do
|
||||
#Logger.debug("Starting fortune module")
|
||||
#IO.inspect(self())
|
||||
{:ok, cfg}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_call(:unload, _from, cfg) do
|
||||
Logger.info("Unloading")
|
||||
{:reply, :ok, cfg}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_cast({:privmsg, {channel, nick, line}}, cfg) do
|
||||
if IO.inspect(line) == "!fortune" do
|
||||
def on_channel_msg(channel, nick, line) do
|
||||
if line == "!fortune" do
|
||||
fortune = Enum.random(@fortunes)
|
||||
reply = "#{nick}: #{fortune}"
|
||||
Irc.send_to(Irc, channel, reply)
|
||||
Irc.send_to(channel, reply)
|
||||
end
|
||||
|
||||
{:noreply, cfg}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user