ant-bot 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4e8ae082331aa86f94717547ed3ac9a4fd97182269363d3e280260d9cac9971
4
- data.tar.gz: 2e19ddde3d123d08770e89c6b3a33ea8f745c365c812df04400e339a95763543
3
+ metadata.gz: '058d507b156e5fc4f90482b9c95f777f68dd65be8a7160c6e478a0dbcc213ec7'
4
+ data.tar.gz: ef88a1c02647e4cc7f67bbb1f2365648b4110f5d8b078914e721f4997e73e6e0
5
5
  SHA512:
6
- metadata.gz: d80353dd1bb1a77abfefbdbe7855981f119fd32f1de1c967b7644f6f4d98a0953b7c44e6ac4357c44a05c53e89f99237bcd68ad4e8bc59d959cd620048ec8c26
7
- data.tar.gz: a3056348c47d1b6d7e4057dbc4dffafff1cd792201ac42d73efe038187fb49ffb1bd193af9bd8954f587f84c4744d1c33a4cdf58fe63d5e9919da8f8c9b89312
6
+ metadata.gz: 29f4f960337048c5f4908c0d24312d568965b77ce001af58424b455fbe2e0a36843f50a066500f35f722e86b617ed6d825df4f0a09cc19be868517d20e4573c8
7
+ data.tar.gz: 551a31a6c3a7258fa903d76ff8b371e9b0c53a84e7560f5d4136297a6c163892de20a8180df3ae1dc9ab65ca186aca20d6e3f02068677754e0b791101a7ac9d5
@@ -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
- { 'name' => 'json',
32
- 'schema_name' => configs['name'],
33
- 'storage' => 'storage/$name',
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ant
4
4
  module Bot
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
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.1.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-10-07 00:00:00.000000000 Z
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.3
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