summaryrefslogtreecommitdiff
path: root/lib/lsg_web
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
parentsse / embedded player (diff)
update
Diffstat (limited to 'lib/lsg_web')
-rw-r--r--lib/lsg_web/controllers/irc_controller.ex51
-rw-r--r--lib/lsg_web/controllers/page_controller.ex11
-rw-r--r--lib/lsg_web/router.ex9
-rw-r--r--lib/lsg_web/templates/irc/index.html.eex29
-rw-r--r--lib/lsg_web/templates/irc/txt.html.eex19
-rw-r--r--lib/lsg_web/templates/irc/txts.html.eex8
-rw-r--r--lib/lsg_web/templates/layout/app.html.eex23
-rw-r--r--lib/lsg_web/templates/page/api.html.eex35
-rw-r--r--lib/lsg_web/templates/page/index.html.eex37
-rw-r--r--lib/lsg_web/templates/page/irc.html.eex19
-rw-r--r--lib/lsg_web/views/irc_view.ex3
11 files changed, 186 insertions, 58 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)
diff --git a/lib/lsg_web/router.ex b/lib/lsg_web/router.ex
index db0e5cd..9373e85 100644
--- a/lib/lsg_web/router.ex
+++ b/lib/lsg_web/router.ex
@@ -14,9 +14,14 @@ defmodule LSGWeb.Router do
end
scope "/", LSGWeb do
- pipe_through :browser # Use the default browser stack
-
+ pipe_through :browser
+ get "/", PageController, :index
get "/embed/widget", PageController, :widget
+ get "/api", PageController, :api
+
+ get "/irc", IrcController, :index
+ get "/irc/txt", IrcController, :txt
+ get "/irc/txt/:name", IrcController, :txt
end
scope "/api", LSGWeb do
diff --git a/lib/lsg_web/templates/irc/index.html.eex b/lib/lsg_web/templates/irc/index.html.eex
new file mode 100644
index 0000000..91873e6
--- /dev/null
+++ b/lib/lsg_web/templates/irc/index.html.eex
@@ -0,0 +1,29 @@
+<h1>bot `115ans</h1>
+
+<p>
+Si vous cherchez l'IRC c'est <a href="https://115ans.net/irc/">par là</a>.
+<br />
+<a href="/irc/stats/">Statistiques</a>.
+</p>
+
+
+<style type="text/css">
+.help-entry h1 {
+ font-size: 18px;
+}
+.help-entry h2 {
+ font-size: 16px;
+}
+</style>
+
+<div class="irchelps">
+ <%= for help <- @commands do %>
+ <div class="help-entry"><%= help |> Earmark.as_html! |> raw() %></div>
+ <% end %>
+</div>
+
+<p>
+<small>
+ source: <a href="https://git.yt/115ans/sys">git.yt/115ans/sys</a>
+</small>
+</p>
diff --git a/lib/lsg_web/templates/irc/txt.html.eex b/lib/lsg_web/templates/irc/txt.html.eex
new file mode 100644
index 0000000..4ffde50
--- /dev/null
+++ b/lib/lsg_web/templates/irc/txt.html.eex
@@ -0,0 +1,19 @@
+<style type="text/css">
+h1 small {
+ font-size: 14px;
+}
+ol li {
+ margin-bottom: 5px
+}
+</style>
+
+<h1>
+ <small><a href="/irc/txt">irc.txt</a>:</small><br/>
+ <%= @name %>.txt</h1>
+
+<ol>
+ <%= for {txt, id} <- Enum.with_index(@data) do %>
+ <li id="<%= @name %>-<%= id %>"><%= txt %></li>
+ <% end %>
+</ol>
+
diff --git a/lib/lsg_web/templates/irc/txts.html.eex b/lib/lsg_web/templates/irc/txts.html.eex
new file mode 100644
index 0000000..7c96ed9
--- /dev/null
+++ b/lib/lsg_web/templates/irc/txts.html.eex
@@ -0,0 +1,8 @@
+<h1>irc.txt</h1>
+
+<ul>
+ <%= for {txt, data} <- @data do %>
+ <li><a href="/irc/txt/<%= txt %>"><%= txt %></a> <i>(<%= Enum.count(data) %>)</i></li>
+ <% end %>
+</ul>
+
diff --git a/lib/lsg_web/templates/layout/app.html.eex b/lib/lsg_web/templates/layout/app.html.eex
index 0d91f12..1c8f900 100644
--- a/lib/lsg_web/templates/layout/app.html.eex
+++ b/lib/lsg_web/templates/layout/app.html.eex
@@ -4,32 +4,15 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
- <meta name="description" content="">
- <meta name="author" content="">
-
- <title>Hello LSG!</title>
- <link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>">
+ <link rel="stylesheet" href="<%= static_path(@conn, "/assets/css/app.css") %>">
</head>
<body>
<div class="container">
- <header class="header">
- <nav role="navigation">
- <ul class="nav nav-pills pull-right">
- <li><a href="http://www.phoenixframework.org/docs">Get Started</a></li>
- </ul>
- </nav>
- <span class="logo"></span>
- </header>
-
- <p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
- <p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
-
<main role="main">
<%= render @view_module, @view_template, assigns %>
</main>
-
- </div> <!-- /container -->
- <script src="<%= static_path(@conn, "/js/app.js") %>"></script>
+ </div>
+ <script src="<%= static_path(@conn, "/assets/js/app.js") %>"></script>
</body>
</html>
diff --git a/lib/lsg_web/templates/page/api.html.eex b/lib/lsg_web/templates/page/api.html.eex
new file mode 100644
index 0000000..03dfa6b
--- /dev/null
+++ b/lib/lsg_web/templates/page/api.html.eex
@@ -0,0 +1,35 @@
+<h1>sys.115ans.net/api</h1>
+
+<h2>Icecast Status</h2>
+
+<h3>GET /api/icecast.json</h3>
+
+<p>
+ Content-Type: <code>application/json</code>
+</p>
+
+<pre><code>
+{
+ "np": String,
+ "genre": null | String,
+ "live": false | true
+}
+</pre></code>
+
+<h3>GET /api/icecast.sse</h3>
+<p>
+ Content-Type: <code>text/event-stream</code>
+</p>
+
+<p>
+ Stream of:
+</p>
+
+ <ul>
+ <li><strong>icecast</strong> events (same format as <code>/api/icecast.json</code>)</li>
+ <li><strong>ping</strong> events (to keep-alive connection. You can safely ignore them)</li>
+ </ul>
+<p>
+ On client connection, the server sends the latest <code>icecast</code> status known.
+</p>
+
diff --git a/lib/lsg_web/templates/page/index.html.eex b/lib/lsg_web/templates/page/index.html.eex
index 0988ea5..98e407c 100644
--- a/lib/lsg_web/templates/page/index.html.eex
+++ b/lib/lsg_web/templates/page/index.html.eex
@@ -1,36 +1 @@
-<div class="jumbotron">
- <h2><%= gettext "Welcome to %{name}!", name: "Phoenix" %></h2>
- <p class="lead">A productive web framework that<br />does not compromise speed and maintainability.</p>
-</div>
-
-<div class="row marketing">
- <div class="col-lg-6">
- <h4>Resources</h4>
- <ul>
- <li>
- <a href="http://phoenixframework.org/docs/overview">Guides</a>
- </li>
- <li>
- <a href="https://hexdocs.pm/phoenix">Docs</a>
- </li>
- <li>
- <a href="https://github.com/phoenixframework/phoenix">Source</a>
- </li>
- </ul>
- </div>
-
- <div class="col-lg-6">
- <h4>Help</h4>
- <ul>
- <li>
- <a href="http://groups.google.com/group/phoenix-talk">Mailing list</a>
- </li>
- <li>
- <a href="http://webchat.freenode.net/?channels=elixir-lang">#elixir-lang on freenode IRC</a>
- </li>
- <li>
- <a href="https://twitter.com/elixirphoenix">@elixirphoenix</a>
- </li>
- </ul>
- </div>
-</div>
+<p>Vous n'avez rien de mieux à faire ? Non ? Allez sur <a href="https://115ans.net">115ans.net</a>, alors.</p>
diff --git a/lib/lsg_web/templates/page/irc.html.eex b/lib/lsg_web/templates/page/irc.html.eex
new file mode 100644
index 0000000..f6598ee
--- /dev/null
+++ b/lib/lsg_web/templates/page/irc.html.eex
@@ -0,0 +1,19 @@
+<h1>bot `115ans</h1>
+
+<p>Si vous cherchez l'IRC c'est <a href="https://115ans.net/irc/">par là</a>.</p>
+
+<style type="text/css">
+.help-entry h1 {
+ font-size: 18px;
+}
+.help-entry h2 {
+ font-size: 16px;
+}
+</style>
+
+<div class="irchelps">
+ <%= for help <- @bot_helps do %>
+ <div class="help-entry"><%= help |> Earmark.as_html! |> raw() %></div>
+ <% end %>
+</div>
+
diff --git a/lib/lsg_web/views/irc_view.ex b/lib/lsg_web/views/irc_view.ex
new file mode 100644
index 0000000..36a9bc4
--- /dev/null
+++ b/lib/lsg_web/views/irc_view.ex
@@ -0,0 +1,3 @@
+defmodule LSGWeb.IrcView do
+ use LSGWeb, :view
+end