rbender 0.5.1 → 0.5.35

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
  SHA1:
3
- metadata.gz: b87a6e8247553462fc13653986bfd04271ace3dd
4
- data.tar.gz: ac5cd960c69eb6a092ac357fc21fa594908b61cf
3
+ metadata.gz: 1e7dca1a0912cda6f127f976eaca5430eca53305
4
+ data.tar.gz: ff763b15c52961be0ac08eac1481fd0377100406
5
5
  SHA512:
6
- metadata.gz: 50ce484bc121cefb24e04ebc139472f8615fe0de81118025eda139d9f7c7bbb20f0e09cbea343e7f7ff480b5569fee84c455241d7a8db9df58891eb3618bb6b9
7
- data.tar.gz: 8b69df3a95f933ef6f5f654b1968065bea321e8a3da0de6d5cfde94c15dda3d2106360a8a25786bb43b1935f980c4350292001e2133f83fbb9f57ca0d59ab0d8
6
+ metadata.gz: 083c5cd21ec62e28fc98a70e9f50465679062fd4578d95eacbe4bc1ec2941fc50b7f5de3e2a1639fbc3e8d97921cb78557ab2359d625f255a1f55905e73dc3c5
7
+ data.tar.gz: 4bac9546dcf062a3778f5e7b60041b5456cc552c2ae77c0c27a6449e81d2dab50087fda4361d6564b4b5513604e052aaf46f3a44dbd2ac8ea3e5ef46c82f21f8
@@ -20,7 +20,7 @@ class OptParser
20
20
  opts.separator ""
21
21
  opts.separator "Common options:"
22
22
  opts.on_tail("-v", "--version", "Prints current RBender version") do
23
- puts "RBender version: #{RBender::VERSION}"
23
+ puts "RBender version: #{Gem.loaded_specs["rbender"].version}"
24
24
  puts "by art2rik (https://github.com/art2rik)"
25
25
  end
26
26
 
@@ -2,7 +2,7 @@ require 'rbender/base'
2
2
  require 'colorize'
3
3
 
4
4
  module RBender
5
- VERSION = '0.5.1'
5
+ CALLBACK_SPLITTER = '|'
6
6
  @@bot = RBender::Base.new
7
7
 
8
8
  def self.instance
@@ -44,7 +44,7 @@ class RBender::Base
44
44
  process_message(message)
45
45
  rescue => ex
46
46
  puts ex.message.red
47
- puts ex.backtrace
47
+ puts ex.backtrace_locations
48
48
  end
49
49
  end
50
50
  end
@@ -63,6 +63,8 @@ class RBender::Base
63
63
  session_setup(RBender::MongoClient.client)
64
64
 
65
65
  @token = params['development']['token']
66
+ RBender::ConfigHandler.token = @token
67
+
66
68
  # if params.has_key? localizations
67
69
  #
68
70
  # end
@@ -31,5 +31,13 @@ module RBender
31
31
  def self.config_path=(path)
32
32
  @@config_path = "#{path}/#{CONFIG_NAME}"
33
33
  end
34
+
35
+ def self.token=(token)
36
+ @@token = token
37
+ end
38
+
39
+ def self.token
40
+ @@token
41
+ end
34
42
  end
35
43
  end
@@ -1,5 +1,3 @@
1
- CALLBACK_SPLITTER = '|'
2
-
3
1
  class RBender::KeyboardInline
4
2
  attr_accessor :markup_tg,
5
3
  :buttons_actions
@@ -1,3 +1,5 @@
1
+ require 'faraday'
2
+
1
3
  class RBender::Methods
2
4
 
3
5
  def initialize(message, api, session)
@@ -25,15 +27,6 @@ class RBender::Methods
25
27
  @message
26
28
  end
27
29
 
28
- # Returns Inline keyboard object by name
29
- def inline_markup(name)
30
- raise "Keyboard #{name} doesn't exists!" unless @inline_keyboards.member? name
31
- keyboard = @inline_keyboards[name]
32
- keyboard.instance_eval(&@helpers_block) unless @helpers_block.nil?
33
- keyboard.build
34
- keyboard.markup_tg
35
- end
36
-
37
30
  def switch(state_to)
38
31
  @session[:state_stack].push(@session[:state])
39
32
  @session[:state] = state_to
@@ -49,27 +42,6 @@ class RBender::Methods
49
42
  #--------------
50
43
  # Hides inline keyboard
51
44
  # Must be called from any inline keyboard state
52
- def hide_inline
53
- edit_message_reply_markup
54
- end
55
-
56
- # Hides keyboard's markup.
57
- def hide_keyboard
58
-
59
- end
60
-
61
- #
62
- # @param text [String] string
63
- #
64
- def answer_callback_query(text: nil,
65
- show_alert: nil)
66
- begin
67
- @api.answer_callback_query callback_query_id: @message.id,
68
- text: text,
69
- show_alert: show_alert
70
- rescue
71
- end
72
- end
73
45
 
74
46
  def send_message(text:,
75
47
  chat_id: @message.from.id,
@@ -376,5 +348,35 @@ class RBender::Methods
376
348
  user_id: user_id)
377
349
  end
378
350
 
351
+ def upload_file(filename, content_type)
352
+ filepath = "#{__dir__}/public/#{filename}"
353
+ Faraday::UploadIO.new(filepath, content_type)
354
+ end
355
+
356
+ alias file upload_file
357
+ alias upload upload_file
358
+
359
+ def download_file(file_path:, to:)
360
+ url = 'https://api.telegram.org/file/bot'
361
+ token = RBender::ConfigHandler.token
362
+ path = Dir.pwd + "/public/#{to}"
363
+
364
+
365
+ http_conn = Faraday.new do |builder|
366
+ builder.adapter(Faraday.default_adapter)
367
+ end
368
+
369
+ response = http_conn.get "#{url}#{token}/#{file_path}"
370
+
371
+ dir = File.dirname(path)
372
+
373
+ unless File.directory?(dir)
374
+ FileUtils.mkdir_p(dir)
375
+ end
376
+
377
+ File.open(path, 'wb') { |fp| fp.write(response.body)}
378
+ end
379
+
380
+ alias download download_file
379
381
  end
380
382
 
@@ -12,6 +12,7 @@ class RBender::State
12
12
  @text_action = nil
13
13
  @helpers_block = nil
14
14
  @methods = RBender::Methods.new(message, api, session)
15
+ @commands = {}
15
16
  end
16
17
 
17
18
  def get_keyboard
@@ -29,7 +30,11 @@ class RBender::State
29
30
  process_callback
30
31
  when Telegram::Bot::Types::Message
31
32
  if @message.text
32
- process_text_message
33
+ if @message.text[0] == '/' and @message.text != '/start'
34
+ process_command(@message.text)
35
+ else
36
+ process_text_message
37
+ end
33
38
  elsif @message.photo
34
39
  process_photo
35
40
  end
@@ -43,9 +48,22 @@ class RBender::State
43
48
  end
44
49
  end
45
50
 
51
+ # @param command String
52
+ def process_command(command_line)
53
+ splitted = command_line.split(" ")
54
+ command = splitted[0]
55
+ splitted.delete_at 0
56
+ params = splitted
57
+
58
+ if @commands.include? command
59
+ instance_exec(params, &@commands[command])
60
+ end
61
+ end
62
+
46
63
  def process_photo
47
64
  instance_exec(message.photo, &@photo_action) unless @photo_action.nil?
48
65
  end
66
+
49
67
  # Process if message is just text
50
68
  def process_text_message
51
69
 
@@ -178,6 +196,18 @@ class RBender::State
178
196
  alias image photo
179
197
  alias picture photo
180
198
 
199
+ def command(command, &action)
200
+ unless @commands.include? command
201
+ if command[0] == '/'
202
+ @commands[command] = action
203
+ else
204
+ raise "Command should be started from slash symbol (/)"
205
+ end
206
+ else
207
+ raise "Command #{command} already exists"
208
+ end
209
+ end
210
+
181
211
 
182
212
  def method_missing(m, *args, &block)
183
213
  if RBender::Methods.method_defined? m
@@ -201,5 +231,14 @@ class RBender::State
201
231
  end
202
232
  end
203
233
 
234
+ # Returns Inline keyboard object by name
235
+ def inline_markup(name)
236
+ raise "Keyboard #{name} doesn't exists!" unless @inline_keyboards.member? name
237
+ keyboard = @inline_keyboards[name]
238
+ keyboard.instance_eval(&@helpers_block) unless @helpers_block.nil?
239
+ keyboard.build
240
+ keyboard.markup_tg
241
+ end
242
+
204
243
  end
205
244
 
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.5.1
4
+ version: 0.5.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur
@@ -43,7 +43,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: 2.0.0
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="