RBotKit 0.1.30
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 +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/RBotKit/.gitignore +9 -0
- data/RBotKit/.rspec +2 -0
- data/RBotKit/.travis.yml +3 -0
- data/RBotKit/Gemfile +4 -0
- data/RBotKit/RBotKit.gemspec +27 -0
- data/RBotKit/README.md +39 -0
- data/RBotKit/Rakefile +2 -0
- data/RBotKit/bin/console +14 -0
- data/RBotKit/bin/setup +7 -0
- data/RBotKit/lib/RBotKit/version.rb +3 -0
- data/RBotKit/lib/RBotKit.rb +5 -0
- data/RBotKit/spec/RBotKit_spec.rb +11 -0
- data/RBotKit/spec/spec_helper.rb +2 -0
- data/RBotKit.gemspec +28 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/.DS_Store +0 -0
- data/bin/console +15 -0
- data/bin/setup +6 -0
- data/lib/.DS_Store +0 -0
- data/lib/RBotKit/.DS_Store +0 -0
- data/lib/RBotKit/base_cmd.rb +54 -0
- data/lib/RBotKit/locale_provider.rb +11 -0
- data/lib/RBotKit/state_provider.rb +25 -0
- data/lib/RBotKit/t_responce.rb +110 -0
- data/lib/RBotKit/version.rb +3 -0
- data/lib/RBotKit.rb +141 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 73762fed270f8fc2b87cb9023afbd46446d2adfb
|
4
|
+
data.tar.gz: 1060483b5ab42e01309e51ea2e7af02209cc63f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da8a09a1c74c01692f1aad5aa6f5c4ff2d4907c6e51a101cf803e098939cb1939df1c8d2bfb5030dcf7c72166f92a0bf6581d2e9400f464fa5248421fac76123
|
7
|
+
data.tar.gz: a22f8466fe2f2c236dcc061e8da943460a54a89494afbe85955fb26811b6085cd6da46d7c36fec857bda9ae4ab16d7c3798684eca8e3b873501f205b44637bfc
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 alexej
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/RBotKit/.gitignore
ADDED
data/RBotKit/.rspec
ADDED
data/RBotKit/.travis.yml
ADDED
data/RBotKit/Gemfile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'RBotKit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "RBotKit"
|
8
|
+
spec.version = RBotKit::VERSION
|
9
|
+
spec.authors = ["alexej"]
|
10
|
+
spec.email = ["red.belial@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
|
13
|
+
spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
data/RBotKit/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# RBotKit
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/RBotKit`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'RBotKit'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install RBotKit
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/RBotKit/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/RBotKit/Rakefile
ADDED
data/RBotKit/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "RBotKit"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/RBotKit/bin/setup
ADDED
data/RBotKit.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'RBotKit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "RBotKit"
|
8
|
+
spec.version = RBotKit::VERSION
|
9
|
+
spec.authors = ["alexej"]
|
10
|
+
spec.email = ["red.belial@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Bot Kit for telegramm"
|
13
|
+
spec.description = "Bot Kit for telegramm"
|
14
|
+
spec.homepage = "http://google.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "2.99.0"
|
26
|
+
spec.add_dependency 'rest-client', '~> 1.8'
|
27
|
+
spec.add_dependency 'i18n', '~> 0'
|
28
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# RBotKit
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/RBotKit`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'RBotKit'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install RBotKit
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/RBotKit/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/.DS_Store
ADDED
Binary file
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "RBotKit"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module RBotKit
|
2
|
+
|
3
|
+
class BaseCmd
|
4
|
+
class << self; attr_accessor :request end
|
5
|
+
class << self; attr_accessor :responces end
|
6
|
+
class << self; attr_accessor :state_provider end
|
7
|
+
|
8
|
+
@request = nil
|
9
|
+
@state_provider = nil
|
10
|
+
@responces = nil
|
11
|
+
|
12
|
+
attr_accessor :request
|
13
|
+
attr_accessor :responces
|
14
|
+
attr_accessor :state_provider
|
15
|
+
|
16
|
+
def before_init
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def before_validate
|
21
|
+
end
|
22
|
+
|
23
|
+
def handle
|
24
|
+
end
|
25
|
+
|
26
|
+
def new_ret_resp(kb_builder = nil)
|
27
|
+
new_resp(@request.chat_id, kb_builder)
|
28
|
+
end
|
29
|
+
|
30
|
+
def new_resp(chat_id, kb_builder = nil)
|
31
|
+
resp = TRep.new(chat_id, kb_builder)
|
32
|
+
add_resp resp
|
33
|
+
resp
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_resp(resp)
|
37
|
+
@responces = [] if @responces == nil
|
38
|
+
@responces << resp
|
39
|
+
end
|
40
|
+
|
41
|
+
def err_if_true(bv, msg)
|
42
|
+
raise UserError.new(msg) if bv
|
43
|
+
end
|
44
|
+
|
45
|
+
def err_if_false(bv, msg)
|
46
|
+
raise UserError.new(msg) if !bv
|
47
|
+
end
|
48
|
+
|
49
|
+
def err_if_nil(bv, msg)
|
50
|
+
raise UserError.new(msg) if bv == nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RBotKit
|
2
|
+
|
3
|
+
class StateProvider
|
4
|
+
|
5
|
+
def is_req_already_processed(chat_id, req_id)
|
6
|
+
return false if req_id == nil
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def update_last_processed_req_id(chat_id, req_id)
|
11
|
+
return false if req_id == nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_current_state(chat_id)
|
15
|
+
:none
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_state_for(chat_id, state)
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module RBotKit
|
2
|
+
|
3
|
+
class TRep
|
4
|
+
require "rest-client"
|
5
|
+
require 'json'
|
6
|
+
require 'i18n'
|
7
|
+
class << self; attr_accessor :chat_id end
|
8
|
+
attr_accessor :chat_id
|
9
|
+
|
10
|
+
@@test_mode = false
|
11
|
+
def set_test_mode(v)
|
12
|
+
@@test_mode = v
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(chat_id, kb_builder = nil)
|
16
|
+
@chat_id = chat_id
|
17
|
+
@kb_builder = kb_builder
|
18
|
+
@payload = {chat_id: @chat_id}
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(locale = nil)
|
22
|
+
cl = I18n.locale.to_s
|
23
|
+
if locale == nil || locale.to_s == cl
|
24
|
+
@proc_block.call
|
25
|
+
else
|
26
|
+
I18n.locale = locale
|
27
|
+
@proc_block.call
|
28
|
+
I18n.locale = cl
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def loc_txt(key, prms = {})
|
33
|
+
@proc_block = Proc.new {
|
34
|
+
if @@test_mode
|
35
|
+
test_call("loc_txt locale:#{I18n.locale} key:#{key} prms:#{prms}")
|
36
|
+
else
|
37
|
+
@payload = {chat_id: @chat_id, text: I18n.t(key, prms)}
|
38
|
+
set_payload_keyboard
|
39
|
+
tel_send_message
|
40
|
+
end
|
41
|
+
}
|
42
|
+
itself
|
43
|
+
end
|
44
|
+
|
45
|
+
def loc_photo_file(photofile, ckey, cprms = {})
|
46
|
+
@proc_block = Proc.new {
|
47
|
+
if @@test_mode
|
48
|
+
test_call("loc_photo_file locale:#{I18n.locale} ckey:#{ckey} cprms:#{cprms} photofile:#{photofile}")
|
49
|
+
else
|
50
|
+
@payload = {chat_id: @chat_id, caption: I18n.t(ckey, cprms), photo: File.new(photofile, 'rb') }
|
51
|
+
set_payload_keyboard
|
52
|
+
tel_send_photo
|
53
|
+
end
|
54
|
+
}
|
55
|
+
itself
|
56
|
+
end
|
57
|
+
|
58
|
+
def txt(text)
|
59
|
+
@proc_block = Proc.new {
|
60
|
+
if @@test_mode
|
61
|
+
test_call("txt text:#{text}")
|
62
|
+
else
|
63
|
+
@payload = {chat_id: @chat_id, text: text}
|
64
|
+
set_payload_keyboard
|
65
|
+
tel_send_message
|
66
|
+
end
|
67
|
+
}
|
68
|
+
itself
|
69
|
+
end
|
70
|
+
|
71
|
+
def photo_file(photofile, caption)
|
72
|
+
@proc_block = Proc.new {
|
73
|
+
if @@test_mode
|
74
|
+
test_call("photo_file caption:#{caption} photofile:#{photofile}")
|
75
|
+
else
|
76
|
+
@payload = {chat_id: @chat_id, caption: caption, photo: File.new(photofile, 'rb') }
|
77
|
+
set_payload_keyboard
|
78
|
+
tel_send_photo
|
79
|
+
end
|
80
|
+
}
|
81
|
+
itself
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def test_call(text)
|
87
|
+
kbputs = @kb_builder == nil ? "" : " kb:#{@kb_builder.call()}"
|
88
|
+
STDOUT.puts "chat_id:#{@chat_id}#{kbputs} #{text}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def set_payload_keyboard
|
92
|
+
@payload[:reply_markup] = @kb_builder.call().to_json if @kb_builder != nil
|
93
|
+
end
|
94
|
+
|
95
|
+
def tel_send_message
|
96
|
+
RestClient::Request.execute(method: :post, url: "https://api.telegram.org/#{RBotKit.bot_key}/sendMessage",
|
97
|
+
timeout: 10,
|
98
|
+
payload: @payload.to_json ,
|
99
|
+
headers: {content_type: "application/json; charset=utf-8"})
|
100
|
+
end
|
101
|
+
|
102
|
+
def tel_send_photo
|
103
|
+
RestClient::Request.execute(method: :post, url: "https://api.telegram.org/#{RBotKit.bot_key}/sendPhoto",
|
104
|
+
timeout: 10,
|
105
|
+
payload: @payload,
|
106
|
+
multipart: true )
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
data/lib/RBotKit.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require "RBotKit/version"
|
2
|
+
require "RBotKit/base_cmd"
|
3
|
+
require "RBotKit/t_responce"
|
4
|
+
require "RBotKit/state_provider"
|
5
|
+
require "RBotKit/locale_provider"
|
6
|
+
|
7
|
+
|
8
|
+
module RBotKit
|
9
|
+
|
10
|
+
@@bot_key = ""
|
11
|
+
|
12
|
+
def self.set_bot_key(bk)
|
13
|
+
@@bot_key = bk
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.bot_key
|
17
|
+
@@bot_key
|
18
|
+
end
|
19
|
+
|
20
|
+
Request = Struct.new(:id, :chat_id, :user_id, :text, :username)
|
21
|
+
RequestCallback = Struct.new(:id, :chat_id, :user_id, :text, :username)
|
22
|
+
|
23
|
+
def self.tel_parse_data(data)
|
24
|
+
id = data[:update_id]
|
25
|
+
mes = data[:message]
|
26
|
+
if mes != nil
|
27
|
+
usr = mes[:from]
|
28
|
+
chat_id = mes[:chat][:id].to_s
|
29
|
+
user_id = usr[:id]
|
30
|
+
username = usr[:first_name]
|
31
|
+
text = mes[:text] != nil ? mes[:text].strip : nil
|
32
|
+
req = Request.new(id, chat_id, user_id, text, username)
|
33
|
+
else
|
34
|
+
cb = data[:callback_query]
|
35
|
+
if cb != nil
|
36
|
+
mes = cb[:message]
|
37
|
+
chat_id = mes[:chat][:id].to_s if mes != nil
|
38
|
+
usr = cb[:from]
|
39
|
+
user_id = usr[:id]
|
40
|
+
username = usr[:first_name]
|
41
|
+
text = cb[:data]
|
42
|
+
req = RequestCallback.new(id, chat_id, user_id, text, username)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
CommandCase = Struct.new(:state, :cmdtext, :cmdclass)
|
49
|
+
|
50
|
+
def self.new_case(state, cmdtext, cmdclass)
|
51
|
+
CommandCase.new(state, cmdtext, cmdclass)
|
52
|
+
end
|
53
|
+
|
54
|
+
class UserError < Exception
|
55
|
+
end
|
56
|
+
|
57
|
+
class CommandManager
|
58
|
+
@@cmd_classprefix = "RBotKit::"
|
59
|
+
@@is_test_mode = false
|
60
|
+
|
61
|
+
def self.set_cmd_classprefix(kp)
|
62
|
+
@@cmd_classprefix = kp
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.set_is_test_mode()
|
66
|
+
@@is_test_mode = true
|
67
|
+
end
|
68
|
+
|
69
|
+
def initialize(state_provider, caces, inlinecases, locale_provider = nil)
|
70
|
+
@state_provider = state_provider
|
71
|
+
@caces = caces
|
72
|
+
@inlinecases = inlinecases
|
73
|
+
@locale_provider = locale_provider == nil ? LocaleProvider.new : locale_provider
|
74
|
+
end
|
75
|
+
|
76
|
+
def process_request(req)
|
77
|
+
return if req.text == nil
|
78
|
+
return if @state_provider.is_req_already_processed(req.chat_id, req.id)
|
79
|
+
|
80
|
+
@state_provider.update_last_processed_req_id(req.chat_id, req.id)
|
81
|
+
|
82
|
+
state = @state_provider.get_current_state(req.chat_id)
|
83
|
+
p "STATE = #{state}"
|
84
|
+
cmdCase = nil
|
85
|
+
|
86
|
+
arrs = req.class == RequestCallback ? @inlinecases : @caces
|
87
|
+
|
88
|
+
arrs.each do |cc|
|
89
|
+
in_state = cc.state.class == Array ? cc.state.include?(state) : cc.state == state
|
90
|
+
if in_state || cc.state == :any
|
91
|
+
if cc.cmdtext.class == Hash
|
92
|
+
regexp = cc.cmdtext[:regexp]
|
93
|
+
cmdCase = cc if regexp != nil && regexp.match(req.text)
|
94
|
+
elsif cc.cmdtext.class == Symbol && cc.cmdtext == :any
|
95
|
+
cmdCase = cc
|
96
|
+
else
|
97
|
+
cmdCase = cc if cc.cmdtext == req.text
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
break if cmdCase != nil
|
102
|
+
end
|
103
|
+
|
104
|
+
return if cmdCase == nil
|
105
|
+
p "CMD = #{cmdCase} #{@@cmd_classprefix}#{cmdCase.cmdclass}"
|
106
|
+
begin
|
107
|
+
|
108
|
+
cmdHandel = Object::const_get("#{@@cmd_classprefix}#{cmdCase.cmdclass}").new
|
109
|
+
cmdHandel.request = req
|
110
|
+
cmdHandel.state_provider = @state_provider
|
111
|
+
cmdHandel.before_init()
|
112
|
+
cmdHandel.before_validate()
|
113
|
+
cmdHandel.handle()
|
114
|
+
responces = cmdHandel.responces
|
115
|
+
|
116
|
+
return if responces == nil || responces.empty?
|
117
|
+
|
118
|
+
responces.each do |res|
|
119
|
+
locale = @locale_provider.get_locale_for(res.chat_id)
|
120
|
+
res.set_test_mode(@@is_test_mode)
|
121
|
+
res.call(locale)
|
122
|
+
end
|
123
|
+
|
124
|
+
rescue UserError => e
|
125
|
+
p "UserError #{e.message} "
|
126
|
+
eresp = TRep.new(req.chat_id)
|
127
|
+
eresp.txt(e.message)
|
128
|
+
locale = @locale_provider.get_locale(req.chat_id)
|
129
|
+
eresp.set_test_mode(@@is_test_mode)
|
130
|
+
eresp.call(locale)
|
131
|
+
return
|
132
|
+
rescue => e
|
133
|
+
p "Exc #{e} "
|
134
|
+
return
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: RBotKit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.30
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- alexej
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.99.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.99.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: i18n
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Bot Kit for telegramm
|
84
|
+
email:
|
85
|
+
- red.belial@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".DS_Store"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- RBotKit.gemspec
|
97
|
+
- RBotKit/.gitignore
|
98
|
+
- RBotKit/.rspec
|
99
|
+
- RBotKit/.travis.yml
|
100
|
+
- RBotKit/Gemfile
|
101
|
+
- RBotKit/RBotKit.gemspec
|
102
|
+
- RBotKit/README.md
|
103
|
+
- RBotKit/Rakefile
|
104
|
+
- RBotKit/bin/console
|
105
|
+
- RBotKit/bin/setup
|
106
|
+
- RBotKit/lib/RBotKit.rb
|
107
|
+
- RBotKit/lib/RBotKit/version.rb
|
108
|
+
- RBotKit/spec/RBotKit_spec.rb
|
109
|
+
- RBotKit/spec/spec_helper.rb
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/.DS_Store
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- lib/.DS_Store
|
116
|
+
- lib/RBotKit.rb
|
117
|
+
- lib/RBotKit/.DS_Store
|
118
|
+
- lib/RBotKit/base_cmd.rb
|
119
|
+
- lib/RBotKit/locale_provider.rb
|
120
|
+
- lib/RBotKit/state_provider.rb
|
121
|
+
- lib/RBotKit/t_responce.rb
|
122
|
+
- lib/RBotKit/version.rb
|
123
|
+
homepage: http://google.com
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.8
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Bot Kit for telegramm
|
147
|
+
test_files: []
|