diff options
Diffstat (limited to 'lib/nola_plugins/kick_roulette_plugin.ex')
-rw-r--r-- | lib/nola_plugins/kick_roulette_plugin.ex | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/nola_plugins/kick_roulette_plugin.ex b/lib/nola_plugins/kick_roulette_plugin.ex new file mode 100644 index 0000000..55b7da4 --- /dev/null +++ b/lib/nola_plugins/kick_roulette_plugin.ex @@ -0,0 +1,32 @@ +defmodule Nola.IRC.KickRoulettePlugin 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 |