forked from naoto/citrus-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
random_reply.rb
56 lines (46 loc) · 1.24 KB
/
random_reply.rb
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class RandomReply < Citrus::Plugin
def on_privmsg(prefix, channel, message)
@config["replies"].each do |r|
if message =~ /(#{r["words"]})/ &&
(!r["channels"] || r["channels"].include?(channel))
#notice channel, r["reply"].sort_by{rand}[0]
r["reply"].sort_by{rand}[0].split(/\s/).each { |talk|
notice channel, talk
sleep 1
}
end
end
end
end
tests do
describe SimpleReply do
before :all do
@core = DummyCore.new({})
@socket = @core.socket
@prefix = Net::IRC::Prefix.new("foo!foo@localhost")
@plugin = SimpleReply.new(@core, { "SimpleReply" => {
"replies" => [
{
"words" => ["foo", "bar"],
"channels" => "#test",
"reply" => "Nice boat.",
}
]
} })
end
it "should reply correctly" do
@socket.clear
@plugin.on_privmsg(@prefix, "#test", "foo")
@socket.pop.to_s.should == "NOTICE #test :Nice boat.\r\n"
@socket.clear
@plugin.on_privmsg(@prefix, "#test", "bar")
@socket.pop.to_s.should == "NOTICE #test :Nice boat.\r\n"
@socket.clear
@plugin.on_privmsg(@prefix, "#test", "baz")
@socket.should be_empty
@socket.clear
@plugin.on_privmsg(@prefix, "#test2", "foo")
@socket.should be_empty
end
end
end