diff options
author | href <href@random.sh> | 2020-07-07 21:39:10 +0200 |
---|---|---|
committer | href <href@random.sh> | 2020-07-07 21:39:51 +0200 |
commit | d6ee134a5957e299c3ad59011df320b3c41e6e61 (patch) | |
tree | 29567e6635466f8a3415a935b3cc8a777019f5bc /lib/lsg_web/controllers/irc_controller.ex | |
parent | bleh (diff) |
pouet
Diffstat (limited to 'lib/lsg_web/controllers/irc_controller.ex')
-rw-r--r-- | lib/lsg_web/controllers/irc_controller.ex | 27 |
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 022807d..e0bf24d 100644 --- a/lib/lsg_web/controllers/irc_controller.ex +++ b/lib/lsg_web/controllers/irc_controller.ex @@ -1,13 +1,21 @@ defmodule LSGWeb.IrcController do use LSGWeb, :controller - def index(conn, _) do - commands = for mod <- (Application.get_env(:lsg, :irc)[:plugins] ++ Application.get_env(:lsg, :irc)[:handlers]) do + plug LSGWeb.ContextPlug + + def index(conn, params) do + network = Map.get(params, "network") + channel = if c = Map.get(params, "channel"), do: LSGWeb.reformat_chan(c) + commands = for mod <- ([IRC.Account.AccountPlugin] ++ Application.get_env(:lsg, :irc)[:plugins] ++ Application.get_env(:lsg, :irc)[:handlers]) do identifier = Module.split(mod) |> List.last |> String.replace("Plugin", "") |> Macro.underscore {identifier, mod.irc_doc()} end |> Enum.reject(fn({_, i}) -> i == nil end) - render conn, "index.html", commands: commands + members = cond do + network -> IRC.Membership.expanded_members_or_friends(conn.assigns.account, network, channel) + true -> IRC.Membership.of_account(conn.assigns.account) + end + render conn, "index.html", network: network, commands: commands, channel: channel, members: members end def txt(conn, %{"name" => name}) do @@ -33,13 +41,22 @@ defmodule LSGWeb.IrcController do 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 + conn + |> assign(:title, "txt") + |> render("txts.html", data: data, doc: doc, files: Enum.count(data), lines: lines) end defp do_txt(conn, txt) do data = data() + base_url = cond do + conn.assigns[:chan] -> "/#{conn.assigns.network}/#{LSGWeb.format_chan(conn.assigns.chan)}" + true -> "/-" + end if Map.has_key?(data, txt) do - render(conn, "txt.html", name: txt, data: data[txt], doc: nil) + conn + |> assign(:breadcrumbs, [{"txt", "#{base_url}/txt"}]) + |> assign(:title, "#{txt}.txt") + |> render("txt.html", name: txt, data: data[txt], doc: nil) else conn |> put_status(404) |