defmodule Nola.Plugins.KickRoulette do
@moduledoc """
# kick roulette
* **!kick**, tentez votre chance…
"""
def irc_doc, do: @moduledoc
def start_link() do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
def init([]) do
{:ok, _} = Registry.register(IRC.PubSub, "trigger:kick", [plugin: __MODULE__])
{: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