1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-03 17:55:52 +03:00

Сравнить коммиты

...

7 Коммитов

Автор SHA1 Сообщение Дата
Max Melentiev
f61cc1e536 v0.7.4 2016-05-31 17:44:24 +03:00
printercu
2f7ff9d50e Merge pull request #4 from dreyks/rails5
Rails5 compatibility
2016-05-31 17:34:31 +03:00
Roman Usherenko
aca35a1934 Rails5 compatibility 2016-05-31 17:12:36 +03:00
Max Melentiev
5bf98b419b v0.7.3 2016-05-31 11:49:54 +03:00
Max Melentiev
8077ef9bcf Fixed issues with poller in production. Fixes #3 2016-05-31 11:46:58 +03:00
Max Melentiev
5fef6fb43a v0.7.2 2016-05-31 11:02:55 +03:00
Max Melentiev
07be01c07d Bot API 2.1 2016-05-31 11:01:00 +03:00
10 изменённых файлов: 69 добавлений и 15 удалений

Просмотреть файл

@@ -1,4 +1,18 @@
# 0.7.0 Unreleased # 0.7.4
- Rails 5 support by @dreyks (#4).
# 0.7.3
- Fixed issues with poller in production (#3)
# 0.7.2
- Bot API 2.1
- Fixed possible crashes when payload type is not supported.
Provides empty session when neither `from` nor `chat` is defined.
# 0.7.0
- New Bot API methods. - New Bot API methods.
- Helpers for inline keyboards, support for callback_query (with contextual actions). - Helpers for inline keyboards, support for callback_query (with contextual actions).

Просмотреть файл

@@ -1,9 +1,14 @@
namespace :telegram do namespace :telegram do
namespace :bot do namespace :bot do
desc 'Run poller' desc 'Run poller. It broadcasts Rails.logger to STDOUT in dev like `rails s` do. ' \
task poller: :environment do 'Use LOG_TO_STDOUT to enable/disable broadcasting.'
console = ActiveSupport::Logger.new(STDERR) task :poller do
Rails.logger.extend ActiveSupport::Logger.broadcast console ENV['BOT_POLLER_MODE'] = 'true'
Rake::Task['environment'].invoke
if ENV.fetch('LOG_TO_STDOUT') { Rails.env.development? }.present?
console = ActiveSupport::Logger.new(STDERR)
Rails.logger.extend ActiveSupport::Logger.broadcast console
end
Telegram::Bot::UpdatesPoller.start(ENV['BOT'].try!(:to_sym) || :default) Telegram::Bot::UpdatesPoller.start(ENV['BOT'].try!(:to_sym) || :default)
end end

Просмотреть файл

@@ -71,11 +71,16 @@ module Telegram
answerCallbackQuery answerCallbackQuery
answerInlineQuery answerInlineQuery
forwardMessage forwardMessage
getChat
getChatAdministrators
getChatMember
getChatMembersCount
getFile getFile
getMe getMe
getUpdates getUpdates
getUserProfilePhotos getUserProfilePhotos
kickChatMember kickChatMember
leaveChat
sendAudio sendAudio
sendChatAction sendChatAction
sendContact sendContact

Просмотреть файл

@@ -14,9 +14,14 @@ module Telegram
# It just tells routes helpers whether to add routed bots to # It just tells routes helpers whether to add routed bots to
# Bot::UpdatesPoller, so their config will be available by bot key in # Bot::UpdatesPoller, so their config will be available by bot key in
# Bot::UpdatesPoller.start. # Bot::UpdatesPoller.start.
#
# It's enabled by default in Rails dev environment and `rake telegram:bot:poller`
# task. Use `BOT_POLLER_MODE=true` envvar to set it manually.
def bot_poller_mode? def bot_poller_mode?
return @bot_poller_mode if defined?(@bot_poller_mode) return @bot_poller_mode if defined?(@bot_poller_mode)
Rails.env.development? if defined?(Rails) @bot_poller_mode = ENV.fetch('BOT_POLLER_MODE') do
Rails.env.development? if defined?(Rails)
end
end end
# Hash of bots made with bots_config. # Hash of bots made with bots_config.

Просмотреть файл

@@ -50,7 +50,7 @@ module Telegram
# ControllerClass.new(bot, from: telegram_user, chat: telegram_chat). # ControllerClass.new(bot, from: telegram_user, chat: telegram_chat).
# process(:help, *args) # process(:help, *args)
# #
class UpdatesController < AbstractController::Base class UpdatesController < AbstractController::Base # rubocop:disable ClassLength
abstract! abstract!
require 'telegram/bot/updates_controller/session' require 'telegram/bot/updates_controller/session'
@@ -84,6 +84,7 @@ module Telegram
inline_query inline_query
chosen_inline_result chosen_inline_result
callback_query callback_query
edited_message
).freeze ).freeze
CMD_REGEX = %r{\A/([a-z\d_]{,31})(@(\S+))?(\s|$)}i CMD_REGEX = %r{\A/([a-z\d_]{,31})(@(\S+))?(\s|$)}i
CONFLICT_CMD_REGEX = Regexp.new("^(#{PAYLOAD_TYPES.join('|')}|\\d)") CONFLICT_CMD_REGEX = Regexp.new("^(#{PAYLOAD_TYPES.join('|')}|\\d)")
@@ -180,6 +181,11 @@ module Telegram
[true, cmd, args] if cmd [true, cmd, args] if cmd
end end
# It doesn't extract commands from edited messages. Just process
# them as usual ones.
def action_for_edited_message
end
def action_for_inline_query def action_for_inline_query
[false, payload_type, [payload['query'], payload['offset']]] [false, payload_type, [payload['query'], payload['offset']]]
end end

Просмотреть файл

@@ -6,7 +6,7 @@ module Telegram
module Instrumentation module Instrumentation
class << self class << self
def prepended(base) def prepended(base)
base.config_accessor :logger base.send :config_accessor, :logger
base.extend ClassMethods base.extend ClassMethods
end end

Просмотреть файл

@@ -77,11 +77,25 @@ module Telegram
def reload! def reload!
return yield unless reload return yield unless reload
ActionDispatch::Reloader.prepare! reloading_code do
if controller.is_a?(Class) && controller.name if controller.is_a?(Class) && controller.name
@controller = Object.const_get(controller.name) @controller = Object.const_get(controller.name)
end
yield
end
end
if defined?(Rails) && Rails.application.respond_to?(:reloader)
def reloading_code
Rails.application.reloader.wrap do
yield
end
end
else
def reloading_code
ActionDispatch::Reloader.prepare!
yield.tap { ActionDispatch::Reloader.cleanup! }
end end
yield.tap { ActionDispatch::Reloader.cleanup! }
end end
end end
end end

Просмотреть файл

@@ -1,6 +1,6 @@
module Telegram module Telegram
module Bot module Bot
VERSION = '0.7.0'.freeze VERSION = '0.7.4'.freeze
def self.gem_version def self.gem_version
Gem::Version.new VERSION Gem::Version.new VERSION

Просмотреть файл

@@ -102,6 +102,11 @@ RSpec.describe Telegram::Bot::UpdatesController do
it { should eq [false, payload_type, payload.values_at(:data)] } it { should eq [false, payload_type, payload.values_at(:data)] }
end end
context 'when payload is edited_message' do
let(:payload_type) { 'edited_message' }
it { should eq [false, payload_type, [payload]] }
end
context 'when payload is not supported' do context 'when payload is not supported' do
let(:payload_type) { '_unsupported_' } let(:payload_type) { '_unsupported_' }
it { should eq [false, :unsupported_payload_type, []] } it { should eq [false, :unsupported_payload_type, []] }

Просмотреть файл

@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '~> 2.0' spec.required_ruby_version = '~> 2.0'
spec.add_dependency 'activesupport', '~> 4.0' spec.add_dependency 'activesupport', '>= 4.0', '< 5.1'
spec.add_dependency 'actionpack', '~> 4.0' spec.add_dependency 'actionpack', '>= 4.0', '< 5.1'
spec.add_dependency 'httpclient', '~> 2.7' spec.add_dependency 'httpclient', '~> 2.7'
spec.add_development_dependency 'bundler', '~> 1.11' spec.add_development_dependency 'bundler', '~> 1.11'
spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rake', '~> 10.0'