ant-bot 0.1.0 → 0.2.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/lib/ant/bot/base.rb +15 -7
- data/lib/ant/bot/migrator.rb +18 -0
- data/lib/ant/bot/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '058d507b156e5fc4f90482b9c95f777f68dd65be8a7160c6e478a0dbcc213ec7'
|
4
|
+
data.tar.gz: ef88a1c02647e4cc7f67bbb1f2365648b4110f5d8b078914e721f4997e73e6e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29f4f960337048c5f4908c0d24312d568965b77ce001af58424b455fbe2e0a36843f50a066500f35f722e86b617ed6d825df4f0a09cc19be868517d20e4573c8
|
7
|
+
data.tar.gz: 551a31a6c3a7258fa903d76ff8b371e9b0c53a84e7560f5d4136297a6c163892de20a8180df3ae1dc9ab65ca186aca20d6e3f02068677754e0b791101a7ac9d5
|
data/lib/ant/bot/base.rb
CHANGED
@@ -28,10 +28,9 @@ module Ant
|
|
28
28
|
# TODO: move this to config
|
29
29
|
@repository = Ant::Storage::Repository.from_config(
|
30
30
|
nil,
|
31
|
-
|
32
|
-
'
|
33
|
-
|
34
|
-
'primary_key' => 'channel_id' },
|
31
|
+
configs['state_repository']
|
32
|
+
.merge('primary_key' => 'channel_id',
|
33
|
+
'table' => 'bot_sessions'),
|
35
34
|
{}
|
36
35
|
)
|
37
36
|
@factory = Ant::Storage::Factory.new(EmptyModel)
|
@@ -39,6 +38,10 @@ module Ant
|
|
39
38
|
@factory.register(:json, @repository)
|
40
39
|
end
|
41
40
|
|
41
|
+
def session
|
42
|
+
@repository.connection
|
43
|
+
end
|
44
|
+
|
42
45
|
# Starts the bot execution, this is a blocking call.
|
43
46
|
def run
|
44
47
|
@pool = Array.new(@pool_size) do
|
@@ -131,7 +134,7 @@ module Ant
|
|
131
134
|
log_debug('I\'m going to ask the next param', param: param)
|
132
135
|
@provider.send_message(current_channel,
|
133
136
|
"I need you to tell me #{param}")
|
134
|
-
@state[:requested_param] = param
|
137
|
+
@state[:requested_param] = param.to_s
|
135
138
|
end
|
136
139
|
|
137
140
|
# Stores a parameter into the status
|
@@ -150,14 +153,19 @@ module Ant
|
|
150
153
|
|
151
154
|
# Private implementation for load message
|
152
155
|
def load_state(channel)
|
153
|
-
@factory.get(channel)
|
156
|
+
data = @factory.get(channel)
|
157
|
+
data[:params] = JSON.parse(data[:params], symbolize_names: true)
|
158
|
+
data
|
154
159
|
rescue Ant::Storage::Exceptions::ObjectNotFound
|
155
|
-
@factory.create(channel_id: channel, params: {})
|
160
|
+
@factory.create(channel_id: channel, params: {}.to_json)
|
156
161
|
end
|
157
162
|
|
158
163
|
# Saves the state into storage
|
159
164
|
def save_state!
|
165
|
+
json = @state[:params]
|
166
|
+
@state[:params] = json.to_json
|
160
167
|
@state.store
|
168
|
+
@state[:params] = json
|
161
169
|
end
|
162
170
|
end
|
163
171
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
require 'sequel/extensions/migration'
|
3
|
+
module Ant
|
4
|
+
module Bot
|
5
|
+
module Migrator
|
6
|
+
class << self
|
7
|
+
def run_migrations!(conn)
|
8
|
+
conn.create_table?(:bot_sessions) do
|
9
|
+
String :channel_id, primary: true
|
10
|
+
String :params, text: true
|
11
|
+
String :cmd
|
12
|
+
String :requested_param
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/ant/bot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ant-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilberto Vargas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ant-core
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- lib/ant/bot/base.rb
|
179
179
|
- lib/ant/bot/command_definition.rb
|
180
180
|
- lib/ant/bot/message.rb
|
181
|
+
- lib/ant/bot/migrator.rb
|
181
182
|
- lib/ant/bot/version.rb
|
182
183
|
homepage: https://github.com/tachomex/ant
|
183
184
|
licenses:
|
@@ -198,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
199
|
- !ruby/object:Gem::Version
|
199
200
|
version: '0'
|
200
201
|
requirements: []
|
201
|
-
rubygems_version: 3.0.
|
202
|
+
rubygems_version: 3.0.1
|
202
203
|
signing_key:
|
203
204
|
specification_version: 4
|
204
205
|
summary: Provides a framework for building bots with ruby
|