summaryrefslogblamecommitdiff
path: root/lib/lsg_web/controllers/gpt_controller.ex
blob: acf9b272b86a6e7be24177a94fc9ac73d9d9674d (plain) (tree)
































                                                                                       
defmodule LSGWeb.GptController do
  use LSGWeb, :controller
  require Logger

  plug LSGWeb.ContextPlug

  def result(conn, params = %{"id" => result_id}) do
    case LSG.IRC.GptPlugin.get_result(result_id) do
      {:ok, result} ->
        network = Map.get(params, "network")
        channel = if c = Map.get(params, "chan"), do: LSGWeb.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 LSG.IRC.GptPlugin.get_prompt(prompt_id) do
      {:ok, prompt} ->
        network = Map.get(params, "network")
        channel = if c = Map.get(params, "chan"), do: LSGWeb.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