diff options
author | Jordan Bracco <href@random.sh> | 2025-06-25 19:22:59 +0200 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2025-06-25 19:22:59 +0200 |
commit | c934e79e5852e05f714b2d542cc2678e287c49b8 (patch) | |
tree | 55779a0168260fce03e4775eacdd613ffc945588 /lib/plugins/seen.ex | |
parent | updates (diff) |
format.
Diffstat (limited to 'lib/plugins/seen.ex')
-rw-r--r-- | lib/plugins/seen.ex | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/plugins/seen.ex b/lib/plugins/seen.ex index 045702c..cff0928 100644 --- a/lib/plugins/seen.ex +++ b/lib/plugins/seen.ex @@ -6,6 +6,7 @@ defmodule Nola.Plugins.Seen do """ def irc_doc, do: @moduledoc + def start_link() do GenServer.start_link(__MODULE__, [], name: __MODULE__) end @@ -19,7 +20,11 @@ defmodule Nola.Plugins.Seen do {:ok, %{dets: dets}} end - def handle_info({:irc, :trigger, "seen", m = %Nola.Message{trigger: %Nola.Trigger{type: :bang, args: [nick]}}}, state) do + def handle_info( + {:irc, :trigger, "seen", + m = %Nola.Message{trigger: %Nola.Trigger{type: :bang, args: [nick]}}}, + state + ) do witness(m, state) m.replyfun.(last_seen(m.channel, nick, state)) {:noreply, state} @@ -43,17 +48,20 @@ defmodule Nola.Plugins.Seen do defp last_seen(channel, nick, %{dets: dets}) do case :dets.lookup(dets, {channel, nick}) do [{_, date, text}] -> - diff = round(DateTime.diff(DateTime.utc_now(), date)/60) + diff = round(DateTime.diff(DateTime.utc_now(), date) / 60) + cond do diff >= 30 -> duration = Timex.Duration.from_minutes(diff) format = Timex.Format.Duration.Formatter.lformat(duration, "fr", :humanized) "#{nick} a parlé pour la dernière fois il y a #{format}: “#{text}”" - true -> "#{nick} est là..." + + true -> + "#{nick} est là..." end + [] -> "je ne connais pas de #{nick}" end end - end |