kanal-plugins-batteries_bridge 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +100 -0
- data/LICENSE.txt +21 -0
- data/README.md +99 -0
- data/Rakefile +12 -0
- data/kanal-plugins-batteries_bridge.gemspec +39 -0
- data/lib/kanal/plugins/batteries_bridge/batteries_bridge_plugin.rb +79 -0
- data/lib/kanal/plugins/batteries_bridge/bridges/bridge.rb +137 -0
- data/lib/kanal/plugins/batteries_bridge/bridges/telegram_bridge.rb +69 -0
- data/lib/kanal/plugins/batteries_bridge/version.rb +9 -0
- data/lib/kanal/plugins/batteries_bridge.rb +13 -0
- data/sig/kanal/plugins/batteries_bridge.rbs +8 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 729217d8b7323085326493575ed58ea54567b85ec4a47c856842e0ba467c34be
|
4
|
+
data.tar.gz: 06e8b9821df67f22375525bf1a6845b9e11083ca76e7f4965cfc010c983e0cdb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 941a07c33bb9a1b78af164536806196f5aeb60d4676e6d1d30984c0574b5120e674134584a3735dfc75659a58faca776e141b0eb096cfd06149bf5a49f28d5bb
|
7
|
+
data.tar.gz: 38cb64bdafba133b088dd389e7f38e1a23b914384a1471a5d63101399434587266ed3c2c409c408166190931a562287d0ff9ec26c0c1cfccd2e96125a90095c1
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.6
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at idchlife@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in kanal-plugins-batteries_bridge.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "kanal", ">= 0.4.2"
|
11
|
+
|
12
|
+
group :development do
|
13
|
+
gem "rubocop", "~> 1.21"
|
14
|
+
gem "ruby-debug-ide", "~> 0.7.3"
|
15
|
+
gem "solargraph"
|
16
|
+
gem "yard"
|
17
|
+
end
|
18
|
+
|
19
|
+
group :test do
|
20
|
+
gem "rspec", "~> 3.0"
|
21
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kanal-plugins-batteries_bridge (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
backport (1.2.0)
|
11
|
+
benchmark (0.2.1)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
e2mmap (0.1.0)
|
14
|
+
jaro_winkler (1.5.4)
|
15
|
+
json (2.6.3)
|
16
|
+
kanal (0.4.2)
|
17
|
+
kramdown (2.4.0)
|
18
|
+
rexml
|
19
|
+
kramdown-parser-gfm (1.1.0)
|
20
|
+
kramdown (~> 2.0)
|
21
|
+
nokogiri (1.14.2-x86_64-darwin)
|
22
|
+
racc (~> 1.4)
|
23
|
+
nokogiri (1.14.2-x86_64-linux)
|
24
|
+
racc (~> 1.4)
|
25
|
+
parallel (1.22.1)
|
26
|
+
parser (3.2.1.1)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
racc (1.6.2)
|
29
|
+
rainbow (3.1.1)
|
30
|
+
rake (13.0.6)
|
31
|
+
regexp_parser (2.7.0)
|
32
|
+
reverse_markdown (2.1.1)
|
33
|
+
nokogiri
|
34
|
+
rexml (3.2.5)
|
35
|
+
rspec (3.12.0)
|
36
|
+
rspec-core (~> 3.12.0)
|
37
|
+
rspec-expectations (~> 3.12.0)
|
38
|
+
rspec-mocks (~> 3.12.0)
|
39
|
+
rspec-core (3.12.1)
|
40
|
+
rspec-support (~> 3.12.0)
|
41
|
+
rspec-expectations (3.12.2)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-mocks (3.12.4)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.12.0)
|
47
|
+
rspec-support (3.12.0)
|
48
|
+
rubocop (1.48.1)
|
49
|
+
json (~> 2.3)
|
50
|
+
parallel (~> 1.10)
|
51
|
+
parser (>= 3.2.0.0)
|
52
|
+
rainbow (>= 2.2.2, < 4.0)
|
53
|
+
regexp_parser (>= 1.8, < 3.0)
|
54
|
+
rexml (>= 3.2.5, < 4.0)
|
55
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
56
|
+
ruby-progressbar (~> 1.7)
|
57
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
58
|
+
rubocop-ast (1.27.0)
|
59
|
+
parser (>= 3.2.1.0)
|
60
|
+
ruby-debug-ide (0.7.3)
|
61
|
+
rake (>= 0.8.1)
|
62
|
+
ruby-progressbar (1.13.0)
|
63
|
+
solargraph (0.48.0)
|
64
|
+
backport (~> 1.2)
|
65
|
+
benchmark
|
66
|
+
bundler (>= 1.17.2)
|
67
|
+
diff-lcs (~> 1.4)
|
68
|
+
e2mmap
|
69
|
+
jaro_winkler (~> 1.5)
|
70
|
+
kramdown (~> 2.3)
|
71
|
+
kramdown-parser-gfm (~> 1.1)
|
72
|
+
parser (~> 3.0)
|
73
|
+
reverse_markdown (>= 1.0.5, < 3)
|
74
|
+
rubocop (>= 0.52)
|
75
|
+
thor (~> 1.0)
|
76
|
+
tilt (~> 2.0)
|
77
|
+
yard (~> 0.9, >= 0.9.24)
|
78
|
+
thor (1.2.1)
|
79
|
+
tilt (2.1.0)
|
80
|
+
unicode-display_width (2.4.2)
|
81
|
+
webrick (1.7.0)
|
82
|
+
yard (0.9.28)
|
83
|
+
webrick (~> 1.7.0)
|
84
|
+
|
85
|
+
PLATFORMS
|
86
|
+
x86_64-darwin-21
|
87
|
+
x86_64-linux
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
kanal (>= 0.4.2)
|
91
|
+
kanal-plugins-batteries_bridge!
|
92
|
+
rake (~> 13.0)
|
93
|
+
rspec (~> 3.0)
|
94
|
+
rubocop (~> 1.21)
|
95
|
+
ruby-debug-ide (~> 0.7.3)
|
96
|
+
solargraph
|
97
|
+
yard
|
98
|
+
|
99
|
+
BUNDLED WITH
|
100
|
+
2.4.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 idchlife
|
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/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Kanal::Plugins::BatteriesBridge
|
2
|
+
|
3
|
+
### BatteriesBridge plugin provides the bridge between different interfaces with their properties to the batteries plugin properties.
|
4
|
+
E.g.: if you use telegram interface and have `input.tg_text` - this plugin will convert it into `input.body` (body property provided by the batteries plugin)
|
5
|
+
|
6
|
+
### Where to find Batteries plugin? Well, as of right now, Batteries plugin is a part of Kanal core codebase, part of it's repository. If you have Kanal core library -
|
7
|
+
you can get plugin via Kanal::Plugins::Batteries::BatteriesPlugin
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add kanal-plugins-batteries_bridge
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install kanal-plugins-batteries_bridge
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
1. Create instance of plugin:
|
22
|
+
|
23
|
+
```rb
|
24
|
+
plugin = Kanal::Plugins::BatteriesBridge::BatteriesBridge.new
|
25
|
+
```
|
26
|
+
|
27
|
+
2. Include needed bridges:
|
28
|
+
|
29
|
+
```rb
|
30
|
+
plugin.add_telegram # This adds built in default Telegram bridge
|
31
|
+
|
32
|
+
plugin.add_bridge YourBridgeClass.new
|
33
|
+
```
|
34
|
+
|
35
|
+
3. Register plugin:
|
36
|
+
|
37
|
+
```rb
|
38
|
+
core.register_plugin plugin
|
39
|
+
```
|
40
|
+
|
41
|
+
## Build-in bridges
|
42
|
+
|
43
|
+
- Telegram: `plugin.add_telegram`
|
44
|
+
|
45
|
+
## Creating bridge:
|
46
|
+
|
47
|
+
```rb
|
48
|
+
# WARNING: don't forget that all used input/output properties should be registered!
|
49
|
+
|
50
|
+
class YourBridgeClass < Kanal::Plugins::BatteriesBridge::Bridges::Bridge
|
51
|
+
# Required method that will be used
|
52
|
+
def setup
|
53
|
+
# This line is required, you should specify which .source is needed for this bridge to work
|
54
|
+
# Some info about input parameter :source - Batteries plugin introduced this parameter and ALL
|
55
|
+
# interfaces should populate .source input parameter when creating input. Thanks to this we can determine whether
|
56
|
+
# input came from telegram, or facebook messenger or some other source.
|
57
|
+
require_source :my_messenger_source
|
58
|
+
|
59
|
+
# Here with handy DSL methods you can specify which parameters to convert
|
60
|
+
input_convert :input_parameter_to_convert, :input_parameter_that_will_be_populated do |value_of_input_parameter|
|
61
|
+
# You can do anything with provided value here and return changed value, or return unchanged value for the sake of
|
62
|
+
# just populating different input property
|
63
|
+
your_changed_value
|
64
|
+
end
|
65
|
+
|
66
|
+
input_convert :float_param, :int_param do |value|
|
67
|
+
value.to_i
|
68
|
+
end
|
69
|
+
|
70
|
+
output_convert :from_param, :to_param do |value|
|
71
|
+
value
|
72
|
+
end
|
73
|
+
|
74
|
+
# You can specify as many convertations as you like
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
plugin.add_bridge YourBridgeClass.new
|
79
|
+
```
|
80
|
+
|
81
|
+
## Development
|
82
|
+
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
|
+
|
85
|
+
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`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
### If there is interface without bridge for batteries out there - we will be grateful if you contribute new bridge!
|
90
|
+
|
91
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/idchlife/kanal-plugins-batteries_bridge. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/idchlife/kanal-plugins-batteries_bridge/blob/main/CODE_OF_CONDUCT.md).
|
92
|
+
|
93
|
+
## License
|
94
|
+
|
95
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
96
|
+
|
97
|
+
## Code of Conduct
|
98
|
+
|
99
|
+
Everyone interacting in the Kanal::Plugins::BatteriesBridge project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/idchlife/kanal-plugins-batteries_bridge/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/kanal/plugins/batteries_bridge/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "kanal-plugins-batteries_bridge"
|
7
|
+
spec.version = Kanal::Plugins::BatteriesBridge::VERSION
|
8
|
+
spec.authors = ["idchlife"]
|
9
|
+
spec.email = ["idchlife@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Bridge between Kanal Batteries plugin and different interfaces"
|
12
|
+
spec.description = "This plugin provides transformation between different interface properties (e.g. tg_audio, tg_image) to batteries properties. Input and also output"
|
13
|
+
spec.homepage = "https://github.com/idchlife/kanal-plugins-batteries_bridge"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.7.6"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/idchlife/kanal-plugins-batteries_bridge"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/idchlife/kanal-plugins-batteries_bridge/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "kanal"
|
4
|
+
require_relative "./bridges/telegram_bridge"
|
5
|
+
|
6
|
+
module Kanal
|
7
|
+
module Plugins
|
8
|
+
module BatteriesBridge
|
9
|
+
#
|
10
|
+
# Plugin registers all needed hooks to process
|
11
|
+
#
|
12
|
+
class BatteriesBridgePlugin < Kanal::Core::Plugins::Plugin
|
13
|
+
include Kanal::Core::Logging
|
14
|
+
include Bridges
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
super
|
18
|
+
|
19
|
+
@bridges = []
|
20
|
+
@fail_gracefully = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def name
|
24
|
+
:batteries_bridge
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# @param [Bridge] bridge <description>
|
29
|
+
#
|
30
|
+
# @return [BatteriesBridgePlugin] <description>
|
31
|
+
#
|
32
|
+
def add_bridge(bridge)
|
33
|
+
raise "bridge should be instance of a Bridge class" unless bridge.is_a? Bridge
|
34
|
+
|
35
|
+
return if @bridges.include? bridge
|
36
|
+
|
37
|
+
bridge.fail_gracefully = @fail_gracefully
|
38
|
+
|
39
|
+
@bridges << bridge
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# When bridge converter raises an error, raise it instead of swallowing (logs will be written in both cases)
|
45
|
+
#
|
46
|
+
# @return [void] <description>
|
47
|
+
#
|
48
|
+
def fail_loud
|
49
|
+
@fail_gracefully = false
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# <Description>
|
54
|
+
#
|
55
|
+
# @return [BatteriesBridgePlugin] <description>
|
56
|
+
#
|
57
|
+
def add_telegram
|
58
|
+
add_bridge TelegramBridge.new
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# @param [Kanal::Core::Core] core <description>
|
64
|
+
#
|
65
|
+
# @return [void] <description>
|
66
|
+
#
|
67
|
+
def setup(core)
|
68
|
+
unless core.plugin_registered? :batteries
|
69
|
+
raise "[Kanal::Plugins::BatteriesBridge::BatteriesBridgePlugin]: cannot register plugin because :batteries plugin is not (maybe yet) registered in the core. It is required"
|
70
|
+
end
|
71
|
+
|
72
|
+
@bridges.each do |b|
|
73
|
+
b.send("internal_setup", core.hooks)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "kanal"
|
4
|
+
|
5
|
+
module Kanal
|
6
|
+
module Plugins
|
7
|
+
module BatteriesBridge
|
8
|
+
module Bridges
|
9
|
+
#
|
10
|
+
# Base class for bridges. All bridges should be derived from this class
|
11
|
+
#
|
12
|
+
class Bridge
|
13
|
+
include Kanal::Core::Logging::Logger
|
14
|
+
|
15
|
+
attr_reader :core_hooks
|
16
|
+
|
17
|
+
attr_writer :fail_gracefully
|
18
|
+
|
19
|
+
# Struct for using in param converters
|
20
|
+
ParamConverter = Struct.new("ParamConverter", :from_param, :to_param, :block)
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@core_hooks = nil
|
24
|
+
@source = nil
|
25
|
+
@input_converters = []
|
26
|
+
@output_converters = []
|
27
|
+
@fail_gracefully = true
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Required for overriding method in the derived bridge classes
|
32
|
+
#
|
33
|
+
# @return [void] <description>
|
34
|
+
#
|
35
|
+
def setup
|
36
|
+
raise NotImplementedError
|
37
|
+
end
|
38
|
+
|
39
|
+
protected :core_hooks
|
40
|
+
|
41
|
+
#
|
42
|
+
# :source input parameter will be checked for this
|
43
|
+
#
|
44
|
+
# @param [Symbol] source <description>
|
45
|
+
#
|
46
|
+
# @return [void] <description>
|
47
|
+
#
|
48
|
+
def require_source(source)
|
49
|
+
@source = source
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Register input converter
|
54
|
+
#
|
55
|
+
# @param [Symbol] from_param which input parameter will be used for getting value
|
56
|
+
# @param [Symbol] to_param which input parameter will be populated with return value from block
|
57
|
+
# @param [Proc] &block block will receive value from parameter defined in from_param argument, returned value will be used for new parameter value
|
58
|
+
#
|
59
|
+
# @return [void] <description>
|
60
|
+
#
|
61
|
+
def input_convert(from_param, to_param, &block)
|
62
|
+
@input_converters << ParamConverter.new(from_param, to_param, block)
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# See #input_convert
|
67
|
+
#
|
68
|
+
# @param [Symbol] from_param <description>
|
69
|
+
# @param [Symbol] to_param <description>
|
70
|
+
# @param [Proc] &block <description>
|
71
|
+
#
|
72
|
+
# @return [void] <description>
|
73
|
+
#
|
74
|
+
def output_convert(from_param, to_param, &block)
|
75
|
+
@output_converters << ParamConverter.new(from_param, to_param, block)
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def attach_hooks
|
81
|
+
_source = @source
|
82
|
+
_input_converters = @input_converters
|
83
|
+
_logger = logger
|
84
|
+
|
85
|
+
@core_hooks.attach :input_before_router do |input|
|
86
|
+
if input.source == _source
|
87
|
+
_input_converters.each do |converter|
|
88
|
+
next if input.send(converter.from_param).nil?
|
89
|
+
|
90
|
+
input.send("#{converter.to_param}=", converter.block.call(input.send(converter.from_param)))
|
91
|
+
rescue Exception => e
|
92
|
+
_logger.error "BatteriesBridge input param converter #{self.class} tried to convert #{converter.from_param} to #{converter.to_param} and experienced an error: #{e}"
|
93
|
+
|
94
|
+
raise unless @fail_gracefully
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
_output_converters = @output_converters
|
100
|
+
@core_hooks.attach :output_before_returned do |input, output|
|
101
|
+
if input.source == _source
|
102
|
+
_output_converters.each do |converter|
|
103
|
+
next if output.send(converter.from_param).nil?
|
104
|
+
|
105
|
+
output.send("#{converter.to_param}=", converter.block.call(output.send(converter.from_param)))
|
106
|
+
rescue Exception => e
|
107
|
+
_logger.error "BatteriesBridge output param converter #{self.class} tried to convert #{converter.from_param} to #{converter.to_param} and experienced an error: #{e}"
|
108
|
+
|
109
|
+
raise unless @fail_gracefully
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
#
|
116
|
+
# This method will be called by the plugin to setup bridge and provide needed dependencies
|
117
|
+
#
|
118
|
+
# @param [Kanal::Core::Hooks::HookStorage] core_hooks <description>
|
119
|
+
#
|
120
|
+
# @return [void] <description>
|
121
|
+
#
|
122
|
+
def internal_setup(core_hooks)
|
123
|
+
@core_hooks = core_hooks
|
124
|
+
|
125
|
+
setup
|
126
|
+
|
127
|
+
if @source.nil? || (@input_converters.empty? && @output_converters.empty?)
|
128
|
+
raise "Cannot setup #{self.class} without required parameters: source, at least one input/output converter"
|
129
|
+
end
|
130
|
+
|
131
|
+
attach_hooks
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "kanal"
|
4
|
+
require "kanal/plugins/batteries/attachments/attachment"
|
5
|
+
require_relative "./bridge"
|
6
|
+
|
7
|
+
module Kanal
|
8
|
+
module Plugins
|
9
|
+
module BatteriesBridge
|
10
|
+
module Bridges
|
11
|
+
class TelegramBridge < Bridge
|
12
|
+
include Kanal::Plugins::Batteries::Attachments
|
13
|
+
|
14
|
+
def setup
|
15
|
+
require_source :telegram
|
16
|
+
|
17
|
+
input_convert :tg_text, :body do |val|
|
18
|
+
val
|
19
|
+
end
|
20
|
+
|
21
|
+
input_convert :tg_button_pressed, :button_pressed do |val|
|
22
|
+
val
|
23
|
+
end
|
24
|
+
|
25
|
+
input_convert :tg_image_link, :image do |val|
|
26
|
+
Attachment.new val
|
27
|
+
end
|
28
|
+
|
29
|
+
input_convert :tg_audio_link, :audio do |val|
|
30
|
+
Attachment.new val
|
31
|
+
end
|
32
|
+
|
33
|
+
input_convert :tg_video_link, :video do |val|
|
34
|
+
Attachment.new val
|
35
|
+
end
|
36
|
+
|
37
|
+
input_convert :tg_document_link, :document do |val|
|
38
|
+
Attachment.new val
|
39
|
+
end
|
40
|
+
|
41
|
+
output_convert :body, :tg_text do |val|
|
42
|
+
val
|
43
|
+
end
|
44
|
+
|
45
|
+
output_convert :image, :tg_image_path do |val|
|
46
|
+
val
|
47
|
+
end
|
48
|
+
|
49
|
+
output_convert :audio, :tg_audio_path do |val|
|
50
|
+
val
|
51
|
+
end
|
52
|
+
|
53
|
+
output_convert :video, :tg_video_path do |val|
|
54
|
+
val
|
55
|
+
end
|
56
|
+
|
57
|
+
output_convert :document, :tg_document_path do |val|
|
58
|
+
val
|
59
|
+
end
|
60
|
+
|
61
|
+
output_convert :keyboard, :tg_reply_markup do |val|
|
62
|
+
val
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "batteries_bridge/version"
|
4
|
+
require_relative "./batteries_bridge/batteries_bridge_plugin"
|
5
|
+
|
6
|
+
module Kanal
|
7
|
+
module Plugins
|
8
|
+
module BatteriesBridge
|
9
|
+
class Error < StandardError; end
|
10
|
+
# Your code goes here...
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kanal-plugins-batteries_bridge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- idchlife
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This plugin provides transformation between different interface properties
|
14
|
+
(e.g. tg_audio, tg_image) to batteries properties. Input and also output
|
15
|
+
email:
|
16
|
+
- idchlife@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- ".ruby-version"
|
24
|
+
- CHANGELOG.md
|
25
|
+
- CODE_OF_CONDUCT.md
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- LICENSE.txt
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- kanal-plugins-batteries_bridge.gemspec
|
32
|
+
- lib/kanal/plugins/batteries_bridge.rb
|
33
|
+
- lib/kanal/plugins/batteries_bridge/batteries_bridge_plugin.rb
|
34
|
+
- lib/kanal/plugins/batteries_bridge/bridges/bridge.rb
|
35
|
+
- lib/kanal/plugins/batteries_bridge/bridges/telegram_bridge.rb
|
36
|
+
- lib/kanal/plugins/batteries_bridge/version.rb
|
37
|
+
- sig/kanal/plugins/batteries_bridge.rbs
|
38
|
+
homepage: https://github.com/idchlife/kanal-plugins-batteries_bridge
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
allowed_push_host: https://rubygems.org
|
43
|
+
homepage_uri: https://github.com/idchlife/kanal-plugins-batteries_bridge
|
44
|
+
source_code_uri: https://github.com/idchlife/kanal-plugins-batteries_bridge
|
45
|
+
changelog_uri: https://github.com/idchlife/kanal-plugins-batteries_bridge/CHANGELOG.md
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.7.6
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.1.6
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Bridge between Kanal Batteries plugin and different interfaces
|
65
|
+
test_files: []
|