lita 3.0.4 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/lita/adapter.rb +10 -0
- data/lib/lita/message.rb +9 -0
- data/lib/lita/response.rb +4 -1
- data/lib/lita/robot.rb +20 -0
- data/lib/lita/user.rb +7 -0
- data/lib/lita/version.rb +1 -1
- data/spec/lita/adapter_spec.rb +6 -0
- data/spec/lita/message_spec.rb +17 -8
- data/spec/lita/response_spec.rb +1 -1
- data/spec/lita/robot_spec.rb +39 -0
- data/spec/lita/user_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b317185fd4bf51c66e01de3aef18547d27d154ef
|
4
|
+
data.tar.gz: 0ee25a799c8b033fb82e0e58fe3654ebaf974eea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23c70beb7798a316f725225c17a0b75f8e0fdd2d104e9d9f4c611ae6c423300810adb1c1a9805629287a0db1d27b60071779bd4bf7ecebfbef302a3fde3623f3
|
7
|
+
data.tar.gz: 0498b930d44e0057058a25df985b8117d97de953f76ed89c414c7902482f889db1333b4376665aab01409f60fbcc55ae6fb3159594432cbfac0944b4bd8c9168
|
data/README.md
CHANGED
@@ -13,13 +13,13 @@ Automate your business and have fun with your very own robot companion.
|
|
13
13
|
|
14
14
|
## Documentation
|
15
15
|
|
16
|
-
Please visit [lita.io](
|
16
|
+
Please visit [lita.io](https://www.lita.io/) for comprehensive documentation.
|
17
17
|
|
18
18
|
## Plugins
|
19
19
|
|
20
|
-
A list of all publicly available Lita plugins is available on the [lita.io plugins page](
|
20
|
+
A list of all publicly available Lita plugins is available on the [lita.io plugins page](https://www.lita.io/plugins).
|
21
21
|
|
22
|
-
The plugins page automatically updates daily with information from RubyGems. See [publishing](
|
22
|
+
The plugins page automatically updates daily with information from RubyGems. See [publishing](https://www.lita.io/plugin-authoring#publishing) for more information.
|
23
23
|
|
24
24
|
## Contributing
|
25
25
|
|
data/lib/lita/adapter.rb
CHANGED
@@ -94,6 +94,16 @@ module Lita
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
+
# Formats a name for "mentioning" a user in a group chat. Override this
|
98
|
+
# method in child classes to customize the mention format for the chat
|
99
|
+
# service.
|
100
|
+
# @param name [String] The name to format as a mention name.
|
101
|
+
# @return [String] The formatted mention name.
|
102
|
+
# @since 3.1.0
|
103
|
+
def mention_format(name)
|
104
|
+
"#{name}:"
|
105
|
+
end
|
106
|
+
|
97
107
|
# @see .translate
|
98
108
|
def translate(*args)
|
99
109
|
self.class.translate(*args)
|
data/lib/lita/message.rb
CHANGED
@@ -81,5 +81,14 @@ module Lita
|
|
81
81
|
private_source.private_message!
|
82
82
|
@robot.send_messages(private_source, *strings)
|
83
83
|
end
|
84
|
+
|
85
|
+
# Replies by sending the given strings back to the source of the message.
|
86
|
+
# Each message is prefixed with the user's mention name.
|
87
|
+
# @param strings [String, Array<String>] The strings to send back.
|
88
|
+
# @return [void]
|
89
|
+
# @since 3.1.0
|
90
|
+
def reply_with_mention(*strings)
|
91
|
+
@robot.send_messages_with_mention(source, *strings)
|
92
|
+
end
|
84
93
|
end
|
85
94
|
end
|
data/lib/lita/response.rb
CHANGED
@@ -18,9 +18,12 @@ module Lita
|
|
18
18
|
# @see Lita::Message#reply
|
19
19
|
# @!method reply_privately
|
20
20
|
# @see Lita::Message#reply_privately
|
21
|
+
# @!method reply_with_mention
|
22
|
+
# @see Lita::Message#reply_with_mention
|
21
23
|
# @!method user
|
22
24
|
# @see Lita::Message#user
|
23
|
-
def_delegators :message, :args, :reply, :reply_privately,
|
25
|
+
def_delegators :message, :args, :reply, :reply_privately,
|
26
|
+
:reply_with_mention, :user, :command?
|
24
27
|
|
25
28
|
# @param message [Lita::Message] The incoming message.
|
26
29
|
# @param pattern [Regexp] The pattern the incoming message matched.
|
data/lib/lita/robot.rb
CHANGED
@@ -76,6 +76,26 @@ module Lita
|
|
76
76
|
end
|
77
77
|
alias_method :send_message, :send_messages
|
78
78
|
|
79
|
+
# Sends one or more messages to a user or room. If sending to a room,
|
80
|
+
# prefixes each message with the user's mention name.
|
81
|
+
# @param target [Lita::Source] The user or room to send to. If the Source
|
82
|
+
# has a room, it will choose the room. Otherwise, it will send to the
|
83
|
+
# user.
|
84
|
+
# @param strings [String, Array<String>] One or more strings to send.
|
85
|
+
# @return [void]
|
86
|
+
# @since 3.1.0
|
87
|
+
def send_messages_with_mention(target, *strings)
|
88
|
+
return send_messages(target, *strings) if target.private_message?
|
89
|
+
|
90
|
+
mention_name = target.user.mention_name
|
91
|
+
prefixed_strings = strings.map do |s|
|
92
|
+
"#{@adapter.mention_format(mention_name).strip} #{s}"
|
93
|
+
end
|
94
|
+
|
95
|
+
send_messages(target, *prefixed_strings)
|
96
|
+
end
|
97
|
+
alias_method :send_message_with_mention, :send_messages_with_mention
|
98
|
+
|
79
99
|
# Sets the topic for a chat room.
|
80
100
|
# @param target [Lita::Source] A source object specifying the room.
|
81
101
|
# @param topic [String] The new topic message to set.
|
data/lib/lita/user.rb
CHANGED
@@ -99,6 +99,13 @@ module Lita
|
|
99
99
|
ensure_name_metadata_set
|
100
100
|
end
|
101
101
|
|
102
|
+
# The name used to "mention" the user in a group chat.
|
103
|
+
# @return [String] The user's mention name.
|
104
|
+
# @since 3.1.0
|
105
|
+
def mention_name
|
106
|
+
metadata["mention_name"] || name
|
107
|
+
end
|
108
|
+
|
102
109
|
# Saves the user record to Redis, overwriting an previous data for the
|
103
110
|
# current ID and user name.
|
104
111
|
# @return [void]
|
data/lib/lita/version.rb
CHANGED
data/spec/lita/adapter_spec.rb
CHANGED
data/spec/lita/message_spec.rb
CHANGED
@@ -5,8 +5,10 @@ describe Lita::Message do
|
|
5
5
|
instance_double("Lita::Robot", name: "Lita", mention_name: "LitaBot", alias: ".")
|
6
6
|
end
|
7
7
|
|
8
|
+
let(:source) { instance_double("Lita::Source") }
|
9
|
+
|
8
10
|
subject do
|
9
|
-
described_class.new(robot, "Hello",
|
11
|
+
described_class.new(robot, "Hello", source)
|
10
12
|
end
|
11
13
|
|
12
14
|
it "has a body" do
|
@@ -14,17 +16,17 @@ describe Lita::Message do
|
|
14
16
|
end
|
15
17
|
|
16
18
|
it "has a source" do
|
17
|
-
expect(subject.source).to eq(
|
19
|
+
expect(subject.source).to eq(source)
|
18
20
|
end
|
19
21
|
|
20
22
|
describe "#args" do
|
21
23
|
it "returns an array of the 2nd through nth word in the message" do
|
22
|
-
subject = described_class.new(robot, "args foo bar",
|
24
|
+
subject = described_class.new(robot, "args foo bar", source)
|
23
25
|
expect(subject.args).to eq(%w(foo bar))
|
24
26
|
end
|
25
27
|
|
26
28
|
it "escapes messages that have mismatched quotes" do
|
27
|
-
subject = described_class.new(robot, "args it's working",
|
29
|
+
subject = described_class.new(robot, "args it's working", source)
|
28
30
|
expect(subject.args).to eq(%w(it's working))
|
29
31
|
end
|
30
32
|
end
|
@@ -41,7 +43,7 @@ describe Lita::Message do
|
|
41
43
|
subject = described_class.new(
|
42
44
|
robot,
|
43
45
|
"#{robot.mention_name}: hello",
|
44
|
-
|
46
|
+
source
|
45
47
|
)
|
46
48
|
expect(subject).to be_a_command
|
47
49
|
end
|
@@ -50,7 +52,7 @@ describe Lita::Message do
|
|
50
52
|
subject = described_class.new(
|
51
53
|
robot,
|
52
54
|
"#{robot.mention_name.upcase}: hello",
|
53
|
-
|
55
|
+
source
|
54
56
|
)
|
55
57
|
expect(subject).to be_a_command
|
56
58
|
end
|
@@ -59,7 +61,7 @@ describe Lita::Message do
|
|
59
61
|
subject = described_class.new(
|
60
62
|
robot,
|
61
63
|
"#{robot.alias}hello",
|
62
|
-
|
64
|
+
source
|
63
65
|
)
|
64
66
|
expect(subject).to be_a_command
|
65
67
|
end
|
@@ -78,7 +80,7 @@ describe Lita::Message do
|
|
78
80
|
|
79
81
|
describe "#reply" do
|
80
82
|
it "sends strings back to the source through the robot" do
|
81
|
-
expect(robot).to receive(:send_messages).with(
|
83
|
+
expect(robot).to receive(:send_messages).with(source, "foo", "bar")
|
82
84
|
subject.reply("foo", "bar")
|
83
85
|
end
|
84
86
|
end
|
@@ -97,4 +99,11 @@ describe Lita::Message do
|
|
97
99
|
subject.reply_privately("foo", "bar")
|
98
100
|
end
|
99
101
|
end
|
102
|
+
|
103
|
+
describe "#reply_with_mention" do
|
104
|
+
it "prefixes strings with a user mention and sends them back to the source" do
|
105
|
+
expect(robot).to receive(:send_messages_with_mention).with(source, "foo", "bar")
|
106
|
+
subject.reply_with_mention("foo", "bar")
|
107
|
+
end
|
108
|
+
end
|
100
109
|
end
|
data/spec/lita/response_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Lita::Response do
|
|
5
5
|
|
6
6
|
let(:message) { instance_double("Lita::Message").as_null_object }
|
7
7
|
|
8
|
-
[:args, :reply, :user, :command?].each do |method|
|
8
|
+
[:args, :reply, :reply_privately, :reply_with_mention, :user, :command?].each do |method|
|
9
9
|
it "delegates :#{method} to #message" do
|
10
10
|
expect(message).to receive(method)
|
11
11
|
subject.public_send(method)
|
data/spec/lita/robot_spec.rb
CHANGED
@@ -99,6 +99,45 @@ describe Lita::Robot do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
describe "#send_message_with_mention" do
|
103
|
+
let(:user) { instance_double("Lita::User", mention_name: "carl") }
|
104
|
+
let(:source) { instance_double("Lita::Source", private_message?: false, user: user) }
|
105
|
+
|
106
|
+
it "calls #send_message with the strings, prefixed with the user's mention name" do
|
107
|
+
allow_any_instance_of(Lita::Adapters::Shell).to receive(:mention_format).with(
|
108
|
+
"carl"
|
109
|
+
).and_return("carl:")
|
110
|
+
expect_any_instance_of(Lita::Adapters::Shell).to receive(:send_messages).with(
|
111
|
+
source,
|
112
|
+
["carl: foo", "carl: bar"]
|
113
|
+
)
|
114
|
+
|
115
|
+
subject.send_messages_with_mention(source, "foo", "bar")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "strips whitespace from both sides of the formatted mention name" do
|
119
|
+
allow_any_instance_of(Lita::Adapters::Shell).to receive(:mention_format).with(
|
120
|
+
"carl"
|
121
|
+
).and_return(" carl: ")
|
122
|
+
expect_any_instance_of(Lita::Adapters::Shell).to receive(:send_messages).with(
|
123
|
+
source,
|
124
|
+
["carl: foo", "carl: bar"]
|
125
|
+
)
|
126
|
+
|
127
|
+
subject.send_messages_with_mention(source, "foo", "bar")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "calls #send_message directly if the original message was sent privately" do
|
131
|
+
allow(source).to receive(:private_message?).and_return(true)
|
132
|
+
expect_any_instance_of(Lita::Adapters::Shell).to receive(:send_messages).with(
|
133
|
+
source,
|
134
|
+
%w(foo bar)
|
135
|
+
)
|
136
|
+
|
137
|
+
subject.send_messages_with_mention(source, "foo", "bar")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
102
141
|
describe "#set_topic" do
|
103
142
|
let(:source) { instance_double("Lita::Source") }
|
104
143
|
|
data/spec/lita/user_spec.rb
CHANGED
@@ -96,6 +96,18 @@ describe Lita::User, lita: true do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
describe "#mention_name" do
|
100
|
+
it "returns the user's mention name from metadata" do
|
101
|
+
subject = described_class.new(1, name: "Carl", mention_name: "carlthepug")
|
102
|
+
expect(subject.mention_name).to eq("carlthepug")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns the user's name if there is no mention name in the metadata" do
|
106
|
+
subject = described_class.new(1, name: "Carl")
|
107
|
+
expect(subject.mention_name).to eq("Carl")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
99
111
|
describe "#save" do
|
100
112
|
subject { described_class.new(1, name: "Carl", mention_name: "carlthepug") }
|
101
113
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.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-
|
11
|
+
date: 2014-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|