lita-ignore-me 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+ - 2.2
5
+ services:
6
+ - redis-server
7
+ sudo: false
8
+ cache: bundler
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # lita-ignore-me
2
2
 
3
- *lita-ignore-me* is a Lita extension that allows a user to tell the robot that he or she wishes to be ignored unless addressing the robot directly. This means that routes that are triggered that are not commands are not executed.
3
+ [![RubyGems](https://img.shields.io/gem/v/lita-ignore-me.svg)](https://rubygems.org/gems/lita-ignore-me)
4
+ [![Build Status](https://img.shields.io/travis/tessellator/lita-ignore-me/master.svg)](https://travis-ci.org/tessellator/lita-ignore-me)
5
+ [![Code Climate](https://img.shields.io/codeclimate/github/tessellator/lita-ignore-me.svg)](https://codeclimate.com/github/tessellator/lita-ignore-me)
6
+
7
+ **lita-ignore-me** is a Lita extension that allows a user to tell the robot that he or she wishes to be ignored unless addressing the robot directly. This means that routes that are triggered that are not commands are not executed.
4
8
 
5
9
  ## Installation
6
10
 
@@ -12,7 +16,7 @@ spec.add_runtime_dependency "lita-ignore-me"
12
16
 
13
17
  ## Usage
14
18
 
15
- There is no additional configuration necessary. There are two commands added for a user to manage whether the robot will listen to or ignore that user in the current room: `ignore me` and `listen to me.
19
+ There is no additional configuration necessary. There are two commands added for a user to manage whether the robot will listen to or ignore that user in the current room: `ignore me` and `listen to me`.
16
20
 
17
21
  Assuming there is some handler that echoes messages that start with 'echo' installed and configured, a conversation might look like this:
18
22
 
@@ -20,16 +24,18 @@ Assuming there is some handler that echoes messages that start with 'echo' insta
20
24
  Chad: echo I don't like to be echoed.
21
25
  Lita: I don't like to be echoed.
22
26
  Chad: @Lita: ignore me
23
- Lita: Okay Chad, I'll ignore you in #channel unless you address me directly.
27
+ Lita: Okay Chad, I'll ignore you in #room unless you address me directly.
24
28
  Chad: echo I don't like to be echoed.
25
29
  Chad: lita help
26
30
  Lita: *prints help*
27
31
  Chad: @Lita: listen to me
28
- Lita: Okay Chad, I'm listening.
32
+ Lita: Okay Chad, I'm listening to you in #room.
29
33
  Chad: echo I expect to be echoed.
30
34
  Lita: I expect to be echoed.
31
35
  ```
32
36
 
37
+ You can also request that the robot ignore you or listen to you in a different room by specifying the room name (e.g., `ignore me in #some-room`). In the case of Slack, this allows you to send a message to the robot directly, without the need to clutter the target room with extra messages.
38
+
33
39
  ## License
34
40
 
35
41
  [MIT](https://opensource.org/licenses/MIT)
@@ -8,34 +8,80 @@ module Lita
8
8
  "ignore me" => t('ignore_help')
9
9
  })
10
10
 
11
+ route(/^ignore me in (.+)$/i, :ignore_me_in_room, command: true, help: {
12
+ "ignore me in #room" => t('ignore_help_with_room')
13
+ })
14
+
11
15
  route(/^listen to me$/i, :listen_to_me, command: true, help: {
12
16
  "listen to me" => t('listen_help')
13
17
  })
14
18
 
19
+ route(/^listen to me in (.+)$/i, :listen_to_me_in_room, command: true, help: {
20
+ "listen to me in #room" => t('listen_help_with_room')
21
+ })
22
+
23
+ def find_room(response)
24
+ Lita::Room.fuzzy_find(response.matches[0][0])
25
+ end
26
+
15
27
  def ignore_me(response)
16
- source = response.message.source
28
+ ignore_source(response, response.message.source)
29
+ end
30
+
31
+ def ignore_me_in_room(response)
32
+ room = find_room(response)
33
+ user = response.message.source.user
34
+
35
+ if room.nil?
36
+ response.reply t('sorry_no_room', name: user.name)
37
+ else
38
+ source = Lita::Source.new(user: user, room: room)
39
+ ignore_source(response, source)
40
+ end
41
+ end
42
+
43
+ def ignore_source(response, source)
17
44
  name = source.user.name
45
+ room = source.room_object.name
18
46
 
19
47
  if ignored? source
20
- response.reply t('already_ignored', name: name, room: source.room)
48
+ response.reply t('already_ignored', name: name, room: room)
21
49
  else
22
50
  ignore source
23
- response.reply t('ignored', name: name, room: source.room)
51
+ response.reply t('ignored', name: name, room: room)
24
52
  end
25
53
  end
26
54
 
27
55
  def listen_to_me(response)
28
- source = response.message.source
56
+ listen_to_source(response, response.message.source)
57
+ end
58
+
59
+ def listen_to_me_in_room(response)
60
+ room = find_room(response)
61
+ user = response.message.source.user
62
+
63
+ if room.nil?
64
+ response.reply t('sorry_no_room', name: user.name)
65
+ else
66
+ source = Lita::Source.new(user: user, room: room)
67
+ listen_to_source(response, source)
68
+ end
69
+ end
70
+
71
+ def listen_to_source(response, source)
29
72
  name = source.user.name
73
+ room = source.room_object.name
30
74
 
31
75
  if ignored? source
32
76
  heed source
33
- response.reply t('listening', name: name)
77
+ response.reply t('listening', name: name, room: room)
34
78
  else
35
- response.reply t('already_listening', name: name)
79
+ response.reply t('already_listening', name: name, room: room)
36
80
  end
37
81
  end
38
82
 
83
+ private :find_room, :ignore_source, :listen_to_source
84
+
39
85
  end
40
86
 
41
87
  Lita.register_handler(IgnoreMe)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-ignore-me"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Chad Taylor"]
5
5
  spec.email = ["taylor.thomas.c@gmail.com"]
6
6
  spec.description = %q{A Lita extension to ignore a user's non-command messages upon request.}
@@ -14,7 +14,7 @@ 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", ">= 4.6"
17
+ spec.add_runtime_dependency "lita", "~> 4.0"
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.3"
20
20
  spec.add_development_dependency "pry-byebug"
@@ -2,9 +2,12 @@ en:
2
2
  lita:
3
3
  handlers:
4
4
  ignore_me:
5
- ignore_help: Instructs the robot to ignore you unless you address it directly.
6
- listen_help: Instructs the robot to no longer ignore you.
5
+ ignore_help: Instructs the robot to ignore you in the current room unless you address it directly.
6
+ ignore_help_with_room: Instructs the robot to ignore you in the specified room unless you address it directly.
7
+ listen_help: Instructs the robot to no longer ignore you in the current room.
8
+ listen_help_with_room: Instructs the robot to no longer ignore you in the specified room.
7
9
  ignored: "Okay %{name}, I will ignore you in %{room} unless you address me directly."
8
10
  already_ignored: "I'm already ignoring you in %{room}, %{name}."
9
- listening: "Okay %{name}, I'm listening."
10
- already_listening: "Don't worry %{name}, I'm not ignoring you! :heart:"
11
+ listening: "Okay %{name}, I'm listening to you in %{room}."
12
+ already_listening: "Don't worry %{name}, I'm not ignoring you in %{room}! :heart:"
13
+ sorry_no_room: "I'm sorry %{name}, I'm afraid I can't do that. That room doesn't exist."
@@ -9,48 +9,90 @@ describe Echo, lita_handler: true, additional_lita_handlers: Lita::Handlers::Ign
9
9
  before :example do
10
10
  registry.register_hook(:validate_route, Lita::Extensions::IgnoreMe)
11
11
  @bob = Lita::User.create(123, name: "Bob")
12
+ @room_a = Lita::Room.create_or_update("#room-a", name: "#a")
13
+ @room_b = Lita::Room.create_or_update("#room-b", name: "#b")
12
14
  end
13
15
 
14
16
  it "echoes a message from bob" do
15
- send_message(@message, as: @bob, from: "#a")
17
+ send_message(@message, as: @bob, from: @room_a)
16
18
  expect(replies.first).to eq @echo_response
17
19
  end
18
20
 
19
21
  context "bob is ignored in #a" do
20
22
  before do
21
- send_command("ignore me", as: @bob, from: "#a")
23
+ send_command("ignore me", as: @bob, from: @room_a)
22
24
  end
23
25
 
24
26
  it "ignores bob's message in #a" do
25
- send_message(@message, as: @bob, from: "#a")
27
+ send_message(@message, as: @bob, from: @room_a)
26
28
  expect(replies.last).not_to eq @echo_message
27
29
  end
28
30
 
29
31
  it "does not ignore alice's message in #a" do
30
- send_message(@message, as: Lita::User.create(456, name: "alice"), from: "#a")
32
+ send_message(@message, as: Lita::User.create(456, name: "alice"), from: @room_a)
31
33
  expect(replies.last).to eq @echo_response
32
34
  end
33
35
 
34
36
  it "does not ignore bob's message in #b" do
35
- send_message(@message, as: @bob, from: "#b")
37
+ send_message(@message, as: @bob, from: @room_b)
36
38
  expect(replies.last).to eq @echo_response
37
39
  end
38
40
 
39
41
  it "does not ignore bob's command in #a" do
40
- send_command(@message, as: @bob, from: "#a")
42
+ send_command(@message, as: @bob, from: @room_a)
41
43
  expect(replies.last).to eq @echo_response
42
44
  end
43
45
 
44
46
  context "bob turns off ignore in #a" do
45
47
  before do
46
- send_command("listen to me", as: @bob, from: "#a")
48
+ send_command("listen to me", as: @bob, from: @room_a)
47
49
  end
48
50
 
49
51
  it "does not ignore bob's message in #a" do
50
- send_message(@message, as: @bob, from: "#a")
52
+ send_message(@message, as: @bob, from: @room_a)
51
53
  expect(replies.last).to eq @echo_response
52
54
  end
53
55
  end
54
56
 
55
57
  end
58
+
59
+ context "bob requests to be ignored in #b from #a" do
60
+
61
+ before :example do
62
+ send_command("ignore me in #b", as: @bob, from: @room_a)
63
+ end
64
+
65
+ it "does not ignore bob in #a" do
66
+ send_message(@message, as: @bob, from: @room_a)
67
+ expect(replies.last).to eq @echo_response
68
+ end
69
+
70
+ it "ignores bob in #b" do
71
+ send_message(@message, as: @bob, from: @room_b)
72
+ expect(replies.last).not_to eq @echo_response
73
+ end
74
+
75
+ end
76
+
77
+ context "bob requests to be listened to in #b from #a" do
78
+
79
+ before :example do
80
+ send_command("ignore me", as: @bob, from: @room_a)
81
+ send_command("ignore me", as: @bob, from: @room_b)
82
+
83
+ send_command("listen to me in #b", as: @bob, from: @room_a)
84
+ end
85
+
86
+ it "continues to ignore bob in #a" do
87
+ send_message(@message, as: @bob, from: @room_a)
88
+ expect(replies.last).not_to eq @echo_response
89
+ end
90
+
91
+ it "listens to bob in #b" do
92
+ send_message(@message, as: @bob, from: @room_b)
93
+ expect(replies.last).to eq @echo_response
94
+ end
95
+
96
+ end
97
+
56
98
  end
@@ -3,40 +3,59 @@ require "spec_helper"
3
3
  describe Lita::Handlers::IgnoreMe, lita_handler: true do
4
4
  before :example do
5
5
  @bob = Lita::User.create(123, name: "Bob")
6
+ @room_a = Lita::Room.create_or_update("#room-a", name: "#a")
7
+ @room_b = Lita::Room.create_or_update("#room-b", name: "#b")
6
8
  end
7
9
 
8
10
  context "routing" do
9
11
  it { is_expected.to route_command("ignore me").to(:ignore_me) }
10
12
  it { is_expected.to route_command("IGNORE ME").to(:ignore_me) }
13
+ it { is_expected.to route_command("ignore me in #some-room").to(:ignore_me_in_room) }
11
14
 
12
15
  it { is_expected.to route_command("listen to me").to(:listen_to_me) }
13
16
  it { is_expected.to route_command("LISTEN TO ME").to(:listen_to_me) }
17
+ it { is_expected.to route_command("listen to me in #some-room").to(:listen_to_me_in_room) }
14
18
  end
15
19
 
16
20
  context "when bob is not being ignored" do
17
21
  it "tells bob it will ignore him upon request" do
18
- send_command("ignore me", as: @bob, from: "#a")
22
+ send_command("ignore me", as: @bob, from: @room_a)
19
23
  expect(replies.last).to eq "Okay Bob, I will ignore you in #a unless you address me directly."
20
24
  end
21
25
 
26
+ it "tells bob it will ignore him when he asks to be ignored in a different room" do
27
+ send_command("ignore me in #b", as: @bob, from: @room_a)
28
+ expect(replies.last).to eq "Okay Bob, I will ignore you in #b unless you address me directly."
29
+ end
30
+
31
+ it "tells bob it cannot find a non-existent room when he requests to be ignored" do
32
+ send_command("ignore me in #non-room", as: @bob, from: @room_a)
33
+ expect(replies.last).to eq "I'm sorry Bob, I'm afraid I can't do that. That room doesn't exist."
34
+ end
35
+
22
36
  it "tells bob it is not ignoring him if he requests that the robot listen" do
23
- send_command("listen to me", as: @bob, from: "#a")
24
- expect(replies.last).to eq "Don't worry Bob, I'm not ignoring you! :heart:"
37
+ send_command("listen to me", as: @bob, from: @room_a)
38
+ expect(replies.last).to eq "Don't worry Bob, I'm not ignoring you in #a! :heart:"
39
+ end
40
+
41
+ it "tells bob it cannot find a non-existent room when he requests the robot listen" do
42
+ send_command("listen to me in #non-existent", as: @bob, from: @room_a)
43
+ expect(replies.last).to eq "I'm sorry Bob, I'm afraid I can't do that. That room doesn't exist."
25
44
  end
26
45
  end
27
46
 
28
47
  context "when bob is being ignored in #a" do
29
48
  before :example do
30
- send_command("ignore me", as: @bob, from: "#a")
49
+ send_command("ignore me", as: @bob, from: @room_a)
31
50
  end
32
51
 
33
52
  it "tells bob he is no longer ignoring him upon request" do
34
- send_command("listen to me", as: @bob, from: "#a")
35
- expect(replies.last).to eq "Okay Bob, I'm listening."
53
+ send_command("listen to me", as: @bob, from: @room_a)
54
+ expect(replies.last).to eq "Okay Bob, I'm listening to you in #a."
36
55
  end
37
56
 
38
57
  it "tells bob it is already ignoring him if he requests to be ignored" do
39
- send_command("ignore me", as: @bob, from: "#a")
58
+ send_command("ignore me", as: @bob, from: @room_a)
40
59
  expect(replies.last).to eq "I'm already ignoring you in #a, Bob."
41
60
  end
42
61
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-ignore-me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Taylor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-11 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.6'
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: '4.6'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -101,7 +101,10 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".codeclimate.yml"
104
105
  - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
105
108
  - Gemfile
106
109
  - LICENSE
107
110
  - README.md
@@ -136,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
139
  version: '0'
137
140
  requirements: []
138
141
  rubyforge_project:
139
- rubygems_version: 2.4.1
142
+ rubygems_version: 2.5.1
140
143
  signing_key:
141
144
  specification_version: 4
142
145
  summary: A Lita extension that allows a user to tell the robot to ignore him or her