summaryrefslogtreecommitdiff
path: root/lib/nola_web/controllers/gpt_controller.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nola_web/controllers/gpt_controller.ex')
-rw-r--r--lib/nola_web/controllers/gpt_controller.ex33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/nola_web/controllers/gpt_controller.ex b/lib/nola_web/controllers/gpt_controller.ex
new file mode 100644
index 0000000..038b235
--- /dev/null
+++ b/lib/nola_web/controllers/gpt_controller.ex
@@ -0,0 +1,33 @@
+defmodule NolaWeb.GptController do
+ use NolaWeb, :controller
+ require Logger
+
+ plug NolaWeb.ContextPlug
+
+ def result(conn, params = %{"id" => result_id}) do
+ case Nola.IRC.GptPlugin.get_result(result_id) do
+ {:ok, result} ->
+ network = Map.get(params, "network")
+ channel = if c = Map.get(params, "chan"), do: NolaWeb.reformat_chan(c)
+ render(conn, "result.html", network: network, channel: channel, result: result)
+ {:error, :not_found} ->
+ conn
+ |> put_status(404)
+ |> text("Page not found")
+ end
+ end
+
+ def prompt(conn, params = %{"id" => prompt_id}) do
+ case Nola.IRC.GptPlugin.get_prompt(prompt_id) do
+ {:ok, prompt} ->
+ network = Map.get(params, "network")
+ channel = if c = Map.get(params, "chan"), do: NolaWeb.reformat_chan(c)
+ render(conn, "prompt.html", network: network, channel: channel, prompt: prompt)
+ {:error, :not_found} ->
+ conn
+ |> put_status(404)
+ |> text("Page not found")
+ end
+ end
+
+end