lita-irc 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5f6718f839abd60bc28ecfa83cc7fdad901bc39
4
- data.tar.gz: cfe790709ff47c4e191e481099bee658e5049abf
3
+ metadata.gz: 4395b1f99ddbd742dd59d2393d3e396671167cdb
4
+ data.tar.gz: a3eb5703529d4b9498b0a4ab8d8e0154da14b345
5
5
  SHA512:
6
- metadata.gz: 12fd0af0616013b03b98f74ed7d490f759e5b4bc55684c604642803cf2f695b2cbc17b2dc18d03be4016d95f4e386bca283208f3475efc6fd9574acf4233f9ef
7
- data.tar.gz: b55553fd2aab232ec95a82be7ca433b8bd2c33628a0d375e4c1462e1ad28a97d562528be1b3aee78ce3f3a1bb4b6e8377b78c56b2c42da40f57579912423b948
6
+ metadata.gz: f0eed00861cc230928a47ff74d087fe6c477a6b577cd6658f1ae66d2bcee0c432b4c825f4ba4baa22da5eca3cba4a7fbf9ad88ca723c3a29118c872ef5f9efc5
7
+ data.tar.gz: 1bc336e4c560da4740dbc342c06e1206d39182c3955d5c414cbdfb6fad360b6d96287ed4993af4af5abe62528481b6a1372b20d7c4a874fce6777cbaa3df3206
data/README.md CHANGED
@@ -16,26 +16,23 @@ gem "lita-irc"
16
16
 
17
17
  ## Configuration
18
18
 
19
- All attributes set on `config.adapter` will be passed on to the underlying [Cinch](https://github.com/cinchrb/cinch) robot. The documentation for [Cinch's options](http://rubydoc.info/github/cinchrb/cinch/file/docs/bot_options.md) detail all of them.
20
-
21
- The attributes listed below are either fundamental to making the bot work, or have defaults provided by Lita that take precedence over Cinch's defaults.
22
-
23
19
  ### Required attributes
24
20
 
25
- * `server` (String) - The name of the IRC server Lita should connect to. Default: `nil`.
26
- * `channels` (Array<String>) - An array of channels Lita should join upon connection. Default: `nil`.
21
+ * `server` (String) - The name of the IRC server Lita should connect to.
22
+ * `channels` (Array<String>) - An array of channels Lita should join upon connection.
27
23
 
28
24
  ### Optional attributes
29
25
 
30
- * `user` (String) - The username for Lita's IRC account. Default: `"Lita"".
26
+ * `user` (String) - The username for Lita's IRC account. Default: `"Lita"`.
31
27
  * `password` (String) - The password for Lita's IRC account. Default: `nil`.
32
28
  * `realname` (String) - The "real name" field for Lita's IRC account. Default: `"Lita"`.
29
+ * `log_level` (Symbol) - Sets the log level for Cinch's loggers. By default, Cinch's loggers are disabled. Default: `nil`.
33
30
 
34
- ### Lita-specific attributes
31
+ **Note**: `config.robot.name` is used as Lita's IRC nickname. `config.adapters.irc.nick` is ignored.
35
32
 
36
- * `log_level` (Symbol) - Sets the log level for Cinch's loggers. By default, Cinch's loggers are disabled. Default: `nil`.
33
+ ### Additional Cinch options
37
34
 
38
- **Note**: `config.robot.name` is used as Lita's IRC nickname. `config.adapter.nick` is ignored.
35
+ Under the hood, lita-irc uses [Cinch](https://github.com/cinchrb/cinch) for the IRC connection. Cinch has several [configuration options](http://www.rubydoc.info/github/cinchrb/cinch/file/docs/bot_options.md) that you may want to set. To do this, assign a proc/lambda to `config.adapters.irc.cinch`. lita-irc will yield the Cinch configuration object to the proc, so you can configure it as you'd like. Note that for the options listed in the sections above, those values will overwrite anything set in the proc.
39
36
 
40
37
  ### Example
41
38
 
@@ -43,11 +40,14 @@ The attributes listed below are either fundamental to making the bot work, or ha
43
40
  Lita.configure do |config|
44
41
  config.robot.name = "Lita"
45
42
  config.robot.adapter = :irc
46
- config.adapter.server = "irc.freenode.net"
47
- config.adapter.channels = ["#litabot"]
48
- config.adapter.user = "Lita"
49
- config.adapter.realname = "Lita"
50
- config.adapter.password = "secret"
43
+ config.adapters.irc.server = "irc.freenode.net"
44
+ config.adapters.irc.channels = ["#litabot"]
45
+ config.adapters.irc.user = "Lita"
46
+ config.adapters.irc.realname = "Lita"
47
+ config.adapters.irc.password = "secret"
48
+ config.adapters.irc.cinch = lambda do |cinch_config|
49
+ cinch_config.max_reconnect_delay = 123
50
+ end
51
51
  end
52
52
  ```
53
53
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -6,7 +6,20 @@ require "lita/adapters/irc/cinch_plugin"
6
6
  module Lita
7
7
  module Adapters
8
8
  class IRC < Adapter
9
- require_configs :server, :channels
9
+ # Required attributes
10
+ config :channels, type: [Array, String], required: true
11
+ config :server, type: String, required: true
12
+
13
+ # Optional attributes
14
+ config :user, type: String, default: "Lita"
15
+ config :password, type: String
16
+ config :realname, type: String, default: "Lita"
17
+ config :log_level, type: Symbol
18
+ config :cinch do
19
+ validate do |value|
20
+ "must be a callable object" unless value.respond_to?(:call)
21
+ end
22
+ end
10
23
 
11
24
  attr_reader :cinch
12
25
 
@@ -58,42 +71,38 @@ module Lita
58
71
  private
59
72
 
60
73
  def channels
61
- Array(Lita.config.adapter.channels)
62
- end
63
-
64
- def nick
65
- Lita.config.robot.name
74
+ Array(robot.config.adapters.irc.channels)
66
75
  end
67
76
 
68
77
  def configure_cinch
69
78
  Lita.logger.debug("Configuring Cinch.")
70
- cinch.configure do |config|
71
- config.channels = channels
72
- config.nick = nick
73
79
 
74
- Lita.config.adapter.each do |key, value|
75
- next if [:channels, :nick].include?(key.to_sym)
80
+ cinch.configure do |cinch_config|
81
+ config.cinch.call(cinch_config) if config.cinch
82
+
83
+ cinch_config.channels = channels
84
+ cinch_config.server = config.server
85
+ cinch_config.nick = robot.config.robot.name
76
86
 
77
- if config.class::KnownOptions.include?(key)
78
- config.send("#{key}=", value)
79
- end
80
- end
87
+ cinch_config.user = config.user if config.user
88
+ cinch_config.password = config.password if config.password
89
+ cinch_config.realname = config.realname if config.realname
81
90
  end
82
91
  end
83
92
 
84
93
  def configure_logging
85
- if Lita.config.adapter.log_level
86
- cinch.loggers.level = Lita.config.adapter.log_level
94
+ if config.log_level
95
+ cinch.loggers.level = config.log_level
87
96
  else
88
97
  cinch.loggers.clear
89
98
  end
90
99
  end
91
100
 
92
101
  def register_plugin
93
- cinch.configure do |config|
94
- config.plugins.prefix = nil
95
- config.plugins.plugins = [CinchPlugin]
96
- config.plugins.options[CinchPlugin] = { robot: robot }
102
+ cinch.configure do |cinch_config|
103
+ cinch_config.plugins.prefix = nil
104
+ cinch_config.plugins.plugins = [CinchPlugin]
105
+ cinch_config.plugins.options[CinchPlugin] = { robot: robot }
97
106
  end
98
107
  end
99
108
  end
@@ -24,7 +24,7 @@ module Lita
24
24
 
25
25
  def on_invite(m)
26
26
  user = user_by_nick(m.user.nick)
27
- m.channel.join if Lita::Authorization.user_is_admin?(user)
27
+ m.channel.join if robot.auth.user_is_admin?(user)
28
28
  end
29
29
 
30
30
  private
data/lita-irc.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-irc"
3
- spec.version = "1.3.0"
3
+ spec.version = "2.0.0"
4
4
  spec.authors = ["Jimmy Cuadra"]
5
5
  spec.email = ["jimmy@jimmycuadra.com"]
6
6
  spec.description = %q{An IRC adapter for Lita.}
@@ -14,12 +14,12 @@ Gem::Specification.new do |spec|
14
14
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
15
  spec.require_paths = ["lib"]
16
16
 
17
- spec.add_runtime_dependency "lita", ">= 2.5"
17
+ spec.add_runtime_dependency "lita", ">= 4.0"
18
18
  spec.add_runtime_dependency "cinch", ">= 2.0"
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.3"
21
21
  spec.add_development_dependency "rake"
22
- spec.add_development_dependency "rspec", ">= 3.0.0.beta2"
22
+ spec.add_development_dependency "rspec", ">= 3.0.0"
23
23
  spec.add_development_dependency "simplecov"
24
24
  spec.add_development_dependency "coveralls"
25
25
  end
@@ -3,7 +3,8 @@ require "spec_helper"
3
3
  describe Lita::Adapters::IRC::CinchPlugin do
4
4
  subject { described_class.new(cinch) }
5
5
 
6
- let(:robot) { double("Lita::Robot") }
6
+ let(:authorization) { instance_double("Lita::Authorization") }
7
+ let(:robot) { double("Lita::Robot", auth: authorization) }
7
8
  let(:cinch) { double("Cinch::Bot").as_null_object }
8
9
  let(:user) { double("Lita::User", name: "Carl") }
9
10
  let(:message) { double("Lita::Message", command!: nil, source: source) }
@@ -64,9 +65,13 @@ describe Lita::Adapters::IRC::CinchPlugin do
64
65
  end
65
66
 
66
67
  describe "#on_invite" do
68
+ before do
69
+ allow(authorization).to receive(:user_is_admin?).and_return(false)
70
+ end
71
+
67
72
  it "joins the room if the invite came from an admin" do
68
73
  allow(subject).to receive(:user_by_nick).and_return(user)
69
- allow(Lita::Authorization).to receive(:user_is_admin?).with(user).and_return(true)
74
+ allow(authorization).to receive(:user_is_admin?).with(user).and_return(true)
70
75
  expect(invite_m.channel).to receive(:join)
71
76
  subject.on_invite(invite_m)
72
77
  end
@@ -1,19 +1,23 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lita::Adapters::IRC, lita: true do
4
- let(:robot) { instance_double("Lita::Robot") }
4
+ let(:robot) { Lita::Robot.new(registry) }
5
5
 
6
6
  subject { described_class.new(robot) }
7
7
 
8
8
  before do
9
- Lita.configure do |config|
10
- config.adapter.server = "irc.example.com"
11
- config.adapter.channels = "#lita"
12
- config.adapter.user = "litabot"
13
- config.adapter.password = "secret"
14
- config.adapter.realname = "Lita the Robot"
15
- config.adapter.nick = "NotLita"
16
- config.adapter.max_reconnect_delay = 123
9
+ registry.register_adapter(:irc, described_class)
10
+
11
+ registry.configure do |config|
12
+ config.adapters.irc.server = "irc.example.com"
13
+ config.adapters.irc.channels = "#lita"
14
+ config.adapters.irc.user = "litabot"
15
+ config.adapters.irc.password = "secret"
16
+ config.adapters.irc.realname = "Lita the Robot"
17
+ config.adapters.irc.cinch = lambda do |c|
18
+ c.nick = "NotLita"
19
+ c.sasl.username = "sasl username"
20
+ end
17
21
  end
18
22
  end
19
23
 
@@ -21,12 +25,6 @@ describe Lita::Adapters::IRC, lita: true do
21
25
  expect(Lita.adapters[:irc]).to eql(described_class)
22
26
  end
23
27
 
24
- it "requires a server and channels" do
25
- Lita.clear_config
26
- expect(Lita.logger).to receive(:fatal).with(/server, channels/)
27
- expect { subject }.to raise_error(SystemExit)
28
- end
29
-
30
28
  it "configures Cinch" do
31
29
  subject.cinch.config.tap do |config|
32
30
  expect(config.nick).to eq("Lita")
@@ -35,7 +33,7 @@ describe Lita::Adapters::IRC, lita: true do
35
33
  expect(config.user).to eq("litabot")
36
34
  expect(config.password).to eq("secret")
37
35
  expect(config.realname).to eq("Lita the Robot")
38
- expect(config.max_reconnect_delay).to eq(123)
36
+ expect(config.sasl.username).to eq("sasl username")
39
37
  end
40
38
  end
41
39
 
@@ -44,7 +42,7 @@ describe Lita::Adapters::IRC, lita: true do
44
42
  end
45
43
 
46
44
  it "turns Cinch's logging on if config.adapter.log_level is set" do
47
- Lita.config.adapter.log_level = :debug
45
+ registry.config.adapters.irc.log_level = :debug
48
46
  expect(subject.cinch.loggers).not_to be_empty
49
47
  end
50
48
 
data/spec/spec_helper.rb CHANGED
@@ -8,3 +8,5 @@ SimpleCov.start { add_filter "/spec/" }
8
8
 
9
9
  require "lita-irc"
10
10
  require "lita/rspec"
11
+
12
+ Lita.version_3_compatibility_mode = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-irc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Cuadra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-23 00:00:00.000000000 Z
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.5'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.5'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cinch
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 3.0.0.beta2
75
+ version: 3.0.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 3.0.0.beta2
82
+ version: 3.0.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 2.2.0
152
+ rubygems_version: 2.2.2
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: An IRC adapter for the Lita chat robot.
@@ -157,4 +157,3 @@ test_files:
157
157
  - spec/lita/adapters/irc/cinch_plugin_spec.rb
158
158
  - spec/lita/adapters/irc_spec.rb
159
159
  - spec/spec_helper.rb
160
- has_rdoc: