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.KickRouletteHandler do
@moduledoc """
# kick roulette
* **!kick**
"""
def irc_doc, do: @moduledoc
def start_link(client) do
GenServer.start_link(__MODULE__, [client])
end
def init([client]) do
ExIRC.Client.add_handler client, self
{:ok, client}
end
def handle_info({:received, "!kick", sender, chan}, client) do
if 5 == :crypto.rand_uniform(1, 6) do
spawn(fn() ->
:timer.sleep(:crypto.rand_uniform(500, 15_000))
ExIRC.Client.kick(client, chan, sender.nick, "perdu")
end)
end
{:noreply, client}
end
def handle_info(msg, client) do
{:noreply, client}
end
end
|