cinch 0.3.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +192 -0
  3. data/Rakefile +53 -43
  4. data/examples/basic/autovoice.rb +32 -0
  5. data/examples/basic/google.rb +35 -0
  6. data/examples/basic/hello.rb +15 -0
  7. data/examples/basic/join_part.rb +38 -0
  8. data/examples/basic/memo.rb +39 -0
  9. data/examples/basic/msg.rb +16 -0
  10. data/examples/basic/seen.rb +36 -0
  11. data/examples/basic/urban_dict.rb +35 -0
  12. data/examples/basic/url_shorten.rb +35 -0
  13. data/examples/plugins/autovoice.rb +40 -0
  14. data/examples/plugins/custom_prefix.rb +23 -0
  15. data/examples/plugins/google.rb +37 -0
  16. data/examples/plugins/hello.rb +22 -0
  17. data/examples/plugins/join_part.rb +42 -0
  18. data/examples/plugins/memo.rb +50 -0
  19. data/examples/plugins/msg.rb +22 -0
  20. data/examples/plugins/multiple_matches.rb +41 -0
  21. data/examples/plugins/seen.rb +45 -0
  22. data/examples/plugins/urban_dict.rb +30 -0
  23. data/examples/plugins/url_shorten.rb +32 -0
  24. data/lib/cinch.rb +7 -20
  25. data/lib/cinch/ban.rb +41 -0
  26. data/lib/cinch/bot.rb +479 -0
  27. data/lib/cinch/callback.rb +11 -0
  28. data/lib/cinch/channel.rb +419 -0
  29. data/lib/cinch/constants.rb +369 -0
  30. data/lib/cinch/exceptions.rb +25 -0
  31. data/lib/cinch/helpers.rb +21 -0
  32. data/lib/cinch/irc.rb +344 -38
  33. data/lib/cinch/isupport.rb +96 -0
  34. data/lib/cinch/logger/formatted_logger.rb +80 -0
  35. data/lib/cinch/logger/logger.rb +44 -0
  36. data/lib/cinch/logger/null_logger.rb +18 -0
  37. data/lib/cinch/mask.rb +46 -0
  38. data/lib/cinch/message.rb +183 -0
  39. data/lib/cinch/message_queue.rb +62 -0
  40. data/lib/cinch/plugin.rb +205 -0
  41. data/lib/cinch/rubyext/infinity.rb +1 -0
  42. data/lib/cinch/rubyext/module.rb +18 -0
  43. data/lib/cinch/rubyext/queue.rb +19 -0
  44. data/lib/cinch/rubyext/string.rb +24 -0
  45. data/lib/cinch/syncable.rb +55 -0
  46. data/lib/cinch/user.rb +325 -0
  47. data/spec/bot_spec.rb +5 -0
  48. data/spec/channel_spec.rb +5 -0
  49. data/spec/cinch_spec.rb +5 -0
  50. data/spec/irc_spec.rb +5 -0
  51. data/spec/message_spec.rb +5 -0
  52. data/spec/plugin_spec.rb +5 -0
  53. data/spec/{helper.rb → spec_helper.rb} +0 -0
  54. data/spec/user_spec.rb +5 -0
  55. metadata +69 -51
  56. data/README.rdoc +0 -195
  57. data/examples/autovoice.rb +0 -32
  58. data/examples/custom_patterns.rb +0 -19
  59. data/examples/custom_prefix.rb +0 -25
  60. data/examples/google.rb +0 -31
  61. data/examples/hello.rb +0 -13
  62. data/examples/join_part.rb +0 -26
  63. data/examples/memo.rb +0 -40
  64. data/examples/msg.rb +0 -14
  65. data/examples/named-param-types.rb +0 -19
  66. data/examples/seen.rb +0 -41
  67. data/examples/urban_dict.rb +0 -31
  68. data/examples/url_shorten.rb +0 -34
  69. data/lib/cinch/base.rb +0 -368
  70. data/lib/cinch/irc/message.rb +0 -135
  71. data/lib/cinch/irc/parser.rb +0 -141
  72. data/lib/cinch/irc/socket.rb +0 -329
  73. data/lib/cinch/names.rb +0 -54
  74. data/lib/cinch/rules.rb +0 -171
  75. data/spec/base_spec.rb +0 -94
  76. data/spec/irc/helper.rb +0 -8
  77. data/spec/irc/message_spec.rb +0 -61
  78. data/spec/irc/parser_spec.rb +0 -103
  79. data/spec/irc/socket_spec.rb +0 -90
  80. data/spec/names_spec.rb +0 -393
  81. data/spec/options_spec.rb +0 -45
  82. data/spec/rules_spec.rb +0 -109
@@ -1,90 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class Cinch::IRC::Socket
4
- def write(data)
5
- return data
6
- end
7
-
8
- def read(chompstr="\r\n")
9
- str = "foo bar baz\r\n"
10
- str.chomp!(chompstr) if chompstr
11
- end
12
- end
13
-
14
- commands = [
15
- [:pass, %w(foobar), "PASS foobar"],
16
- [:nick, %(ipsum), "NICK ipsum"],
17
- [:user, ["guest", 0, '*', "real name"], "USER guest 0 * :real name"],
18
- [:oper, %w(foo bar), "OPER foo bar"],
19
- [:mode, %w(#foo +v bar), "MODE #foo +v bar"],
20
- [:quit, %w(goodbye), "QUIT :goodbye"],
21
- [:join, %w(#mychan), "JOIN #mychan"],
22
- [:part, %w(#mychan), "PART #mychan"],
23
- [:part, %w(#mychan cya!), "PART #mychan :cya!", "with part message"],
24
- [:topic, %w(#mychan newtopic), "TOPIC #mychan :newtopic"],
25
- [:names, %w(#foo #bar), "NAMES #foo,#bar"],
26
- [:list, %w(#foo #bar), "LIST #foo,#bar"],
27
- [:invite, %w(foo #mychan), "INVITE foo #mychan"],
28
- [:kick, %w(#chan villian), "KICK #chan villian"],
29
- [:kick, %w(#chan villian gtfo!), "KICK #chan villian :gtfo!", "with kick reason"],
30
- [:privmsg, ['#chan', 'foo bar baz'], "PRIVMSG #chan :foo bar baz"],
31
- [:notice, ['#chan', 'foo bar baz'], "NOTICE #chan :foo bar baz"],
32
- [:motd, %w(someserver), "MOTD someserver"],
33
- [:version, %w(anotherserver), "VERSION anotherserver"],
34
- [:stats, %w(m server), "STATS m server"],
35
- [:time, %w(irc.someserver.net), "TIME irc.someserver.net"],
36
- [:info, %w(foobar), "INFO foobar"],
37
- [:squery, %w(irchelp HELPME), "SQUERY irchelp :HELPME"],
38
- [:who, %w(*.com o), "WHO *.com o"],
39
- [:whois, %w(foo.org user), "WHOIS foo.org user"],
40
- [:whowas, %w(foo.org user), "WHOWAS foo.org user"],
41
- [:kill, ['badperson', 'get out!'], "KILL badperson :get out!"],
42
- [:ping, %w(010123444), "PING 010123444"],
43
- [:pong, %w(irc.foobar.org), "PONG irc.foobar.org"],
44
- [:away, [], "AWAY"],
45
- [:away, ['gone for lunch'], "AWAY :gone for lunch"],
46
- [:users, %w(irc.foobar.org), "USERS irc.foobar.org"],
47
- [:userhost, %w(foo bar baz), "USERHOST foo bar baz"],
48
- ]
49
-
50
- describe "Cinch::IRC::Socket" do
51
- before do
52
- @irc = Cinch::IRC::Socket.new('irc.myserver.net')
53
- end
54
-
55
- describe "::new" do
56
- it "should return an Cinch::IRC::Socket" do
57
- @irc.class.should == Cinch::IRC::Socket
58
- end
59
-
60
- it "should default to port 6667" do
61
- @irc.port.should == 6667
62
- end
63
-
64
- it "should not automatically connect" do
65
- @irc.connected.should == false
66
- end
67
-
68
- it "should set socket instance as nil" do
69
- @irc.socket.should == nil
70
- end
71
- end
72
-
73
- describe "#read" do
74
- it "should chomp CRLF by default" do
75
- @irc.read.should == "foo bar baz"
76
- @irc.read.should_not == "foo bar baz\r\n"
77
- end
78
- end
79
-
80
- commands.each do |requirements|
81
- meth, params, pass, extra = *requirements
82
- describe "##{meth}" do
83
- it "should send a #{meth.to_s.upcase} command #{extra if extra}" do
84
- @irc.send(meth, *params).should == pass
85
- end
86
- end
87
- end
88
-
89
- end
90
-
@@ -1,393 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- describe Cinch::Base do
4
- before :each do
5
- @bot = Cinch::Base.new
6
- end
7
-
8
- it 'should be able to track names' do
9
- @bot.should respond_to(:track_names)
10
- end
11
-
12
- describe 'when tracking names' do
13
- before :each do
14
- @bot.track_names
15
- end
16
-
17
- it 'should indicate it is tracking names' do
18
- @bot.tracking_names?.should == true
19
- end
20
-
21
- it 'should provide access to the stored channel names' do
22
- @bot.should respond_to(:channel_names)
23
- end
24
-
25
- it 'should initialize the stored channel names as a hash' do
26
- @bot.channel_names.should == {}
27
- end
28
-
29
- it 'should provide a join listener' do
30
- @bot.listeners[:join].should_not be_nil
31
- end
32
-
33
- describe 'join listener' do
34
- before :each do
35
- @listener = @bot.listeners[:join].first
36
- @message = Struct.new(:nick, :channel).new('someguy', '#somechan')
37
-
38
- @bot.instance_variable_set('@channel_names', { @message.channel => [] })
39
- end
40
-
41
- it 'should be callable' do
42
- @listener.should respond_to(:call)
43
- end
44
-
45
- it "should add the joiner's nick to the channel name list" do
46
- @listener.call(@message)
47
- @bot.channel_names[@message.channel].should == [@message.nick]
48
- end
49
-
50
- it "should not remove any already-present nicks in the channel name list" do
51
- nicks = %w[tom mary joe]
52
- @bot.instance_variable_set('@channel_names', { @message.channel => nicks.dup })
53
- @listener.call(@message)
54
- @bot.channel_names[@message.channel].sort.should == (nicks + [@message.nick]).sort
55
- end
56
-
57
- it 'should not affect any other channel name lists' do
58
- channel_names = { '#otherchan' => %w[some people], @message.channel => [] }
59
- @bot.instance_variable_set('@channel_names', channel_names.dup)
60
- @listener.call(@message)
61
- @bot.channel_names.should == { '#otherchan' => %w[some people], @message.channel => [@message.nick] }
62
- end
63
-
64
- it 'should handle the channel names not already tracking the channel' do
65
- @bot.instance_variable_set('@channel_names', {})
66
- @listener.call(@message)
67
- @bot.channel_names[@message.channel].should == [@message.nick]
68
- end
69
-
70
- it 'should not issue a names command to the channel' do
71
- @bot.should_receive(:names).never
72
- @listener.call(@message)
73
- end
74
-
75
- describe 'and the joiner is the bot' do
76
- before :each do
77
- @message.nick = @bot.nick
78
- end
79
-
80
- it 'should not add the nick to the name list' do
81
- @listener.call(@message)
82
- @bot.channel_names[@message.channel].should_not include(@message.nick)
83
- end
84
-
85
- it 'should issue a names command to the channel' do
86
- @bot.should_receive(:names).with(@message.channel)
87
- @listener.call(@message)
88
- end
89
- end
90
- end
91
-
92
- it 'should provide a names listener' do
93
- @bot.listeners[:'353'].should_not be_nil
94
- end
95
-
96
- describe 'names listener' do
97
- before :each do
98
- @listener = @bot.listeners[:'353'].first
99
- @nick_text = 'cardroid admc cldwalker bmizerany'
100
- @nicks = %w[cardroid admc cldwalker bmizerany]
101
- @channel = '#github'
102
- @message = Struct.new(:params, :text).new(['cardroid', '@', @channel, @nick_text], @nick_text)
103
- end
104
-
105
- it 'should be callable' do
106
- @listener.should respond_to(:call)
107
- end
108
-
109
- it 'should set the channel name list to the given nick list' do
110
- @listener.call(@message)
111
- @bot.channel_names[@channel].should == @nicks
112
- end
113
-
114
- it 'should add the given nicks to an already-present channel name list' do
115
- nicks = %w[other people already present]
116
- @bot.instance_variable_set('@channel_names', { @channel => nicks.dup })
117
-
118
- @listener.call(@message)
119
- @bot.channel_names[@channel].should == (nicks + @nicks)
120
- end
121
-
122
- it 'should not affect any other channel name lists' do
123
- channel_names = { '#otherchan' => %w[some people], @channel => [] }
124
- @bot.instance_variable_set('@channel_names', channel_names.dup)
125
- @listener.call(@message)
126
- @bot.channel_names.should == { '#otherchan' => %w[some people], @channel => @nicks }
127
- end
128
-
129
- it 'should strip extra marking characters from the given nick list' do
130
- nick_text = 'cardroid admc cldwalker bmizerany programble @luckiestmonkey @tekkub binjured ceej'
131
- nicks = %w[cardroid admc cldwalker bmizerany programble luckiestmonkey tekkub binjured ceej]
132
- @message.params[-1] = nick_text
133
- @message.text = nick_text
134
-
135
- @listener.call(@message)
136
- @bot.channel_names[@channel].should == nicks
137
- end
138
- end
139
-
140
- it 'should provide a part listener' do
141
- @bot.listeners[:part].should_not be_nil
142
- end
143
-
144
- describe 'part listener' do
145
- before :each do
146
- @listener = @bot.listeners[:part].first
147
- @message = Struct.new(:nick, :channel).new('someguy', '#somechan')
148
-
149
- @bot.instance_variable_set('@channel_names', { @message.channel => [] })
150
- end
151
-
152
- it 'should be callable' do
153
- @listener.should respond_to(:call)
154
- end
155
-
156
- it "should remove the parter's nick from the channel name list" do
157
- @nicks = %w[bunch of people]
158
- @bot.instance_variable_set('@channel_names', { @message.channel => (@nicks + [@message.nick]) })
159
-
160
- @listener.call(@message)
161
- @bot.channel_names[@message.channel].should == @nicks
162
- end
163
-
164
- it "should remove the parter's nick from the channel name list no matter where or how many times it occurs" do
165
- @nicks = %w[bunch of people]
166
- @bot.instance_variable_set('@channel_names', { @message.channel => @nicks.join(" #{@message.nick} ").split })
167
-
168
- @listener.call(@message)
169
- @bot.channel_names[@message.channel].should == @nicks
170
- end
171
-
172
- it 'should not affect any other channel name lists' do
173
- @nicks = %w[bunch of people]
174
- channel_names = { '#otherchan' => %w[some people], @message.channel => (@nicks + [@message.nick]) }
175
- @bot.instance_variable_set('@channel_names', channel_names.dup)
176
- @listener.call(@message)
177
- @bot.channel_names.should == { '#otherchan' => %w[some people], @message.channel => @nicks }
178
- end
179
-
180
- it 'should handle the channel names not already tracking the channel' do
181
- @bot.instance_variable_set('@channel_names', {})
182
- @listener.call(@message)
183
- @bot.channel_names[@message.channel].should == []
184
- end
185
-
186
- it 'should handle the nick not appearing on the list' do
187
- @nicks = %w[bunch of people]
188
- @bot.instance_variable_set('@channel_names', { @message.channel => @nicks.dup })
189
-
190
- @listener.call(@message)
191
- @bot.channel_names[@message.channel].should == @nicks
192
- end
193
-
194
- describe 'and the parter is the bot' do
195
- before :each do
196
- @message.nick = @bot.nick
197
- end
198
-
199
- it 'should completely remove the channel from the names hash' do
200
- channel_names = { '#otherchan' => %w[some people], @message.channel => %w[bunch of people] }
201
- @bot.instance_variable_set('@channel_names', channel_names.dup)
202
- @listener.call(@message)
203
- @bot.channel_names.should == { '#otherchan' => %w[some people] }
204
- end
205
- end
206
- end
207
-
208
- it 'should provide a quit listener' do
209
- @bot.listeners[:quit].should_not be_nil
210
- end
211
-
212
- describe 'quit listener' do
213
- before :each do
214
- @listener = @bot.listeners[:quit].first
215
- @message = Struct.new(:nick).new('someguy')
216
- @channel = '#somechan'
217
- @nicks = %w[bunch of people]
218
- @other_chan = '#otherchan'
219
- @other_nicks = %w[other people here]
220
- end
221
-
222
- it 'should be callable' do
223
- @listener.should respond_to(:call)
224
- end
225
-
226
- it "should remove the quitter's nick from every channel name list" do
227
- @bot.instance_variable_set('@channel_names', { @channel => (@nicks + [@message.nick]), @other_chan => (@other_nicks + [@message.nick]) })
228
-
229
- @listener.call(@message)
230
- @bot.channel_names.should == { @channel => @nicks, @other_chan => @other_nicks }
231
- end
232
-
233
- it "should remove the quitter's nick from every channel name list no matter where or how many times it occurs" do
234
- @bot.instance_variable_set('@channel_names', { @channel => @nicks.join(" #{@message.nick} ").split, @other_chan => @other_nicks.join(" #{@message.nick} ").split })
235
-
236
- @listener.call(@message)
237
- @bot.channel_names.should == { @channel => @nicks, @other_chan => @other_nicks }
238
- end
239
-
240
- it 'should not affect any other channel name lists' do
241
- @bot.instance_variable_set('@channel_names', { @channel => (@nicks + [@message.nick]), @other_chan => @other_nicks.dup })
242
-
243
- @listener.call(@message)
244
- @bot.channel_names.should == { @channel => @nicks, @other_chan => @other_nicks }
245
- end
246
- end
247
-
248
- it 'should provide a kill listener' do
249
- @bot.listeners[:kill].should_not be_nil
250
- end
251
-
252
- describe 'kill listener' do
253
- before :each do
254
- @listener = @bot.listeners[:kill].first
255
- @message = Struct.new(:nick).new('someguy')
256
- @channel = '#somechan'
257
- @nicks = %w[bunch of people]
258
- @other_chan = '#otherchan'
259
- @other_nicks = %w[other people here]
260
- end
261
-
262
- it 'should be callable' do
263
- @listener.should respond_to(:call)
264
- end
265
-
266
- it 'should remove the killed nick from every channel name list' do
267
- @bot.instance_variable_set('@channel_names', { @channel => (@nicks + [@message.nick]), @other_chan => (@other_nicks + [@message.nick]) })
268
-
269
- @listener.call(@message)
270
- @bot.channel_names.should == { @channel => @nicks, @other_chan => @other_nicks }
271
- end
272
-
273
- it 'should remove the killed nick from every channel name list no matter where or how many times it occurs' do
274
- @bot.instance_variable_set('@channel_names', { @channel => @nicks.join(" #{@message.nick} ").split, @other_chan => @other_nicks.join(" #{@message.nick} ").split })
275
-
276
- @listener.call(@message)
277
- @bot.channel_names.should == { @channel => @nicks, @other_chan => @other_nicks }
278
- end
279
-
280
- it 'should not affect any other channel name lists' do
281
- @bot.instance_variable_set('@channel_names', { @channel => (@nicks + [@message.nick]), @other_chan => @other_nicks.dup })
282
-
283
- @listener.call(@message)
284
- @bot.channel_names.should == { @channel => @nicks, @other_chan => @other_nicks }
285
- end
286
- end
287
-
288
- it 'should provide a nick listener' do
289
- @bot.listeners[:nick].should_not be_nil
290
- end
291
-
292
- describe 'nick listener' do
293
- before :each do
294
- @listener = @bot.listeners[:nick].first
295
- @message = Struct.new(:nick, :recipient).new('someguy', 'someotherguy')
296
- @channel = '#somechan'
297
- @nicks = %w[bunch of people]
298
- @other_chan = '#otherchan'
299
- @other_nicks = %w[other people here]
300
- end
301
-
302
- it 'should be callable' do
303
- @listener.should respond_to(:call)
304
- end
305
-
306
- it 'should replace the changed nick in every channel name list' do
307
- @bot.instance_variable_set('@channel_names', { @channel => (@nicks + [@message.nick]), @other_chan => (@other_nicks + [@message.nick]) })
308
-
309
- @listener.call(@message)
310
- @bot.channel_names.should == { @channel => (@nicks + [@message.recipient]), @other_chan => (@other_nicks + [@message.recipient]) }
311
- end
312
-
313
- it 'should replace the the changed nick in every channel name list no matter where or how many times it occurs' do
314
- @bot.instance_variable_set('@channel_names', { @channel => @nicks.join(" #{@message.nick} ").split, @other_chan => @other_nicks.join(" #{@message.nick} ").split })
315
-
316
- @listener.call(@message)
317
- @bot.channel_names.should == { @channel => (@nicks + [@message.recipient]), @other_chan => (@other_nicks + [@message.recipient]) }
318
- end
319
-
320
- it 'should not affect any other channel name lists' do
321
- @bot.instance_variable_set('@channel_names', { @channel => (@nicks + [@message.nick]), @other_chan => @other_nicks.dup })
322
-
323
- @listener.call(@message)
324
- @bot.channel_names.should == { @channel => (@nicks + [@message.recipient]), @other_chan => @other_nicks }
325
- end
326
- end
327
-
328
- it 'should not interfere with other bots' do
329
- @bot_one = Cinch::Base.new
330
- @bot_two = Cinch::Base.new
331
-
332
- @bot_one.track_names
333
- @bot_two.track_names
334
-
335
- @message = Struct.new(:nick, :channel)
336
- @message_one = @message.new('someguy', '#somechan')
337
- @message_two = @message.new('otherguy', '#otherchan')
338
-
339
- @bot_one.listeners[:join].first.call(@message_one)
340
- @bot_two.listeners[:join].first.call(@message_two)
341
-
342
- @bot_one.channel_names.should == { @message_one.channel => [@message_one.nick] }
343
- @bot_two.channel_names.should == { @message_two.channel => [@message_two.nick] }
344
- end
345
-
346
- it 'should not re-add listeners when asked to track names again' do
347
- @bot.track_names
348
- @bot.listeners[:join].length.should == 1
349
- end
350
-
351
- it 'should not reset the channel name list when asked to track names again' do
352
- @message = Struct.new(:nick, :channel).new('someguy', '#somechan')
353
- @bot.listeners[:join].first.call(@message)
354
-
355
- @bot.track_names
356
- @bot.channel_names.should == { @message.channel => [@message.nick] }
357
- end
358
- end
359
-
360
- describe 'before tracking names' do
361
- it 'should indicate it is not tracking names' do
362
- @bot.tracking_names?.should == false
363
- end
364
-
365
- it 'should have no channel name list' do
366
- @bot.channel_names.should be_nil
367
- end
368
-
369
- it 'should have no join listener' do
370
- @bot.listeners[:join].should be_nil
371
- end
372
-
373
- it 'should have no names listener' do
374
- @bot.listeners[:'353'].should be_nil
375
- end
376
-
377
- it 'should have no part listener' do
378
- @bot.listeners[:part].should be_nil
379
- end
380
-
381
- it 'should have no quit listener' do
382
- @bot.listeners[:quit].should be_nil
383
- end
384
-
385
- it 'should have no kill listener' do
386
- @bot.listeners[:kill].should be_nil
387
- end
388
-
389
- it 'should have no nick listener' do
390
- @bot.listeners[:nick].should be_nil
391
- end
392
- end
393
- end