camper_van 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -53,6 +53,8 @@ Connect, and `/LIST` will show you the irc channels / campfire rooms you
53
53
  have access to. To connect to more than one subdomain, make a separate
54
54
  connection for each.
55
55
 
56
+ If your IRC client (mIRC) doesn't allow `:` in the password, you can use `-`.
57
+
56
58
  Your campfire subdomain should be just the subdomain part. If your campfire url
57
59
  is `mycompany.campfirenow.com`, your subdomain would be `mycompany`.
58
60
 
data/bin/camper_van CHANGED
@@ -46,6 +46,8 @@ Options:
46
46
 
47
47
  opt :pid, 'Path of the PID file', :type => :string,
48
48
  :default => '/var/run/camper_van.pid'
49
+
50
+ opt :part_on_away, 'Part from channels when going away'
49
51
  end
50
52
 
51
53
  opts = Trollop.with_standard_exception_handling parser do
@@ -80,7 +82,8 @@ else
80
82
  :ssl_cert => opts[:ssl_cert],
81
83
  :ssl_verify_peer => opts[:ssl_verify_peer],
82
84
  :daemon => opts[:daemon],
83
- :pid => opts[:pid]
85
+ :pid => opts[:pid],
86
+ :part_on_away => opts[:part_on_away]
84
87
  )
85
88
 
86
89
  end
data/camper_van.gemspec CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.required_ruby_version = "~> 1.9.2"
22
22
 
23
- s.add_dependency "eventmachine", "~> 0.12.10"
24
- s.add_dependency "firering", "~> 1.2.0"
23
+ s.add_dependency "eventmachine", "~> 1.0.3"
24
+ s.add_dependency "firering", "~> 1.3.0"
25
25
  s.add_dependency "logging", "~> 1.5.1"
26
26
  s.add_dependency "trollop", "~> 1.16.2"
27
27
 
@@ -17,7 +17,7 @@ module CamperVan
17
17
  attr_reader :subdomain, :api_key
18
18
 
19
19
  # Information for the connected user
20
- attr_reader :nick, :user, :host
20
+ attr_reader :nick, :user, :host, :away
21
21
 
22
22
  # A Hash of connected CampfireChannels
23
23
  attr_reader :channels
@@ -26,6 +26,9 @@ module CamperVan
26
26
  # Set to false when shutting down so extra commands are ignored.
27
27
  attr_reader :active
28
28
 
29
+ # Additional options
30
+ attr_reader :options
31
+
29
32
  MOTD = <<-motd
30
33
  Welcome to CamperVan.
31
34
  To see what campfire rooms are available to the
@@ -40,11 +43,18 @@ module CamperVan
40
43
 
41
44
  # Public: initialize an IRC server connection
42
45
  #
43
- # client - the EM connection representing the IRC client
44
- def initialize(client)
46
+ # client - the EM connection representing the IRC client
47
+ # options - a Hash of additional options, defaults to {}
48
+ # :part_on_away - leave connected campfire rooms when irc client
49
+ # goes away, rejoin when coming back
50
+ #
51
+ def initialize(client, options = {})
45
52
  @client = client
46
53
  @active = true
47
54
  @channels = {}
55
+ @away = false
56
+ @saved_channels = []
57
+ @options = options
48
58
  end
49
59
 
50
60
  # The campfire client
@@ -95,6 +105,13 @@ module CamperVan
95
105
  shutdown
96
106
  else
97
107
  @subdomain, @api_key = *args.first.split(":")
108
+
109
+ # allow alternate '-' separator
110
+ if !@api_key
111
+ # split on the last occurrence of '-':
112
+ @subdomain, @api_key = *args.first.split(/-(?=[^-]+$)/)
113
+ end
114
+
98
115
  # ignore full "mycompany.campfirenow.com" being set as the subdomain
99
116
  @subdomain = subdomain.split(".").first
100
117
  end
@@ -243,7 +260,24 @@ module CamperVan
243
260
  end
244
261
 
245
262
  handle :away do |args|
246
- # ignore silently, there's no campfire API for this
263
+ if @away
264
+ user_reply 305, "You are no longer marked as being away"
265
+ if options[:part_on_away]
266
+ @saved_channels.each do |channel|
267
+ join_channel channel
268
+ end
269
+ @saved_channels = []
270
+ end
271
+ else
272
+ user_reply 306, "You have been marked as being away"
273
+ if options[:part_on_away]
274
+ @saved_channels = channels.keys
275
+ channels.values.each do |channel|
276
+ channel.part
277
+ end
278
+ end
279
+ end
280
+ @away = !@away
247
281
  end
248
282
 
249
283
  handle :quit do |args|
@@ -109,7 +109,7 @@ module CamperVan
109
109
  @lt2_delimiter = "\r\n"
110
110
 
111
111
  # start up the IRCD for this connection
112
- @ircd = IRCD.new(self)
112
+ @ircd = IRCD.new(self, options)
113
113
 
114
114
  if options[:ssl]
115
115
  logger.info "starting TLS for #{remote_ip}"
@@ -1,3 +1,3 @@
1
1
  module CamperVan
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -22,6 +22,8 @@ describe CamperVan::IRCD do
22
22
 
23
23
  class TestIRCD < CamperVan::IRCD
24
24
  attr_writer :campfire
25
+ attr_writer :away
26
+ attr_accessor :saved_channels
25
27
  end
26
28
 
27
29
  before :each do
@@ -42,6 +44,18 @@ describe CamperVan::IRCD do
42
44
  @server.api_key.must_equal "asdf1234"
43
45
  end
44
46
 
47
+ it "allows '-' as a domain/api key separator" do
48
+ @server.handle :pass => ["test-asdf1234"]
49
+ @server.subdomain.must_equal "test"
50
+ @server.api_key.must_equal "asdf1234"
51
+ end
52
+
53
+ it "uses the *last* '-' as the separator in a domain/api key pair" do
54
+ @server.handle :pass => ["test-subdomain-asdf1234"]
55
+ @server.subdomain.must_equal "test-subdomain"
56
+ @server.api_key.must_equal "asdf1234"
57
+ end
58
+
45
59
  it "only uses the subdomain if a full domain is specified" do
46
60
  @server.handle :pass => ["test.campfirenow.com:asdf1234"]
47
61
  @server.subdomain.must_equal "test"
@@ -238,6 +252,71 @@ describe CamperVan::IRCD do
238
252
 
239
253
  end
240
254
 
255
+ context "with an AWAY command" do
256
+ before :each do
257
+ # register
258
+ @server.handle :pass => ["test:1234asdf"]
259
+ @server.handle :nick => ["nathan"]
260
+ @server.handle :user => ["nathan", 0, 0, "Nathan"]
261
+ end
262
+
263
+ context "with part_on_away set" do
264
+ before :each do
265
+ @server.options[:part_on_away] = true
266
+
267
+ @server.campfire = Class.new do
268
+ def rooms
269
+ yield [
270
+ OpenStruct.new(:name => "Test"),
271
+ OpenStruct.new(:name => "Day Job")
272
+ ]
273
+ end
274
+ end.new
275
+
276
+ @server.handle :join => ["#test"]
277
+ @channel = MiniTest::Mock.new
278
+ @server.channels["#test"] = @channel
279
+
280
+ @connection.sent.clear
281
+ end
282
+
283
+ after :each do
284
+ @channel.verify
285
+ end
286
+
287
+ it "parts joined channels when not away" do
288
+ @channel.expect :part, nil
289
+ @server.away = false
290
+ @server.handle :away => ["bbl..."]
291
+ @server.away.must_equal true
292
+ end
293
+
294
+ it "rejoins previous channels when away" do
295
+ @channel.expect :join, nil
296
+ @server.saved_channels = ["#test"]
297
+ @server.away = true
298
+ @server.handle :away => []
299
+ @server.away.must_equal false
300
+ end
301
+ end
302
+
303
+ context "without part_on_away set" do
304
+ it "calls #away while not away" do
305
+ @server.away = false
306
+ @server.handle :away => ["bbl..."]
307
+ @server.away.must_equal true
308
+ @connection.sent.last.must_equal ":nathan!nathan@127.0.0.1 306 :You have been marked as being away"
309
+ end
310
+
311
+ it "returns from #away while away" do
312
+ @server.away = true
313
+ @server.handle :away => []
314
+ @server.away.must_equal false
315
+ @connection.sent.last.must_equal ":nathan!nathan@127.0.0.1 305 :You are no longer marked as being away"
316
+ end
317
+ end
318
+ end
319
+
241
320
  end
242
321
 
243
322
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camper_van
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-12 00:00:00.000000000 Z
12
+ date: 2013-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.12.10
21
+ version: 1.0.3
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.12.10
29
+ version: 1.0.3
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: firering
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 1.2.0
37
+ version: 1.3.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 1.2.0
45
+ version: 1.3.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: logging
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  segments:
151
151
  - 0
152
- hash: -1732883802111020027
152
+ hash: -1560684573150717162
153
153
  requirements: []
154
154
  rubyforge_project: camper_van
155
155
  rubygems_version: 1.8.23