summaryrefslogtreecommitdiff
path: root/lib/lsg_irc/kick_roulette_plugin.ex
diff options
context:
space:
mode:
authorhref <href@random.sh>2020-03-11 21:18:34 +0100
committerhref <href@random.sh>2020-03-11 21:18:34 +0100
commita28d24470ddeca6196219a1333c1ccac1319efef (patch)
tree4f29e3c8fb6afbb1f99d6b8737f844c95fca54df /lib/lsg_irc/kick_roulette_plugin.ex
parentup to 420*100 (diff)
welp
Diffstat (limited to '')
-rw-r--r--lib/lsg_irc/kick_roulette_plugin.ex32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/lsg_irc/kick_roulette_plugin.ex b/lib/lsg_irc/kick_roulette_plugin.ex
new file mode 100644
index 0000000..83efcb0
--- /dev/null
+++ b/lib/lsg_irc/kick_roulette_plugin.ex
@@ -0,0 +1,32 @@
+defmodule LSG.IRC.KickRoulettePlugin do
+ @moduledoc """
+ # kick roulette
+
+ * **!kick**, tentez votre chanceā€¦
+ """
+
+ def irc_doc, do: @moduledoc
+ def start_link() do
+ GenServer.start_link(__MODULE__, [])
+ end
+
+ def init([]) do
+ {:ok, _} = Registry.register(IRC.PubSub, "trigger:kick", [])
+ {:ok, nil}
+ end
+
+ def handle_info({:irc, :trigger, "kick", message = %{trigger: %{type: :bang, args: []}}}, _) do
+ if 5 == :crypto.rand_uniform(1, 6) do
+ spawn(fn() ->
+ :timer.sleep(:crypto.rand_uniform(200, 10_000))
+ message.replyfun.({:kick, message.sender.nick, "perdu"})
+ end)
+ end
+ {:noreply, nil}
+ end
+
+ def handle_info(msg, _) do
+ {:noreply, nil}
+ end
+
+end