diff options
author | href <href@random.sh> | 2018-05-02 19:03:35 +0200 |
---|---|---|
committer | href <href@random.sh> | 2018-05-02 19:04:28 +0200 |
commit | a47dc245808921309f58e8b1c4b6fa028b2df073 (patch) | |
tree | 1842d413f2a43d3759b439417f053052b878a1f7 /lib/irc.ex | |
parent | … (diff) |
meh
Diffstat (limited to '')
-rw-r--r-- | lib/irc.ex | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/irc.ex b/lib/irc.ex new file mode 100644 index 0000000..6ba819c --- /dev/null +++ b/lib/irc.ex @@ -0,0 +1,34 @@ +defmodule IRC do + + defmodule Message do + defstruct [:text, + :sender, + :channel, + :trigger, + :replyfun] + end + defmodule Trigger do + defstruct [:type, :trigger, :args] + end + + def register(key) do + case Registry.register(IRC.PubSub, key, []) do + {:ok, _} -> :ok + error -> error + end + end + + def admin?(%Message{sender: sender}), do: admin?(sender) + + def admin?(%{nick: nick, user: user, host: host}) do + for {n, u, h} <- Application.get_env(:lsg, :irc, [])[:admins]||[] do + admin_part_match?(n, nick) && admin_part_match?(u, user) && admin_part_match?(h, host) + end + |> Enum.any? + end + + defp admin_part_match?(:_, _), do: true + defp admin_part_match?(a, a), do: true + defp admin_part_match?(_, _), do: false + +end |