Skip to content

Commit

Permalink
Merge pull request #45 from southbridgeio/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vladislav-yashin authored Jan 28, 2020
2 parents 0b24544 + 0f8f7fb commit 3d08b7f
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 26 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: ruby
rvm:
- 2.4.9
- 2.6.5
- 2.7.0

branches:
only:
Expand All @@ -16,11 +15,6 @@ env:
- REDMINE_VER=3.4-stable
- REDMINE_VER=4.1-stable

matrix:
exclude:
- env: REDMINE_VER=3.4-stable
rvm: 2.7.0

install: "echo skip bundle install"

before_script:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 0.4.1

* Fix tdlib proxy
* Fix AddBot command
* Fix robot_id detection
* Release ActiveRecord connections in concurrent-ruby threads
* Remove ruby 2.7.0 from build matrix
* Update sidekiq-rate-limiter

# 0.4.0

* Handle Faraday::ClientError in MessageSender
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
gem 'pidfile', git: 'https://github.com/arturtr/pidfile.git'
gem 'sidekiq-cron'
gem 'sidekiq-rate-limiter', git: 'https://github.com/centosadmin/sidekiq-rate-limiter', branch: 'master',
require: 'sidekiq-rate-limiter/server'
gem 'sidekiq-rate-limiter', '0.1.3', require: 'sidekiq-rate-limiter/server'

gem 'telegram-bot-ruby', '>= 0.11', '< 1.0'
gem 'slack-ruby-bot'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/redmine_telegram_setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def authorize
promise = RedmineBots::Telegram::Tdlib::Authenticate.(params).then do
RedmineBots::Telegram::Tdlib::FetchAllChats.call
end.flat.then do
save_phone_settings(phone_number: params['phone_number'])
ActiveRecord::Base.connection_pool.with_connection { save_phone_settings(phone_number: params['phone_number']) }
redirect_to plugin_settings_path('redmine_bots'), notice: t('redmine_bots.telegram.authorize.success')
end

Expand Down
4 changes: 3 additions & 1 deletion app/workers/telegram_accounts_refresh_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class TelegramAccountsRefreshWorker
def perform
TelegramAccount.where.not(telegram_id: nil).find_each do |account|
RedmineBots::Telegram::Tdlib::GetUser.(account.telegram_id).then do |user|
account.update_attributes(user.to_h.slice(*%w[username first_name last_name]))
ActiveRecord::Base.connection_pool.with_connection do
account.update_attributes(user.to_h.slice(*%w[username first_name last_name]))
end
end.wait
end
end
Expand Down
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
name 'Redmine Bots'
url 'https://github.com/southbridgeio/redmine_bots'
description 'This is a platform for building Redmine bots'
version '0.4.0'
version '0.4.1'
author 'Southbridge'
author_url 'https://github.com/southbridgeio'

Expand Down
16 changes: 3 additions & 13 deletions lib/redmine_bots/telegram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,16 @@ def self.init_bot
self_info = {}

if Setting.plugin_redmine_bots['telegram_phone_number'].present?
self_info = Tdlib::GetMe.call.rescue do
raise 'Please, set correct settings for plugin RedmineBots::Telegram'
end.value!.to_h
self_info = Tdlib::GetMe.call.rescue { {} }.value!.to_h
end

robot_id = self_info['id']
robot_id = self_info[:id]

bot = Telegram::Bot::Client.new(token)
bot_info = bot.api.get_me['result']
bot_name = bot_info['username']

until bot_name.present?
sleep 60

bot = Telegram::Bot::Client.new(token)
bot_info = bot.api.get_me['result']
bot_name = bot_info['username']

RedmineBots::Telegram::Tdlib::AddBot.(bot_name) if robot_id
end
RedmineBots::Telegram::Tdlib::AddBot.(bot_name) if robot_id

plugin_settings = Setting.find_by(name: 'plugin_redmine_bots')

Expand Down
6 changes: 5 additions & 1 deletion lib/redmine_bots/telegram/tdlib/close_chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def call(chat_id)

def fetch_robot_ids
Promises.zip(
Promises.future { Setting.find_by(name: 'plugin_redmine_bots').value['telegram_bot_id'].to_i },
Promises.future do
ActiveRecord::Base.connection_pool.with_connection do
Setting.find_by(name: 'plugin_redmine_bots').value['telegram_bot_id'].to_i
end
end,
client.get_me.then(&:id)
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine_bots/telegram/tdlib/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def connect

if settings['tdlib_use_proxy'] && proxy = TelegramProxy.alive.socks5.first
type = TD::Types::ProxyType::Socks5.new(username: proxy.user, password: proxy.password)
client.add_proxy(proxy.host, proxy.port, type, false).then do |td_proxy|
client.add_proxy(proxy.host, proxy.port, false, type).then do |td_proxy|
client.enable_proxy(td_proxy.id)
end.flat.then { client.ready }
else
Expand Down

0 comments on commit 3d08b7f

Please sign in to comment.