diff options
Diffstat (limited to 'lib/command/command.ex')
| -rw-r--r-- | lib/command/command.ex | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/command/command.ex b/lib/command/command.ex new file mode 100644 index 0000000..f83f02b --- /dev/null +++ b/lib/command/command.ex @@ -0,0 +1,57 @@ +alias Phoenix.PubSub +alias Nostrum.Api + +defmodule Thulani.Command do + use GenServer + use Thulani.Command.Util + require Logger + + def start_link(arg) do + GenServer.start_link(__MODULE__, arg) + end + + @impl true + def init(_) do + PubSub.subscribe(:thulani_pubsub, "cmd") + {:ok, %{}} + end + + @impl true + def handle_info(Util.command("meme", "", msg), state) do + {:noreply, state} + end + + @impl true + def handle_info(Util.command("meme", rest, msg), state) do + case rest do + "" -> Thulani.Meme + end + + {:noreply, state} + end + + def handle_info(Util.command("http", rest, msg), state) do + end + + def handle_info(Util.command("roll", rest, msg), state) do + Logger.info("hi") + + case rest do + " " <> expr -> + case Thulani.Calc.eval(expr) do + {:ok, val} -> Api.create_message!(msg.channel_id, "#{val}") + {:error, err} -> Logger.error("BAD: #{err}") + end + + _ -> + Logger.error("nothing else in the message") + end + + {:noreply, state} + end + + def handle_info(_msg, state) do + Logger.debug("unhandled message") + {:noreply, state} + end +end |
