summaryrefslogblamecommitdiff
path: root/lib/lsg_irc/kick_roulette_plugin.ex
blob: 55b7da4c1da09962ddad9c56088ca384fef15fc3 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                        







                                     
                                                          


                 
                                                                                  

















                                                                                                 
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