lita-ignore-me 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0de664e9ad8e0e3ad3e38725e8201639327f74ef
4
+ data.tar.gz: d78e8a966ebb3f91b35cd2e8e3173019764a4bf6
5
+ SHA512:
6
+ metadata.gz: cf977197f5de02dccd91438005eed9e50a809468de673cda11f6a8476f69bf8896501b0875694c4b9b6f2a83b2ddf75dd48abb78574d6d4f4a9420090b00b292
7
+ data.tar.gz: 3e80a2a69f22568bc6fdc2bcadf7a6d1d907f91d9e138ac91c357a0acfe98602d3f87f9389e8f9f8e3402f34e2bcacbf01c63fe0068c5e82f56702db648c54a5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2015 Thomas C. Taylor
2
+
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
+
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # lita-ignore-me
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.
4
+
5
+ ## Installation
6
+
7
+ Add lita-ignore-me to your Lita plugin's gemspec:
8
+
9
+ ``` ruby
10
+ spec.add_runtime_dependency "lita-ignore-me"
11
+ ```
12
+
13
+ ## Usage
14
+
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.
16
+
17
+ Assuming there is some handler that echoes messages that start with 'echo' installed and configured, a conversation might look like this:
18
+
19
+ ```
20
+ Chad: echo I don't like to be echoed.
21
+ Lita: I don't like to be echoed.
22
+ Chad: @Lita: ignore me
23
+ Lita: Okay Chad, I'll ignore you in #channel unless you address me directly.
24
+ Chad: echo I don't like to be echoed.
25
+ Chad: lita help
26
+ Lita: *prints help*
27
+ Chad: @Lita: listen to me
28
+ Lita: Okay Chad, I'm listening.
29
+ Chad: echo I expect to be echoed.
30
+ Lita: I expect to be echoed.
31
+ ```
32
+
33
+ ## License
34
+
35
+ [MIT](https://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,9 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/ignore_registry"
8
+ require "lita/extensions/ignore_me"
9
+ require "lita/handlers/ignore_me"
@@ -0,0 +1,14 @@
1
+ module Lita::Extensions
2
+
3
+ class IgnoreMe
4
+ extend Lita::IgnoreRegistry
5
+
6
+ def self.call(payload)
7
+ message = payload.fetch(:message)
8
+ message.command? or not ignored? message.source
9
+ end
10
+
11
+ Lita.register_hook(:validate_route, IgnoreMe)
12
+ end
13
+
14
+ end
@@ -0,0 +1,43 @@
1
+ module Lita
2
+ module Handlers
3
+
4
+ class IgnoreMe < Handler
5
+ include IgnoreRegistry
6
+
7
+ route(/^ignore me$/i, :ignore_me, command: true, help: {
8
+ "ignore me" => t('ignore_help')
9
+ })
10
+
11
+ route(/^listen to me$/i, :listen_to_me, command: true, help: {
12
+ "listen to me" => t('listen_help')
13
+ })
14
+
15
+ def ignore_me(response)
16
+ source = response.message.source
17
+ name = source.user.name
18
+
19
+ if ignored? source
20
+ response.reply t('already_ignored', name: name, room: source.room)
21
+ else
22
+ ignore source
23
+ response.reply t('ignored', name: name, room: source.room)
24
+ end
25
+ end
26
+
27
+ def listen_to_me(response)
28
+ source = response.message.source
29
+ name = source.user.name
30
+
31
+ if ignored? source
32
+ heed source
33
+ response.reply t('listening', name: name)
34
+ else
35
+ response.reply t('already_listening', name: name)
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ Lita.register_handler(IgnoreMe)
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ module Lita
2
+ module IgnoreRegistry
3
+
4
+ def key(source)
5
+ "ignore_me:#{source.room}"
6
+ end
7
+
8
+ def ignored?(source)
9
+ Lita.redis.sismember(key(source), source.user.id)
10
+ end
11
+
12
+ def ignore(source)
13
+ Lita.redis.sadd(key(source), source.user.id)
14
+ end
15
+
16
+ def heed(source)
17
+ Lita.redis.srem(key(source), source.user.id)
18
+ end
19
+
20
+ private :key
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-ignore-me"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Chad Taylor"]
5
+ spec.email = ["taylor.thomas.c@gmail.com"]
6
+ spec.description = %q{A Lita extension to ignore a user's non-command messages upon request.}
7
+ spec.summary = %q{A Lita extension that allows a user to tell the robot to ignore him or her unless that user addresses the robot directly.}
8
+ spec.homepage = "https://github.com/tessellator/lita-ignore-me"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "extension" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.6"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "pry-byebug"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "rspec", ">= 3.0.0"
24
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,10 @@
1
+ en:
2
+ lita:
3
+ handlers:
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.
7
+ ignored: "Okay %{name}, I will ignore you in %{room} unless you address me directly."
8
+ 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:"
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe Echo, lita_handler: true, additional_lita_handlers: Lita::Handlers::IgnoreMe do
4
+ before :context do
5
+ @message = "echo Goodbye, moon!"
6
+ @echo_response = "Goodbye, moon!"
7
+ end
8
+
9
+ before :example do
10
+ registry.register_hook(:validate_route, Lita::Extensions::IgnoreMe)
11
+ @bob = Lita::User.create(123, name: "Bob")
12
+ end
13
+
14
+ it "echoes a message from bob" do
15
+ send_message(@message, as: @bob, from: "#a")
16
+ expect(replies.first).to eq @echo_response
17
+ end
18
+
19
+ context "bob is ignored in #a" do
20
+ before do
21
+ send_command("ignore me", as: @bob, from: "#a")
22
+ end
23
+
24
+ it "ignores bob's message in #a" do
25
+ send_message(@message, as: @bob, from: "#a")
26
+ expect(replies.last).not_to eq @echo_message
27
+ end
28
+
29
+ it "does not ignore alice's message in #a" do
30
+ send_message(@message, as: Lita::User.create(456, name: "alice"), from: "#a")
31
+ expect(replies.last).to eq @echo_response
32
+ end
33
+
34
+ it "does not ignore bob's message in #b" do
35
+ send_message(@message, as: @bob, from: "#b")
36
+ expect(replies.last).to eq @echo_response
37
+ end
38
+
39
+ it "does not ignore bob's command in #a" do
40
+ send_command(@message, as: @bob, from: "#a")
41
+ expect(replies.last).to eq @echo_response
42
+ end
43
+
44
+ context "bob turns off ignore in #a" do
45
+ before do
46
+ send_command("listen to me", as: @bob, from: "#a")
47
+ end
48
+
49
+ it "does not ignore bob's message in #a" do
50
+ send_message(@message, as: @bob, from: "#a")
51
+ expect(replies.last).to eq @echo_response
52
+ end
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::IgnoreMe, lita_handler: true do
4
+ before :example do
5
+ @bob = Lita::User.create(123, name: "Bob")
6
+ end
7
+
8
+ context "routing" do
9
+ it { is_expected.to route_command("ignore me").to(:ignore_me) }
10
+ it { is_expected.to route_command("IGNORE ME").to(:ignore_me) }
11
+
12
+ it { is_expected.to route_command("listen to me").to(:listen_to_me) }
13
+ it { is_expected.to route_command("LISTEN TO ME").to(:listen_to_me) }
14
+ end
15
+
16
+ context "when bob is not being ignored" do
17
+ it "tells bob it will ignore him upon request" do
18
+ send_command("ignore me", as: @bob, from: "#a")
19
+ expect(replies.last).to eq "Okay Bob, I will ignore you in #a unless you address me directly."
20
+ end
21
+
22
+ 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:"
25
+ end
26
+ end
27
+
28
+ context "when bob is being ignored in #a" do
29
+ before :example do
30
+ send_command("ignore me", as: @bob, from: "#a")
31
+ end
32
+
33
+ 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."
36
+ end
37
+
38
+ it "tells bob it is already ignoring him if he requests to be ignored" do
39
+ send_command("ignore me", as: @bob, from: "#a")
40
+ expect(replies.last).to eq "I'm already ignoring you in #a, Bob."
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ require "lita-ignore-me"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
7
+
8
+ class Echo < Lita::Handler
9
+
10
+ route(/echo\s+(.+)/, :echo)
11
+
12
+ def echo(response)
13
+ response.reply(response.matches)
14
+ end
15
+
16
+ end
17
+
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-ignore-me
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chad Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ description: A Lita extension to ignore a user's non-command messages upon request.
98
+ email:
99
+ - taylor.thomas.c@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - lib/lita-ignore-me.rb
110
+ - lib/lita/extensions/ignore_me.rb
111
+ - lib/lita/handlers/ignore_me.rb
112
+ - lib/lita/ignore_registry.rb
113
+ - lita-ignore-me.gemspec
114
+ - locales/en.yml
115
+ - spec/lita/extensions/ignore_me_spec.rb
116
+ - spec/lita/handlers/ignore_me_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: https://github.com/tessellator/lita-ignore-me
119
+ licenses:
120
+ - MIT
121
+ metadata:
122
+ lita_plugin_type: extension
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: A Lita extension that allows a user to tell the robot to ignore him or her
143
+ unless that user addresses the robot directly.
144
+ test_files:
145
+ - spec/lita/extensions/ignore_me_spec.rb
146
+ - spec/lita/handlers/ignore_me_spec.rb
147
+ - spec/spec_helper.rb