defmodule LSG.IRC.CalcHandler do @moduledoc """ # calc * **!calc ``**: évalue l'expression mathématique ``. """ def irc_doc, do: @moduledoc def start_link(client) do GenServer.start_link(__MODULE__, [client]) end def init([client]) do ExIRC.Client.add_handler client, self {:ok, client} end def handle_info({:received, "!calc "<>expr, %ExIRC.SenderInfo{nick: nick}, chan}, client) do IO.inspect "HAZ CALC " <>inspect(expr) result = try do case Abacus.eval(expr) do {:ok, result} -> result error -> inspect(error) end rescue error -> "#{error.message}" end ExIRC.Client.msg(client, :privmsg, chan, "#{nick}: #{expr} = #{result}") {:noreply, client} end def handle_info(msg, client) do {:noreply, client} end end