1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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__, [], 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
|