lita-tell_on_wake 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: 4c2c2fb1572f30a75878c67ab0c9aa06b77f4717
4
+ data.tar.gz: ac06cd5f218615745f1e94289935a44673f30167
5
+ SHA512:
6
+ metadata.gz: ba01f7390ed78b76b94a45f7b15f2958bc18ef045a7169cb47b29862d6823c11662db25f2b298b52917d4b48bc7ef9cf0be05e7d55cc58dcc965f66dd90ee7f4
7
+ data.tar.gz: 3928a777e9b643d65270994ffaf914f274c534daf7a04a8c60240b6275acd3b13d8d54389294614cd515ea94c5e4cc3f7443154238197b32957b05cb79e98f89
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,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Denis <Zaratan> Pasin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # lita-tell_on_wake
2
+
3
+ Allow you to enqueue a message for the next time a user act.
4
+
5
+ ## Installation
6
+
7
+ Add lita-tell_on_wake to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "lita-tell_on_wake"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ !tell somebody something => enqueue something for somebody
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,13 @@
1
+ require "lita"
2
+ require "redis-objects"
3
+
4
+ Lita.load_locales Dir[File.expand_path(
5
+ File.join("..", "..", "locales", "*.yml"), __FILE__
6
+ )]
7
+
8
+ require "lita/handlers/tell_on_wake"
9
+
10
+ Lita::Handlers::TellOnWake.template_root File.expand_path(
11
+ File.join("..", "..", "templates"),
12
+ __FILE__
13
+ )
@@ -0,0 +1,45 @@
1
+ module Lita
2
+ module Handlers
3
+ class TellOnWake < Handler
4
+ attr_accessor :response
5
+
6
+ # insert handler code here
7
+ route(//, :send_tell)
8
+ on(:user_joined_room, :send_tell)
9
+
10
+ def send_tell(r)
11
+ @response = r
12
+ @user_name = r.user.name
13
+ user_list.each do |tell|
14
+ r.reply_privately(t("tell", message: tell[:message], user: tell[:user], time: tell[:time]))
15
+ end
16
+ user_list.clear
17
+ end
18
+
19
+ route(/^tell\s+(?<user>\S+)\s+(?<message>\S.*)/, :store_tell, command: true, help:{
20
+ "tell somebody something" => "Tell something to somebody as soon as he acts again"
21
+ })
22
+
23
+ def store_tell(r)
24
+ @response = r
25
+ @user_name = r.match_data[:user]
26
+ add_to_user_list(r.match_data[:message])
27
+ r.reply(t("success_enqueue", user_name: @user_name))
28
+ end
29
+
30
+ def user_list
31
+ Redis::List.new(user_find.name, redis, marshal: true)
32
+ end
33
+
34
+ def add_to_user_list(message)
35
+ user_list << {message: message, user: response.user.name, time: Time.now.to_s}
36
+ end
37
+
38
+ def user_find
39
+ @user_find ||= User.fuzzy_find(@user_name)
40
+ end
41
+
42
+ Lita.register_handler(self)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-tell_on_wake"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Zaratan"]
5
+ spec.email = ["denis.pasin@gmail.com"]
6
+ spec.description = "A plugin to enqueue messages for someone"
7
+ spec.summary = "Enqueue messages for away peoples"
8
+ spec.metadata = { "lita_plugin_type" => "handler" }
9
+
10
+ spec.files = `git ls-files`.split($/)
11
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
12
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
13
+ spec.require_paths = ["lib"]
14
+
15
+ spec.add_runtime_dependency "lita", ">= 4.6"
16
+
17
+ spec.add_dependency "redis-objects"
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,6 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ tell_on_wake:
5
+ success_enqueue: "Ok! I'll tell this to %{user_name} as soon as he wakes up :)"
6
+ tell: "Hey! %{user} asked me to tell you: %{message} at %{time}"
data/locales/fr.yml ADDED
@@ -0,0 +1,6 @@
1
+ fr:
2
+ lita:
3
+ handlers:
4
+ tell_on_wake:
5
+ success_enqueue: "Ok! Je dirai ça à %{user_name} dès qu'il se reveillera :)"
6
+ tell: "Hey! %{user} m'a demandé de te dire: %{message} à %{time}"
@@ -0,0 +1,79 @@
1
+ require "spec_helper"
2
+
3
+ def mod
4
+ Lita::Handlers::TellOnWake.new("")
5
+ end
6
+
7
+ def redis
8
+ mod.redis
9
+ end
10
+
11
+ def redis_list(key)
12
+ Redis::List.new(key, redis, marshal: true)
13
+ end
14
+
15
+ describe Lita::Handlers::TellOnWake, lita_handler: true do
16
+ let(:sender) {Lita::User.create("1234", name: "Skizzk")}
17
+ let(:user) {Lita::User.create("1235", name: "Zaratan")}
18
+ let(:now) {Time.now}
19
+
20
+ before do
21
+ allow(Time).to receive(:now).and_return(now)
22
+ end
23
+
24
+ it { is_expected.to route_command("tell zaratan il love apple").to(:store_tell) }
25
+ it { is_expected.to route_event(:user_joined_room).to(:send_tell) }
26
+ it { is_expected.to route("anything").to(:send_tell) }
27
+
28
+ subject do
29
+ send_command("tell #{user.name} I love you", as: sender)
30
+ end
31
+
32
+ it "stores tell messages for later" do
33
+ subject
34
+ expect(redis_list(user.name).first).to eq({message: "I love you", user: sender.name, time: now.to_s})
35
+ end
36
+
37
+ it "responds a succesfull message" do
38
+ expect{subject}.to change{replies}.to([mod.t("success_enqueue", user_name: user.name)])
39
+ end
40
+
41
+ context "when a user act" do
42
+ subject do
43
+ send_message("anything", as: user)
44
+ end
45
+
46
+ context "a tell message for that user is stored" do
47
+ before do
48
+ redis_list(user.name) << {message: "message 1", user: sender.name, time: now.to_s}
49
+ end
50
+
51
+ it "sends privately this message for that user" do
52
+ expect{subject}.to change{replies}.to([mod.t("tell", message: "message 1", user: sender.name, time: now.to_s)])
53
+ end
54
+ end
55
+
56
+ context "more than one message is stored" do
57
+ before do
58
+ redis_list(user.name) << {message: "message 1", user: sender.name, time: now.to_s}
59
+ redis_list(user.name) << {message: "message 2", user: sender.name, time: now.to_s}
60
+ end
61
+
62
+ it "sends them in the right order" do
63
+ expect{subject}.to change{replies.first}.to(mod.t("tell", message: "message 1", user: sender.name, time: now.to_s))
64
+ expect(redis_list(user.name)).to be_empty
65
+ end
66
+ end
67
+
68
+ context "no tell message is stored" do
69
+ before do
70
+ redis_list("NOT_THIS_USER") << {message: "message 1", user: sender.name, time: now.to_s}
71
+ end
72
+
73
+ it "doesn't do anything" do
74
+ expect{subject}.not_to change{replies}
75
+ expect(redis_list("NOT_THIS_USER")).not_to be_empty
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-tell_on_wake"
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
File without changes
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-tell_on_wake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zaratan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-10 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: redis-objects
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
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: rake
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: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ description: A plugin to enqueue messages for someone
112
+ email:
113
+ - denis.pasin@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - lib/lita-tell_on_wake.rb
124
+ - lib/lita/handlers/tell_on_wake.rb
125
+ - lita-tell_on_wake.gemspec
126
+ - locales/en.yml
127
+ - locales/fr.yml
128
+ - spec/lita/handlers/tell_on_wake_spec.rb
129
+ - spec/spec_helper.rb
130
+ - templates/.gitkeep
131
+ homepage:
132
+ licenses: []
133
+ metadata:
134
+ lita_plugin_type: handler
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.4.8
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Enqueue messages for away peoples
155
+ test_files:
156
+ - spec/lita/handlers/tell_on_wake_spec.rb
157
+ - spec/spec_helper.rb
158
+ has_rdoc: