bot 0.0.28 → 0.0.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bot.rb +1 -0
- data/lib/bot/configuration.rb +1 -1
- data/lib/bot/context.rb +42 -0
- data/lib/bot/handler.rb +2 -1
- data/lib/bot/responder.rb +3 -2
- data/lib/bot/version.rb +1 -1
- data/test/dummy/log/test.log +43 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ccf186eafc433707ebd2f1d0c01baf5f7df80f0
|
4
|
+
data.tar.gz: 6282e89eb93a1d0a846a6c5e452630495b4ad989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd7d122593fb198370ebffb9beaeceb08192abd8c4caab112e12b01c2b001525ca337fe428a3ba28f3864dac8dd3cdb0fc1c6b07f384a0fb826d2c0095f3a2dd
|
7
|
+
data.tar.gz: db8eff5f04113b0133bac6f9e49898a6644ca53a20fd94e4817fc91e72cbe6bb5e10dbf75cb250d2e33839a04735d067ec21fe3d59dcb258dea587c09ba3d9b9
|
data/lib/bot.rb
CHANGED
data/lib/bot/configuration.rb
CHANGED
data/lib/bot/context.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Bot
|
2
|
+
class Context
|
3
|
+
attr_accessor :redis_client, :user
|
4
|
+
|
5
|
+
def initialize(user, redis_client)
|
6
|
+
@redis_client = redis_client
|
7
|
+
@user = user
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(m, *args, &block)
|
11
|
+
if m =~ /.+=/
|
12
|
+
self.add(m.to_s.gsub('=', ''), *args)
|
13
|
+
else
|
14
|
+
self.get(m)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(field)
|
19
|
+
data = $redis.hget(context_key, field)
|
20
|
+
JSON.parse(data) if data.present?
|
21
|
+
rescue JSON::ParserError
|
22
|
+
data
|
23
|
+
end
|
24
|
+
|
25
|
+
def set(context)
|
26
|
+
self.clear
|
27
|
+
$redis.hmset(context_key, context.map { |k, v| [k, v] }.flatten)
|
28
|
+
end
|
29
|
+
|
30
|
+
def add(field, content)
|
31
|
+
$redis.hset context_key, field, content
|
32
|
+
end
|
33
|
+
|
34
|
+
def clear
|
35
|
+
$redis.del context_key
|
36
|
+
end
|
37
|
+
|
38
|
+
def context_key
|
39
|
+
"bot:context:#{user.id}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/bot/handler.rb
CHANGED
@@ -15,8 +15,9 @@ module Bot
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def execute_chain(message, responses, user)
|
18
|
+
context = Bot::Context.new(user, Bot.configuration.redis)
|
18
19
|
responder_chain.responders.each do |responder|
|
19
|
-
responder = responder.new(message, user, responses, self)
|
20
|
+
responder = responder.new(message, user, responses, self, context)
|
20
21
|
if responder.can_respond_to_type?(message['type']) && responder.can_handle?
|
21
22
|
responses << responder.handle
|
22
23
|
break
|
data/lib/bot/responder.rb
CHANGED
@@ -5,7 +5,7 @@ module Bot
|
|
5
5
|
|
6
6
|
class_attribute :respond_to_types
|
7
7
|
|
8
|
-
attr_reader :message, :user, :responses, :handler
|
8
|
+
attr_reader :message, :user, :responses, :handler, :context
|
9
9
|
|
10
10
|
def self.respond_to(*types)
|
11
11
|
new_types = (respond_to_types || []).dup
|
@@ -13,11 +13,12 @@ module Bot
|
|
13
13
|
self.respond_to_types = new_types.freeze
|
14
14
|
end
|
15
15
|
|
16
|
-
def initialize(message, user, responses, handler)
|
16
|
+
def initialize(message, user, responses, handler, context)
|
17
17
|
@message = message
|
18
18
|
@user = user
|
19
19
|
@responses = responses
|
20
20
|
@handler = handler
|
21
|
+
@context = context
|
21
22
|
end
|
22
23
|
|
23
24
|
def can_respond_to_type?(type)
|
data/lib/bot/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -2902,6 +2902,49 @@ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
|
|
2902
2902
|
NavigationTest: test_notify_special_types
|
2903
2903
|
-----------------------------------------
|
2904
2904
|
Started POST "/bot/notify" for 127.0.0.1 at 2016-04-21 14:45:54 -0400
|
2905
|
+
Processing by Bot::BotController#notify as HTML
|
2906
|
+
Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
|
2907
|
+
Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
|
2908
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2909
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
2910
|
+
[1m[36m (1.0ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
2911
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
2912
|
+
[1m[36m (0.8ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
2913
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
2914
|
+
[1m[36m (0.8ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
2915
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
2916
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2917
|
+
-------------------
|
2918
|
+
BotTest: test_truth
|
2919
|
+
-------------------
|
2920
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
2921
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
2922
|
+
---------------------------------------
|
2923
|
+
NavigationTest: test_notify_multi_types
|
2924
|
+
---------------------------------------
|
2925
|
+
Started POST "/bot/notify" for 127.0.0.1 at 2016-04-27 21:12:56 -0400
|
2926
|
+
Processing by Bot::BotController#notify as HTML
|
2927
|
+
Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
|
2928
|
+
Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms)
|
2929
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2930
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2931
|
+
---------------------------
|
2932
|
+
NavigationTest: test_notify
|
2933
|
+
---------------------------
|
2934
|
+
Started POST "/bot/notify" for 127.0.0.1 at 2016-04-27 21:12:56 -0400
|
2935
|
+
Processing by Bot::BotController#notify as HTML
|
2936
|
+
Parameters: {"bot"=>ApplicationHandler}
|
2937
|
+
Completed 200 OK in 0ms (Views: 0.2ms | ActiveRecord: 0.0ms)
|
2938
|
+
Started POST "/bot/notify" for 127.0.0.1 at 2016-04-27 21:12:56 -0400
|
2939
|
+
Processing by Bot::BotController#notify as HTML
|
2940
|
+
Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
|
2941
|
+
Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
|
2942
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
2943
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
2944
|
+
-----------------------------------------
|
2945
|
+
NavigationTest: test_notify_special_types
|
2946
|
+
-----------------------------------------
|
2947
|
+
Started POST "/bot/notify" for 127.0.0.1 at 2016-04-27 21:12:56 -0400
|
2905
2948
|
Processing by Bot::BotController#notify as HTML
|
2906
2949
|
Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
|
2907
2950
|
Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.8.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redis
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +109,7 @@ files:
|
|
95
109
|
- lib/bot/adapters/kik.rb
|
96
110
|
- lib/bot/adapters/test.rb
|
97
111
|
- lib/bot/configuration.rb
|
112
|
+
- lib/bot/context.rb
|
98
113
|
- lib/bot/engine.rb
|
99
114
|
- lib/bot/handler.rb
|
100
115
|
- lib/bot/responder.rb
|