diff --git a/config/config.exs b/config/config.exs index 9a3633e..8a1faa6 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,89 +1,58 @@ # This file is responsible for configuring your application # and its dependencies with the aid of the Mix.Config module. # # This configuration file is loaded before any dependency and # is restricted to this project. use Mix.Config config :logger, level: :debug config :logger, :console, format: "$date $time [$level$levelpad] $metadata$message\n", metadata: :all +config :phoenix, :json_library, Jason + # General application configuration config :lsg, namespace: LSG config :lsg, :data_path, "priv" -config :lsg, :icecast_poll_interval, 600_000 +config :lsg, :irc, + name: "ircbot" config :ex_aws, region: "us-east-1", host: "s3.wasabisys.com", s3: [ host: "s3.wasabisys.com", region: "us-east-1", scheme: "https://" ] # Configures the endpoint config :lsg, LSGWeb.Endpoint, url: [host: "localhost"], secret_key_base: "cAFb7x2p/D7PdV8/C6Os18uygoD0FVQh3efNEFc5+5L529q3dofZtZye/BG12MRZ", render_errors: [view: LSGWeb.ErrorView, accepts: ~w(html json)], server: true, + live_view: [signing_salt: "CHANGE_ME_FFS"], pubsub: [name: LSG.PubSub, adapter: Phoenix.PubSub.PG2] config :mime, :types, %{"text/event-stream" => ["sse"]} -# THIS IS NOT USED ANYMORE! -# XXX: Make sure it is not used anymore and remove.. -config :lsg, :irc, - name: "irc bot", - handlers: [ - LSG.IRC.AdminHandler, - #LSG.IRC.BroadcastHandler, - #LSG.IRC.NpHandler, - ], - plugins: [ - LSG.IRC.BasePlugin, - LSG.IRC.TxtPlugin, - LSG.IRC.CalcPlugin, - LSG.IRC.DicePlugin, - LSG.IRC.YouTubePlugin, - LSG.IRC.WikipediaPlugin, - LSG.IRC.KickRoulettePlugin, - LSG.IRC.AlcoolismePlugin, - LSG.IRC.QuatreCentVingtPlugin, - LSG.IRC.LastFmPlugin, - LSG.IRC.LinkPlugin, - LSG.IRC.OutlinePlugin, - LSG.IRC.StocksPlugin - ] - #admins: [ - # # Format is {nick, user, host}. :_ for any value. - #] - #irc: [ - # host: "irc.", - # port: 6667, - # nick: "`115ans", - # user: "115ans", - # name: "https://sys.115ans.net/irc" - #] - config :lsg, LSG.IRC.LastFmHandler, api_key: "x", api_secret: "x" config :lsg, LSG.IRC.YouTubeHandler, api_key: "x", invidious: "yewtu.be" config :mnesia, dir: '.mnesia/#{Mix.env}/#{node()}' # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env}.exs" diff --git a/lib/lsg_web/live/chat_live.ex b/lib/lsg_web/live/chat_live.ex index a2b4c13..d736d72 100644 --- a/lib/lsg_web/live/chat_live.ex +++ b/lib/lsg_web/live/chat_live.ex @@ -1,101 +1,97 @@ defmodule LSGWeb.ChatLive do use Phoenix.LiveView use Phoenix.HTML require Logger def mount(%{"network" => network, "chan" => chan}, %{"account" => account_id}, socket) do chan = LSGWeb.reformat_chan(chan) connection = IRC.Connection.get_network(network, chan) account = IRC.Account.get(account_id) membership = IRC.Membership.of_account(IRC.Account.get("DRgpD4fLf8PDJMLp8Dtb")) if account && connection && Enum.member?(membership, {connection.network, chan}) do {:ok, _} = Registry.register(IRC.PubSub, "#{connection.network}:events", plugin: __MODULE__) for t <- ["messages", "triggers", "outputs", "events"] do {:ok, _} = Registry.register(IRC.PubSub, "#{connection.network}/#{chan}:#{t}", plugin: __MODULE__) end IRC.PuppetConnection.start(account, connection) users = IRC.UserTrack.channel(connection.network, chan) |> Enum.map(fn(tuple) -> IRC.UserTrack.User.from_tuple(tuple) end) |> Enum.reduce(Map.new, fn(user = %{id: id}, acc) -> Map.put(acc, id, user) end) + {backlog, _} = LSG.IRC.BufferPlugin.select_buffer(connection.network, chan) + socket = socket |> assign(:connection_id, connection.id) |> assign(:network, connection.network) |> assign(:chan, chan) |> assign(:title, "live") |> assign(:channel, chan) |> assign(:account_id, account.id) - |> assign(:backlog, []) + |> assign(:backlog, Enum.reverse(backlog)) |> assign(:users, users) |> assign(:counter, 0) {:ok, socket} else {:ok, redirect(socket, to: "/")} end end def handle_event("send", %{"message" => %{"text" => text}}, socket) do account = IRC.Account.get(socket.assigns.account_id) IRC.send_message_as(account, socket.assigns.network, socket.assigns.channel, text, true) {:noreply, assign(socket, :counter, socket.assigns.counter + 1)} end def handle_info({:irc, :event, event = %{type: :join, user_id: id}}, socket) do if user = IRC.UserTrack.lookup(id) do - IO.puts("JOIN USER JOIN USER JOIN USER") - socket = socket |> assign(:users, Map.put(socket.assigns.users, id, user)) |> assign(:backlog, socket.assigns.backlog ++ [event]) - - IO.inspect(socket.assigns.users) - {:noreply, socket} else - IO.puts("\n\n\n?!\n\n\n?!\n\n\n\n") {:noreply, socket} end end def handle_info({:irc, :event, event = %{type: :nick, user_id: id, nick: nick}}, socket) do socket = socket |> assign(:users, update_in(socket.assigns.users, [id, :nick], nick)) |> assign(:backlog, socket.assigns.backlog ++ [event]) {:noreply, socket} end def handle_info({:irc, :event, event = %{type: :quit, user_id: id}}, socket) do socket = socket |> assign(:users, Map.delete(socket.assigns.users, id)) |> assign(:backlog, socket.assigns.backlog ++ [event]) {:noreply, socket} end def handle_info({:irc, :event, event = %{type: :part, user_id: id}}, socket) do socket = socket |> assign(:users, Map.delete(socket.assigns.users, id)) |> assign(:backlog, socket.assigns.backlog ++ [event]) {:noreply, socket} end def handle_info({:irc, :trigger, _, message}, socket) do handle_info({:irc, nil, message}, socket) end def handle_info({:irc, :text, message}, socket) do socket = socket |> assign(:backlog, socket.assigns.backlog ++ [message]) {:noreply, socket} end def handle_info(info, socket) do Logger.debug("Unhandled info: #{inspect info}") {:noreply, socket} end end diff --git a/lib/lsg_web/live/chat_live.html.heex b/lib/lsg_web/live/chat_live.html.heex index 01d8b3a..717be4f 100644 --- a/lib/lsg_web/live/chat_live.html.heex +++ b/lib/lsg_web/live/chat_live.html.heex @@ -1,96 +1,94 @@ <div class="chat" data-turbo="false"> <div class="py-4 px-4 bg-gradient-to-b from-black to-gray-900"> <div class="grid grid-cols-2"> <h1 class="text-gray-50 tracking-tight font-extrabold text-xl"> <%= @network %> <span class="font-bold"><%= @chan %></span> </h1> <div class="text-right"> <a href="/" class="text-gray-400"><%= @account_id %></a> </div> </div> </div> <div class="body"> <div class="log"> - <%= if Enum.empty?(@backlog) do %> <p class="disconnected text-center text-6xl tracking-tight font-extrabold text-red-800 w-full my-24 mx-auto overflow-y-auto"> - Disconnected + Disconnected <span class="text-mono">:'(</span> </p> <p class="phx-errored text-center text-6xl tracking-tight font-extrabold text-red-800 w-full my-24 mx-auto overflow-y-auto"> - Oh no error + Oh no error <span class="text-mono">>:(</span> </p> - <% end %> <ul class="pt-4 pl-4"> <%= for message <- @backlog do %> <%= if is_map(message) && Map.get(message, :__struct__) == IRC.Message do %> <li class="flex gap-2 place-items-center message" data-account-id={message.account.id}> <LSGWeb.Component.naive_date_time_utc datetime={message.at} format="time-24-with-seconds" /> <span class="inline-block font-bold flex-none cursor-default"><%= message.sender.nick %></span> <span class="inline-block flex-grow cursor-default"> <LSGWeb.MessageComponent.content self={message.account.id == @account_id} text={message.text} /> </span> </li> <% end %> <%= if is_binary(message) do %> <li class="notice"><%= message %></li> <% end %> <%= if is_map(message) && Map.get(message, :type) do %> <li class="flex gap-2 place-items-center event"> <LSGWeb.Component.naive_date_time_utc datetime={message.at} format="time-24-with-seconds" /> <span class="inline-block font-bold flex-none cursor-default text-gray-700">* * *</span> <span class="inline-block flex-grow cursor-default text-gray-700"> <LSGWeb.EventComponent.content event={message} self={@users[message.user_id] && @users[message.user_id].account == @account_id} user={@users[message.user_id]} /> </span> </li> <% end %> <% end %> </ul> </div> <aside> <%= for {_, user} <- @users do %> <details class="user dropdown"> <summary><%= user.nick %></summary> <div class="content"> <h3 class="text-xl font-bold"><%= user.nick %></h3> <ul class="mt-4 space-y-2"> <li class="">User: <span class="font-bold"><%= user.username %></span></li> <li class="">Name: <%= user.realname || user.nick %></li> <li class="">Host: <span class="font-mono"><%= user.host %></span></li> </ul> <div class="mt-4 font-xs text-gray-300 text-center"> UID: <%= user.id %> <br /> AID: <%= user.account %> </div> </div> </details> <% end %> </aside> </div> <.form let={f} id={"form-#{@counter}"} for={:message} phx-submit="send" class="w-full px-4 pt-4"> <div> <div class="mt-1 flex rounded-md shadow-sm border border-gray-300"> <%= text_input f, :text, class: "focus:ring-indigo-500 focus:border-indigo-500 block w-full border rounded-md pl-4 sm:text-sm border-gray-300", autofocus: true, 'phx-hook': "AutoFocus", autocomplete: "off", placeholder: "Don't be shy, say something…" %> <%= submit content_tag(:span, "Send"), class: "-ml-px relative inline-flex items-center space-x-2 px-4 py-2 border border-gray-300 text-sm font-medium rounded-r-md text-gray-700 bg-gray-50 hover:bg-gray-100 focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500"%> </div> </div> </.form> </div> diff --git a/priv/static/assets/alcoolog.js.gz b/priv/static/assets/alcoolog.js.gz index 95c3f94..6ac0ce5 100644 Binary files a/priv/static/assets/alcoolog.js.gz and b/priv/static/assets/alcoolog.js.gz differ diff --git a/priv/static/assets/site.css.gz b/priv/static/assets/site.css.gz index f9dd920..351fbbf 100644 Binary files a/priv/static/assets/site.css.gz and b/priv/static/assets/site.css.gz differ diff --git a/priv/static/assets/site.js.gz b/priv/static/assets/site.js.gz index 5e0bb00..b6c539e 100644 Binary files a/priv/static/assets/site.js.gz and b/priv/static/assets/site.js.gz differ