action_bot 0.1.24 → 0.1.25

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
- SHA256:
3
- metadata.gz: 47c36b9257696e78a0dc4f4ac529f6832d4a8c1135cbed2ba4cadb0871a57aa8
4
- data.tar.gz: 003ef51876d760f47dbd0d728a5e334d4a3448a8cf881b548be55e759ce73cf2
2
+ SHA1:
3
+ metadata.gz: a2abf6fec339495d34e7bfaea54c18f53ab877f3
4
+ data.tar.gz: e5651e09a6f7f6e282bfb225e65511ac4c602c74
5
5
  SHA512:
6
- metadata.gz: 5f2b46e3cfa96dfde707c39764f045f675d845913b374cea877c2edfc9006bdb4cdca59de118b94bf0692451798a04e9697d817238ddac85161a4341897f1490
7
- data.tar.gz: 3cf2e11c6580db7abf50f77a929b07dbc38d544bd350079a8f8c860fc10eef8fb7afaef24e2ec190a948f5d0912b8529d1cbade4980ab86b97067a632980e735
6
+ metadata.gz: 31f49eec32c2520f9c87ad3507c70dbd7d1d43f7260000d7db78340136a13d82fe4998e36f59be03335b3e52e5094660b5dc330d9231eb3b883a86d591e72380
7
+ data.tar.gz: f721395167421a56d52c05ae1e0cd5d00b575e7ec8bc11781682715be77cd33c7a1c3bacf1f587c3d762fbd7ba16ebf16a37864a540cfc279e52b8fa129e641e
metadata CHANGED
@@ -1,142 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.24
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Barseek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-12 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: telegram-bot-ruby
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.16.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.16.0
27
- - !ruby/object:Gem::Dependency
28
- name: pg
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 1.2.3
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 1.2.3
41
- - !ruby/object:Gem::Dependency
42
- name: activesupport
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '6.1'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '6.1'
55
- - !ruby/object:Gem::Dependency
56
- name: activerecord
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '6.1'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '6.1'
69
- - !ruby/object:Gem::Dependency
70
- name: actionpack
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '6.1'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '6.1'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '13.0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '13.0'
97
- - !ruby/object:Gem::Dependency
98
- name: i18n
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.8'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '1.8'
111
- description: Create telegram bots with rails like structure with ease
11
+ date: 2022-04-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
112
14
  email: sergey.b@hey.com
113
15
  executables: []
114
16
  extensions: []
115
17
  extra_rdoc_files: []
116
18
  files:
117
- - Gemfile
118
- - Rakefile
119
19
  - lib/action_bot.rb
120
- - lib/action_bot/base.rb
121
- - lib/action_bot/controller.rb
122
- - lib/action_bot/runner.rb
123
- - lib/concerns/configurable.rb
124
- - lib/configuration/configurators/app_configurator.rb
125
- - lib/configuration/configurators/bot_configurator.rb
126
- - lib/configuration/configurators/db_configurator.rb
127
- - lib/configuration/configurators/i18n_configurator.rb
128
- - lib/tasks/bot_scaffold.rake
129
- - scaffolds/bin/example_long_polling_bot_runner.rb
130
- - scaffolds/bin/example_webhook_bot_runner.rb
131
- - scaffolds/bots/example_long_polling_bot.rb
132
- - scaffolds/bots/example_webhook_bot.rb
133
- - scaffolds/config/configuration.rb
134
- - scaffolds/config/secrets/database.yml
135
- - scaffolds/config/secrets/locales.yml
136
- - scaffolds/config/secrets/token.yml
137
- - scaffolds/controllers/bots_controller.rb
138
- - scaffolds/controllers/hello_controller.rb
139
- homepage: https://rubygems.org/gems/hola
20
+ homepage:
140
21
  licenses:
141
22
  - MIT
142
23
  metadata: {}
@@ -155,8 +36,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
36
  - !ruby/object:Gem::Version
156
37
  version: '0'
157
38
  requirements: []
158
- rubygems_version: 3.2.29
39
+ rubyforge_project:
40
+ rubygems_version: 2.6.14.3
159
41
  signing_key:
160
42
  specification_version: 4
161
- summary: Telegram Bots gem for ruby
43
+ summary: Create telegram bots with rails like structure with ease
162
44
  test_files: []
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'telegram-bot-ruby'
4
- gem 'pg'
5
- gem 'activesupport'
6
- gem 'activerecord'
7
- gem 'actionpack'
8
- gem 'rake'
9
- gem 'i18n'
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- import "./lib/tasks/bot_scaffold.rake"
@@ -1,31 +0,0 @@
1
- module ActionBot
2
- class Base
3
- include Configurable.with(:api, :bot)
4
-
5
- def on(condition, **kwargs)
6
- return unless condition
7
-
8
- params = kwargs.delete(:params) || {}
9
- controller, action = kwargs.first
10
- controller_object = "#{controller.to_s.camelize}Controller".constantize.new
11
- raise "No such method: #{action} for #{controller}" unless controller_object.respond_to?(action)
12
-
13
- controller_object.params = ActionController::Parameters.new params
14
- controller_object.public_send(action)
15
- throw(:done)
16
- end
17
-
18
- def action(**kwargs)
19
- params = kwargs.delete(:params) || {}
20
- controller, action = kwargs.first
21
- controller_object = "#{controller.to_s.camelize}Controller".constantize.new
22
- raise "No such method: #{action} for #{controller}" unless controller_object.respond_to?(action)
23
- controller_object.params = ActionController::Parameters.new params
24
- controller_object.public_send(action)
25
- end
26
-
27
- def bot_runner
28
- ActionBot::Runner
29
- end
30
- end
31
- end
@@ -1,51 +0,0 @@
1
- module ActionBot
2
- class Controller
3
- attr_accessor :params
4
-
5
- def notify(tg_chat_id, text, mode = nil)
6
- return notify_chat(tg_chat_id, text, mode) unless text.respond_to?(:each)
7
-
8
- text.each do |message|
9
- sleep(0.5)
10
- notify_chat(tg_chat_id, message, mode)
11
- end
12
- end
13
-
14
- def mention(id, name)
15
- "[#{name}](tg://user?id=#{id})"
16
- end
17
-
18
- def t(*args)
19
- I18n.locale = load_chat.locale if respond_to?(:load_chat)
20
- I18n.t(*args)
21
- end
22
-
23
- def api
24
- ActionBot::Base.config.api || bot.api
25
- end
26
-
27
- def bot
28
- ActionBot::Base.config.bot
29
- end
30
-
31
- private
32
-
33
- attr_reader :error
34
-
35
- def notify_chat(chat_id, text, mode)
36
- api.send_message(chat_id: chat_id, text: text, parse_mode: mode)
37
- rescue Telegram::Bot::Exceptions::ResponseError => error
38
- @error = error
39
- return sleep(error.response.env.response_headers["retry-after"].to_i) if error_too_many_requests?
40
- return Chat.find_by(tg_chat_id: chat_id).destroy! if error_chat_does_not_exist?
41
- end
42
-
43
- def error_too_many_requests?
44
- error.response.status == 429
45
- end
46
-
47
- def error_chat_does_not_exist?
48
- error.instance_variable_get("@data")["description"] == "Forbidden: the group chat was deleted"
49
- end
50
- end
51
- end
@@ -1,7 +0,0 @@
1
- module ActionBot
2
- class Runner < Telegram::Bot::Client
3
- def self.run(*_, &block)
4
- super(BotConfigurator.config.token, &block)
5
- end
6
- end
7
- end
@@ -1,22 +0,0 @@
1
- require 'active_support/all'
2
-
3
- module Configurable
4
- def self.with(*args)
5
- config_class = Class.new do
6
- attr_accessor *args
7
- end
8
-
9
- Module.new do
10
- extend ActiveSupport::Concern
11
- class_methods do
12
- define_method :configure do |&block|
13
- block.call config
14
- end
15
-
16
- define_method :config do
17
- @config ||= config_class.new
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,31 +0,0 @@
1
- class AppConfigurator
2
- ATTRIBUTES = %i( token db_url pashalka i18n_load_path i18n_locale i18n_available_locales ).freeze
3
- include Configurable.with(*ATTRIBUTES)
4
-
5
- def self.configure(*args)
6
- super
7
- configure_i18n
8
- configure_db
9
- configure_bot
10
- end
11
-
12
- def self.configure_db
13
- DBConfigurator.configure do |configuration|
14
- configuration.db_url = config.db_url
15
- end if config.db_url
16
- end
17
-
18
- def self.configure_i18n
19
- I18nConfigurator.configure do |configuration|
20
- configuration.load_path = config.i18n_load_path
21
- configuration.locale = config.i18n_locale
22
- configuration.available_locales = config.i18n_available_locales
23
- end
24
- end
25
-
26
- def self.configure_bot
27
- BotConfigurator.configure do |configuration|
28
- configuration.token = config.token
29
- end
30
- end
31
- end
@@ -1,13 +0,0 @@
1
- require_relative '../../concerns/configurable'
2
-
3
- class BotConfigurator
4
- ATTRIBUTES = %i( token ).freeze
5
- include Configurable.with(*ATTRIBUTES)
6
-
7
-
8
- def self.configure(*args)
9
- puts 'Configuring bot...'
10
- super *args
11
- puts 'Finished'
12
- end
13
- end
@@ -1,12 +0,0 @@
1
- class DBConfigurator
2
- ATTRIBUTES = %i( db_url ).freeze
3
- include Configurable.with(*ATTRIBUTES)
4
-
5
- def self.configure(*args)
6
- puts 'Configuring db...'
7
- super *args
8
- connection_details = config.db_url
9
- connection = ActiveRecord::Base.establish_connection(connection_details)
10
- puts 'Finished'
11
- end
12
- end
@@ -1,13 +0,0 @@
1
- class I18nConfigurator
2
- ATTRIBUTES = %i( load_path locale available_locales ).freeze
3
- include Configurable.with(*ATTRIBUTES)
4
-
5
- def self.configure(*args)
6
- puts 'Configuring i18n...'
7
- super *args
8
- puts 'Finished'
9
- ATTRIBUTES.each do |attr|
10
- I18n.public_send("#{attr}=", config.public_send("#{attr}"))
11
- end
12
- end
13
- end
@@ -1,6 +0,0 @@
1
- spec = Gem::Specification.find_by_name 'action_bot'
2
-
3
- desc 'Generate files for the bot'
4
- task :bot_scaffold do
5
- FileUtils.cp_r "#{spec.gem_dir}/scaffolds/.", "#{Dir.pwd}"
6
- end
@@ -1,7 +0,0 @@
1
- require 'action_bot'
2
-
3
- require_relative '../config/configuration'
4
- require_relative '../bots/example_long_polling_bot'
5
-
6
-
7
- ExampleLongPollingBot.call
@@ -1,20 +0,0 @@
1
- require 'sinatra'
2
- require 'action_bot'
3
-
4
- require_relative '../config/configuration'
5
- require_relative '../bots/example_webhook_bot'
6
- use Rack::Logger
7
-
8
- helpers do
9
- def logger
10
- request.logger
11
- end
12
- end
13
-
14
- # Telegram requires GET endpoint to setup a webhook
15
- get '/webhook' do
16
- end
17
-
18
- post '/webhook' do
19
- # Do stuff with request here
20
- end
@@ -1,37 +0,0 @@
1
- class ExampleLongPollingBot < ActionBot::Base
2
- def call
3
- bot_runner.run do |bot|
4
- ActionBot::Base.configure do |config|
5
- config.bot = bot
6
- end
7
-
8
- bot.listen do |message|
9
- @message = message
10
- run
11
- end
12
- end
13
- end
14
-
15
- def self.call
16
- new.call
17
- end
18
-
19
- def run
20
- return unless message_legal?
21
- catch(:done) do
22
- on @message.text == 'hello_world', hello: :world, params: {
23
- tg_chat_id: tg_chat_id
24
- }
25
- end
26
- end
27
-
28
- private
29
-
30
- def message_legal?
31
- @message.respond_to?(:text) && @message.text
32
- end
33
-
34
- def tg_chat_id
35
- @message.chat.id
36
- end
37
- end
@@ -1,21 +0,0 @@
1
- class ExampleWebhookBot < ActionBot::Base
2
- def initialize
3
- @api = Telegram::Bot::Api.new(AppConfigurator.config.token)
4
- ActionBot::Base.configure do |config|
5
- config.api = @api
6
- end
7
- end
8
-
9
- def run(message)
10
- @message = message
11
-
12
- return unless message_legal?
13
- catch(:done) do
14
- on message == 'hello_world', hello: :world
15
- end
16
- end
17
-
18
- def message_legal?
19
- @message.respond_to?(:text) && @message.text
20
- end
21
- end
@@ -1,20 +0,0 @@
1
- AppConfigurator.configure do |config|
2
- # Configure bot
3
- config.token = begin
4
- YAML::load(IO.read('config/secrets/token.yml'))['telegram_bot_token']
5
- rescue Errno::ENOENT
6
- ENV["TOKEN"]
7
- end
8
-
9
- # Configure database
10
- # config.db_url = begin
11
- # YAML::load(IO.read('config/secrets/database.yml'))["database_url"]
12
- # rescue Errno::ENOENT
13
- # ENV["DATABASE_URL"]
14
- # end
15
-
16
- # Configure i18n
17
- config.i18n_locale = :en
18
- config.i18n_load_path = Dir['config/secrets/locales.yml']
19
- config.i18n_available_locales = %i[en]
20
- end
@@ -1 +0,0 @@
1
- database_url: postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]
@@ -1,2 +0,0 @@
1
- en:
2
- hello_world: "Hello world!"
@@ -1 +0,0 @@
1
- telegram_bot_token: your-tg-bot-token
@@ -1,2 +0,0 @@
1
- class BotsController < ActionBot::Controller
2
- end
@@ -1,5 +0,0 @@
1
- class HelloController < BotsController
2
- def world
3
- notify(params[:tg_chat_id], t('hello_world'))
4
- end
5
- end