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 +4 -4
- data/README.md +7 -2
- data/lib/lita/adapters/irc.rb +22 -4
- data/lita-irc.gemspec +1 -1
- data/spec/lita/adapters/irc_spec.rb +17 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d008c249ad6a0aae3dc19bf9681693c9c6360a80
|
4
|
+
data.tar.gz: 510f7748da4c91ff57c0a73eba7cb36904a84f14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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"
|
data/lib/lita/adapters/irc.rb
CHANGED
@@ -47,11 +47,9 @@ module Lita
|
|
47
47
|
|
48
48
|
def send_messages(target, strings)
|
49
49
|
if target.private_message?
|
50
|
-
|
51
|
-
strings.each { |s| user.msg(s) }
|
50
|
+
send_messages_to_user(target, strings)
|
52
51
|
else
|
53
|
-
|
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
@@ -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.
|
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:
|
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.
|
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.
|