summaryrefslogtreecommitdiff
path: root/lib/lsg_web/controllers
diff options
context:
space:
mode:
authorhref <href@random.sh>2018-02-10 21:40:22 +0100
committerhref <href@random.sh>2018-02-10 21:40:22 +0100
commit935a36eecc0faea60236101e11bc9f7cf1872686 (patch)
treeb7b4358dee2eb3fc60681852f62c750ae8c05cb9 /lib/lsg_web/controllers
parentsse / embedded player (diff)
update
Diffstat (limited to 'lib/lsg_web/controllers')
-rw-r--r--lib/lsg_web/controllers/irc_controller.ex51
-rw-r--r--lib/lsg_web/controllers/page_controller.ex11
2 files changed, 62 insertions, 0 deletions
diff --git a/lib/lsg_web/controllers/irc_controller.ex b/lib/lsg_web/controllers/irc_controller.ex
new file mode 100644
index 0000000..a5a68f7
--- /dev/null
+++ b/lib/lsg_web/controllers/irc_controller.ex
@@ -0,0 +1,51 @@
+defmodule LSGWeb.IrcController do
+ use LSGWeb, :controller
+
+ def index(conn, _) do
+ commands = for mod <- Application.get_env(:lsg, :irc)[:handlers] do
+ mod.irc_doc()
+ end
+ render conn, "index.html", commands: commands
+ end
+
+ def txt(conn, %{"name" => name}), do: do_txt(conn, name)
+ def txt(conn, _), do: do_txt(conn, nil)
+
+ defp do_txt(conn, nil) do
+ render conn, "txts.html", data: data()
+ end
+
+ defp do_txt(conn, txt) do
+ data = data()
+ if Map.has_key?(data, txt) do
+ render(conn, "txt.html", name: txt, data: data[txt])
+ else
+ conn
+ |> put_status(404)
+ end
+ end
+
+ defp data() do
+ dir = Application.get_env(:lsg, LSG.IRC.TxtHandler)[:directory]
+ Path.wildcard(dir <> "/*.txt")
+ |> Enum.reduce(%{}, fn(path, m) ->
+ path = String.split(path, "/")
+ file = List.last(path)
+ [key, "txt"] = String.split(file, ".", parts: 2)
+ data = dir <> file
+ |> File.read!
+ |> String.split("\n")
+ |> Enum.reject(fn(line) ->
+ cond do
+ line == "" -> true
+ !line -> true
+ true -> false
+ end
+ end)
+ Map.put(m, key, data)
+ end)
+ |> Enum.sort
+ |> Enum.into(Map.new)
+ end
+
+end
diff --git a/lib/lsg_web/controllers/page_controller.ex b/lib/lsg_web/controllers/page_controller.ex
index 3d4e444..b356b9c 100644
--- a/lib/lsg_web/controllers/page_controller.ex
+++ b/lib/lsg_web/controllers/page_controller.ex
@@ -5,6 +5,17 @@ defmodule LSGWeb.PageController do
render conn, "index.html"
end
+ def api(conn, _params) do
+ render conn, "api.html"
+ end
+
+ def irc(conn, _) do
+ bot_helps = for mod <- Application.get_env(:lsg, :irc)[:handlers] do
+ mod.irc_doc()
+ end
+ render conn, "irc.html", bot_helps: bot_helps
+ end
+
def icecast(conn, _params) do
conn
|> json(LSG.IcecastAgent.get)