summaryrefslogtreecommitdiff
path: root/lib/lsg_web/controllers/irc_controller.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lsg_web/controllers/irc_controller.ex')
-rw-r--r--lib/lsg_web/controllers/irc_controller.ex27
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/lsg_web/controllers/irc_controller.ex b/lib/lsg_web/controllers/irc_controller.ex
index af7fff1..022807d 100644
--- a/lib/lsg_web/controllers/irc_controller.ex
+++ b/lib/lsg_web/controllers/irc_controller.ex
@@ -2,19 +2,35 @@ defmodule LSGWeb.IrcController do
use LSGWeb, :controller
def index(conn, _) do
- doc = LSG.IRC.TxtHandler.irc_doc()
commands = for mod <- (Application.get_env(:lsg, :irc)[:plugins] ++ Application.get_env(:lsg, :irc)[:handlers]) do
- mod.irc_doc()
+ identifier = Module.split(mod) |> List.last |> String.replace("Plugin", "") |> Macro.underscore
+ {identifier, mod.irc_doc()}
end
- |> Enum.reject(fn(i) -> i == nil end)
+ |> Enum.reject(fn({_, i}) -> i == nil end)
render conn, "index.html", commands: commands
end
- def txt(conn, %{"name" => name}), do: do_txt(conn, name)
+ def txt(conn, %{"name" => name}) do
+ case String.split(name, ".", parts: 2) do
+ [name, "txt"] ->
+ data = data()
+ if Map.has_key?(data, name) do
+ lines = Enum.join(data[name], "\n")
+ text(conn, lines)
+ else
+ conn
+ |> put_status(404)
+ |> text("Not found")
+ end
+ _ ->
+ do_txt(conn, name)
+ end
+ end
def txt(conn, _), do: do_txt(conn, nil)
+
defp do_txt(conn, nil) do
- doc = LSG.IRC.TxtHandler.irc_doc()
+ doc = LSG.IRC.TxtPlugin.irc_doc()
data = data()
lines = Enum.reduce(data, 0, fn({_, lines}, acc) -> acc + Enum.count(lines) end)
render conn, "txts.html", data: data, doc: doc, files: Enum.count(data), lines: lines
@@ -27,6 +43,7 @@ defmodule LSGWeb.IrcController do
else
conn
|> put_status(404)
+ |> text("Not found")
end
end