lita-irc 2.0.0 → 2.0.1

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: 4395b1f99ddbd742dd59d2393d3e396671167cdb
4
- data.tar.gz: a3eb5703529d4b9498b0a4ab8d8e0154da14b345
3
+ metadata.gz: d008c249ad6a0aae3dc19bf9681693c9c6360a80
4
+ data.tar.gz: 510f7748da4c91ff57c0a73eba7cb36904a84f14
5
5
  SHA512:
6
- metadata.gz: f0eed00861cc230928a47ff74d087fe6c477a6b577cd6658f1ae66d2bcee0c432b4c825f4ba4baa22da5eca3cba4a7fbf9ad88ca723c3a29118c872ef5f9efc5
7
- data.tar.gz: 1bc336e4c560da4740dbc342c06e1206d39182c3955d5c414cbdfb6fad360b6d96287ed4993af4af5abe62528481b6a1372b20d7c4a874fce6777cbaa3df3206
6
+ metadata.gz: 1ac5471086cb01b57eb79c0a047f0033f58bdbdcafb376c0ff683ca93f5798f3fab19ef3f35f23239a6b5f3198f0a5639accc2e856a55ee6a64d126b884b6e96
7
+ data.tar.gz: bd2539f901083fbeaa6b7dde60b7a789f4f4143ac4c2c58b49e7351a97126655ccb1e96ca95678feb407306a76dc266f165b07d12ce07f039a382fcaac4d02ad
data/README.md CHANGED
@@ -28,18 +28,23 @@ gem "lita-irc"
28
28
  * `realname` (String) - The "real name" field for Lita's IRC account. Default: `"Lita"`.
29
29
  * `log_level` (Symbol) - Sets the log level for Cinch's loggers. By default, Cinch's loggers are disabled. Default: `nil`.
30
30
 
31
- **Note**: `config.robot.name` is used as Lita's IRC nickname. `config.adapters.irc.nick` is ignored.
32
-
33
31
  ### Additional Cinch options
34
32
 
35
33
  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.
36
34
 
35
+ **Note**: `config.robot.name` is used as Lita's IRC nickname. The `nick` attribute of the Cinch options is overwritten with this value.
36
+
37
+ ### config.robot.admins
38
+
39
+ Each IRC user has a unique ID that Lita generates and stores the first time that user is encountered. To populate the `config.robot.admins` attribute, you'll need to use these IDs for each user you want to mark as an administrator. If you're using Lita version 4.1 or greater, you can get a user's ID by sending Lita the command `users find NICKNAME_OF_USER`.
40
+
37
41
  ### Example
38
42
 
39
43
  ``` ruby
40
44
  Lita.configure do |config|
41
45
  config.robot.name = "Lita"
42
46
  config.robot.adapter = :irc
47
+ config.robot.admins = ["eed844bf-2df0-4091-943a-7ee05ef36f4a"]
43
48
  config.adapters.irc.server = "irc.freenode.net"
44
49
  config.adapters.irc.channels = ["#litabot"]
45
50
  config.adapters.irc.user = "Lita"
@@ -47,11 +47,9 @@ module Lita
47
47
 
48
48
  def send_messages(target, strings)
49
49
  if target.private_message?
50
- user = Cinch::User.new(target.user.name, cinch)
51
- strings.each { |s| user.msg(s) }
50
+ send_messages_to_user(target, strings)
52
51
  else
53
- channel = Cinch::Channel.new(target.room, cinch)
54
- strings.each { |s| channel.msg(s) }
52
+ send_messages_to_channel(target, strings)
55
53
  end
56
54
  end
57
55
 
@@ -105,6 +103,26 @@ module Lita
105
103
  cinch_config.plugins.options[CinchPlugin] = { robot: robot }
106
104
  end
107
105
  end
106
+
107
+ def send_message_to_target(target, string)
108
+ string_without_action = string.gsub(/^\/me\s+/i, "")
109
+
110
+ if string == string_without_action
111
+ target.msg(string)
112
+ else
113
+ target.action(string_without_action)
114
+ end
115
+ end
116
+
117
+ def send_messages_to_channel(target, strings)
118
+ channel = Cinch::Channel.new(target.room, cinch)
119
+ strings.each { |string| send_message_to_target(channel, string) }
120
+ end
121
+
122
+ def send_messages_to_user(target, strings)
123
+ user = Cinch::User.new(target.user.name, cinch)
124
+ strings.each { |string| send_message_to_target(user, string) }
125
+ end
108
126
  end
109
127
 
110
128
  Lita.register_adapter(:irc, IRC)
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 = "2.0.0"
3
+ spec.version = "2.0.1"
4
4
  spec.authors = ["Jimmy Cuadra"]
5
5
  spec.email = ["jimmy@jimmycuadra.com"]
6
6
  spec.description = %q{An IRC adapter for Lita.}
@@ -77,6 +77,14 @@ describe Lita::Adapters::IRC, lita: true do
77
77
  subject.send_messages(source, ["Hello!", "How are you?"])
78
78
  end
79
79
 
80
+ it "sends actions to rooms" do
81
+ source = instance_double("Lita::Source", room: "#foo", private_message?: false)
82
+ channel = instance_double("Cinch::Channel")
83
+ allow(Cinch::Channel).to receive(:new).with("#foo", subject.cinch).and_return(channel)
84
+ expect(channel).to receive(:action).with("greets you")
85
+ subject.send_messages(source, ["/me greets you"])
86
+ end
87
+
80
88
  it "sends messages to users" do
81
89
  user = instance_double("Lita::User", name: "Carl")
82
90
  source = instance_double("Lita::Source", user: user, private_message?: true)
@@ -86,6 +94,15 @@ describe Lita::Adapters::IRC, lita: true do
86
94
  expect(user).to receive(:msg).with("How are you?")
87
95
  subject.send_messages(source, ["Hello!", "How are you?"])
88
96
  end
97
+
98
+ it "sends actions to users" do
99
+ user = instance_double("Lita::User", name: "Carl")
100
+ source = instance_double("Lita::Source", user: user, private_message?: true)
101
+ user = instance_double("Cinch::User")
102
+ allow(Cinch::User).to receive(:new).with("Carl", subject.cinch).and_return(user)
103
+ expect(user).to receive(:action).with("greets you")
104
+ subject.send_messages(source, ["/me greets you"])
105
+ end
89
106
  end
90
107
 
91
108
  describe "#set_topic" do
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: 2.0.0
4
+ version: 2.0.1
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-10-23 00:00:00.000000000 Z
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -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.2
152
+ rubygems_version: 2.4.5
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: An IRC adapter for the Lita chat robot.