rbender 0.7.3 → 0.7.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a793668dab825c522287f029506745b94cd5cf86d5aba5af6a5ca8bc59525389
4
- data.tar.gz: fcacdcb1c9990bf38b6089546dacd78a7ca57c95856bb8799a6396ed104ffb2f
3
+ metadata.gz: '021865fb9c70360011b3cac07f982b46610f277470ec018ae4a793777b2a3335'
4
+ data.tar.gz: 8aa45317a11732e21aa132ee59a3961ea7a82b7874a5366f303e2d2a414796a9
5
5
  SHA512:
6
- metadata.gz: 21fef267a733b01635afe9ba9cdf1bbba98eae94d64d7ffd53989a73901658223fee1b13db35b31d8dbbd91c4092524ece637e425a40d199968b2095f94da95c
7
- data.tar.gz: 1d014f730e8eaec9b504d9751d4bc332b4ab54e0d1133244675e6bbea94ad47ffad3cc1c278499ec02e70074d8366082467895fc422cdab3d1176e248fb1e3da
6
+ metadata.gz: 70df08329bac34d8c78fa13ddffe600ec8dc8addece55c24b41487d5cab4f40fecd4454d82919d0c5e4dc65c9363dfdf0ccdc721d47cba57e5350af54740d2bb
7
+ data.tar.gz: ecd66d14f238e66c8bb4fde3672d0ae41b8019b57baaca71d14d0dfd6dd4de67ed60b75fb50fca1815db1c790b9d4f9d124aa271b5b156d37d45bf6f9c416aac
@@ -15,6 +15,10 @@ class RBender::Base
15
15
 
16
16
  public
17
17
 
18
+ def self.api
19
+ @@api
20
+ end
21
+
18
22
  def initialize
19
23
  @states = {}
20
24
  @global_state = nil
@@ -31,6 +35,7 @@ class RBender::Base
31
35
  puts "Bot is running...".green
32
36
  Telegram::Bot::Client.run(@token) do |bot|
33
37
  @api = bot.api
38
+ @@api = bot.api
34
39
 
35
40
  unless @modules_block.nil?
36
41
  instance_exec(@api, @mongo_client, &@modules_block)
@@ -78,6 +83,7 @@ class RBender::Base
78
83
  end
79
84
  end
80
85
 
86
+ alias screen state
81
87
 
82
88
  def global(&block)
83
89
  if @global_state
@@ -175,7 +181,7 @@ class RBender::Base
175
181
  }
176
182
  end
177
183
 
178
- session[:user].freeze # User's data must be immutable!
184
+ session[:chat].freeze # User's data must be immutable!
179
185
 
180
186
  if is_start_message? message
181
187
  session[:state] = :start
@@ -8,9 +8,11 @@ class RBender::Keyboard
8
8
  :markup_tg,
9
9
  :markup_final,
10
10
  :switch_groups,
11
- :session
11
+ :session,
12
+ :message
12
13
 
13
- def initialize
14
+ def initialize(message)
15
+ @message = message
14
16
  @actions = {}
15
17
  @markup = []
16
18
  @localizations = {}
@@ -1,8 +1,11 @@
1
1
  class RBender::KeyboardInline
2
2
  attr_accessor :markup_tg,
3
- :buttons_actions
3
+ :buttons_actions,
4
+ :message,
5
+ :session
4
6
 
5
- def initialize(name, session, block)
7
+ def initialize(name, message, session, block)
8
+ @message = message
6
9
  @name = name
7
10
  @buttons_callback = {}
8
11
  @buttons_inline = {}
@@ -14,6 +14,7 @@ class RBender::State
14
14
  @before_block = nil
15
15
  @text_block = nil
16
16
  @helpers_block = nil
17
+ @helpers_global_block = nil
17
18
  @pre_checkout_block = nil
18
19
  @checkout_block = nil
19
20
  @shipping_block = nil
@@ -99,6 +100,7 @@ class RBender::State
99
100
  def process_text_message
100
101
  unless @keyboard.nil? # if state has keyboard
101
102
  @keyboard.instance_eval(&@helpers_block) unless @helpers_block.nil?
103
+ @keyboard.instance_eval(&@helpers_global_block) unless @helpers_global_block.nil?
102
104
  build_keyboard
103
105
 
104
106
  @keyboard.markup_final.each do |btn, final_btn|
@@ -122,13 +124,13 @@ class RBender::State
122
124
  keyboard.invoke unless keyboard.nil?
123
125
 
124
126
  unless keyboard.nil?
125
- unless keyboard.buttons_actions[action].nil?
127
+ if keyboard.buttons_actions[action]
126
128
  instance_eval(&keyboard.buttons_actions[action])
127
129
  else
128
130
  raise "There is no action called '#{action}'"
129
131
  end
130
132
  else
131
- edit_message_text text: "deleted"
133
+ edit_message_text text: ":)"
132
134
  end
133
135
  end
134
136
 
@@ -171,6 +173,7 @@ class RBender::State
171
173
  # adds inline keyboard
172
174
  def keyboard_inline(inline_keyboard_name, &inline_keyboard_block)
173
175
  @inline_keyboards_blocks[inline_keyboard_name] = RBender::KeyboardInline.new(inline_keyboard_name,
176
+ @message,
174
177
  @session,
175
178
  inline_keyboard_block)
176
179
  end
@@ -206,14 +209,19 @@ class RBender::State
206
209
  if @is_global
207
210
  raise 'Global state doesn\'t support :keyboard method'
208
211
  end
209
- @keyboard = RBender::Keyboard.new
212
+ @keyboard = RBender::Keyboard.new(@message)
210
213
  @keyboard.session = @session
211
214
  @keyboard.instance_eval(&keyboard_block)
212
215
  end
213
216
 
214
217
  #initialize helper methods
215
218
  def helpers(&helpers_block)
216
- @helpers_block = helpers_block
219
+ if @helpers_block
220
+ @helpers_global_block = helpers_block
221
+ else
222
+ @helpers_block = helpers_block
223
+ end
224
+
217
225
  instance_eval(&helpers_block)
218
226
  end
219
227
 
@@ -274,10 +282,11 @@ class RBender::State
274
282
  # Returns Inline keyboard object by name
275
283
  def inline_markup(name)
276
284
  raise "Keyboard #{name} doesn't exists!" unless @inline_keyboards_blocks.member? name
277
- keyboard = @inline_keyboards_blocks[name]
278
- keyboard.instance_eval(&@helpers_block) unless @helpers_block.nil?
279
- keyboard.build
280
- keyboard.markup_tg
285
+ kb = @inline_keyboards_blocks[name]
286
+ kb.instance_eval(&@helpers_block) unless @helpers_block.nil?
287
+ kb.instance_eval(&@helpers_global_block) unless @helpers_global_block.nil?
288
+ kb.build
289
+ kb.markup_tg
281
290
  end
282
291
 
283
292
  def pre_checkout(&block)
@@ -1,62 +1,10 @@
1
1
  require 'rbender'
2
- Dir["/lib/*.rb"].each {|file| require_relative file}
3
2
 
4
- state :start do
3
+ screen :start do
5
4
  before do
6
5
  # - - - - - -
7
6
  # Before hook
8
7
  # - - - - - -
9
8
  end
10
-
11
-
12
- keyboard do
13
- set_response("Sample response") #response are required
14
- button :btn_1, "Btn1" do
15
- # do something
16
- end
17
-
18
- button :btn_2, "Btn2" do
19
- # do something
20
- end
21
-
22
- line :btn_1, :btn_2
23
- # - - - - - - -
24
- # Init keyboard
25
- # - - - - - - -
26
- end
27
-
28
-
29
- keyboard_inline :kb_inline do
30
- # - - - - - -
31
- # Init inline keyboard
32
- # - - - - - -
33
- end
34
-
35
- after do
36
- # - - - - - -
37
- # After hook
38
- # - - - - - -
39
- end
40
-
41
- text do |text|
42
- # - - - - - - - - - - - -
43
- # Process user's message
44
- # - - - - - - - - - - - -
45
- end
46
9
  end
47
10
 
48
- global do
49
- command '/command' do
50
- # command without params
51
- end
52
-
53
- command '/command2' do |params|
54
- # command with params
55
- end
56
-
57
- helpers do
58
- # - - - - - - - - - - -
59
- # Define global helpers
60
- # - - - - - - - - - - -
61
- end
62
- end
@@ -0,0 +1,15 @@
1
+ global do
2
+ command '/command' do
3
+ # command without params
4
+ end
5
+
6
+ command '/command2' do |params|
7
+ # command with params
8
+ end
9
+
10
+ helpers do
11
+ # - - - - - - - - - - -
12
+ # Define global helpers
13
+ # - - - - - - - - - - -
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ screen :main_screen do
2
+ keyboard do
3
+ set_response("Sample response") #response are required
4
+ button :btn_1, "Btn1" do
5
+ # do something
6
+ end
7
+
8
+ button :btn_2, "Btn2" do
9
+ # do something
10
+ end
11
+
12
+ line :btn_1, :btn_2
13
+ # - - - - - - -
14
+ # Init keyboard
15
+ # - - - - - - -
16
+ end
17
+
18
+
19
+ keyboard_inline :kb_inline do
20
+ # - - - - - -
21
+ # Init inline keyboard
22
+ # - - - - - -
23
+ end
24
+
25
+
26
+ text do |text|
27
+ # - - - - - - - - - - - -
28
+ # Process user's message
29
+ # - - - - - - - - - - - -
30
+ end
31
+
32
+ after do
33
+ # - - - - - -
34
+ # After hook
35
+ # - - - - - -
36
+ end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-09 00:00:00.000000000 Z
12
+ date: 2019-03-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Gem provides domain specific language for messengers bot creation.
15
15
  email: art2rik.desperado@gmail.com
@@ -33,6 +33,8 @@ files:
33
33
  - templates/config.yaml
34
34
  - templates/locales/en.yaml
35
35
  - templates/sample.rb
36
+ - templates/screens/global_screen.rb
37
+ - templates/screens/main_screen.rb
36
38
  homepage: https://github.com/art2rik/RBender
37
39
  licenses: []
38
40
  metadata:
@@ -45,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
47
  requirements:
46
48
  - - ">="
47
49
  - !ruby/object:Gem::Version
48
- version: 2.0.0
50
+ version: 2.4.0
49
51
  required_rubygems_version: !ruby/object:Gem::Requirement
50
52
  requirements:
51
53
  - - ">="