From 2d83df8b32bff7f0028923bb5b64dc0b55f20d03 Mon Sep 17 00:00:00 2001 From: Jordan Bracco Date: Tue, 20 Dec 2022 00:21:54 +0000 Subject: Nola rename: The Big Move, Refs T77 --- lib/nola_plugins/admin_handler.ex | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lib/nola_plugins/admin_handler.ex (limited to 'lib/nola_plugins/admin_handler.ex') diff --git a/lib/nola_plugins/admin_handler.ex b/lib/nola_plugins/admin_handler.ex new file mode 100644 index 0000000..9a5d557 --- /dev/null +++ b/lib/nola_plugins/admin_handler.ex @@ -0,0 +1,41 @@ +defmodule Nola.IRC.AdminHandler do + @moduledoc """ + # admin + + !op + op; requiert admin + """ + + def irc_doc, do: nil + + def start_link(client) do + GenServer.start_link(__MODULE__, [client]) + end + + def init([client]) do + ExIRC.Client.add_handler client, self + :ok = IRC.register("op") + {:ok, client} + end + + def handle_info({:irc, :trigger, "op", m = %IRC.Message{trigger: %IRC.Trigger{type: :bang}, sender: sender}}, client) do + if IRC.admin?(sender) do + m.replyfun.({:mode, "+o"}) + else + m.replyfun.({:kick, "non"}) + end + {:noreply, client} + end + + def handle_info({:joined, chan, sender}, client) do + if IRC.admin?(sender) do + ExIRC.Client.mode(client, chan, "+o", sender.nick) + end + {:noreply, client} + end + + def handle_info(msg, client) do + {:noreply, client} + end + +end -- cgit v1.2.3