1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-04 02:05:52 +03:00
* Update rubopcop [WIP]

* Further rubocop fixes

* Fix rubocop-rails cops

* Fix spec

* Disable rubocop suggestions

* Run rubocop in github actions rather than in codeclimate
Этот коммит содержится в:
Max Melentiev
2023-12-30 15:20:27 +00:00
коммит произвёл GitHub
родитель 7bcb0caded
Коммит 57b17f068c
82 изменённых файлов: 303 добавлений и 134 удалений

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Telegram
module Bot
class UpdatesController

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

@@ -1,9 +1,11 @@
# frozen_string_literal: true
module Telegram
module Bot
class UpdatesController
# Support for parsing commands
module Commands
CMD_REGEX = %r{\A/([a-z\d_]{,31})(@(\S+))?(\s|$)}i
CMD_REGEX = %r{\A/([a-z\d_]{,31})(@(\S+))?(\s|$)}i.freeze
class << self
# Fetches command from text message. All subsequent words are returned
@@ -34,7 +36,7 @@ module Telegram
def action_for_message
cmd, args = Commands.command_from_text(payload['text'], bot_username)
return unless cmd
[[action_for_command(cmd), type: :command, command: cmd], args]
[[action_for_command(cmd), {type: :command, command: cmd}], args]
end
alias_method :action_for_channel_post, :action_for_message

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Telegram
module Bot
class UpdatesController
@@ -23,8 +25,8 @@ module Telegram
def process_action(*args)
raw_payload = {
controller: self.class.name,
action: action_name,
update: update,
action: action_name,
update: update,
}
Instrumentation.instrument(:start_processing, raw_payload.dup)
Instrumentation.instrument(:process_action, raw_payload) do |payload|
@@ -61,14 +63,14 @@ module Telegram
# end
#
# :api: plugin
def cleanup_view_runtime #:nodoc:
def cleanup_view_runtime # :nodoc:
yield
end
# Every time after an action is processed, this method is invoked
# with the payload, so you can add more information.
# :api: plugin
def append_info_to_payload(_payload) #:nodoc:
def append_info_to_payload(_payload) # :nodoc:
end
module ClassMethods
@@ -76,7 +78,7 @@ module Telegram
# controller process action. This method should return an array
# with the messages to be added.
# :api: plugin
def log_process_action(_payload) #:nodoc:
def log_process_action(_payload) # :nodoc:
[]
end
end

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'active_support/log_subscriber'
module Telegram
@@ -8,7 +10,7 @@ module Telegram
info do
payload = event.payload
"Processing by #{payload[:controller]}##{payload[:action]}\n" \
" Update: #{payload[:update].to_json}"
" Update: #{payload[:update].to_json}"
end
end

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Telegram
module Bot
class UpdatesController
@@ -48,12 +50,12 @@ module Telegram
# it has higher priority than contextual action.
def action_for_message
val = message_context_session.delete(:context)
context = val && val.to_s
super || context && begin
args = payload['text'].try!(:split) || []
context = val&.to_s
super || (context && begin
args = payload['text']&.split || []
action = action_for_message_context(context)
[[action, type: :message_context, context: context], args]
end
[[action, {type: :message_context, context: context}], args]
end)
end
# Save context for the next request.

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Telegram
module Bot
class UpdatesController
@@ -59,9 +61,9 @@ module Telegram
# Edit message from callback query.
def edit_message(type, params = {})
params =
if message_id = payload['inline_message_id'] # rubocop:disable AssignmentInCondition
if message_id = payload['inline_message_id'] # rubocop:disable Lint/AssignmentInCondition
params.merge(inline_message_id: message_id)
elsif message = payload['message'] # rubocop:disable AssignmentInCondition
elsif message = payload['message'] # rubocop:disable Lint/AssignmentInCondition
params.merge(chat_id: message['chat']['id'], message_id: message['message_id'])
else
raise 'Can not edit message without `inline_message_id` or `message`'

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'active_support/rescuable'
module Telegram
@@ -11,7 +13,7 @@ module Telegram
def process_action(*)
super
rescue Exception => exception # rubocop:disable RescueException
rescue Exception => exception # rubocop:disable Lint/RescueException
rescue_with_handler(exception) || raise
end
end

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'telegram/bot/updates_controller/testing'
require 'telegram/bot/rspec/message_helpers'
require 'telegram/bot/rspec/callback_query_helpers'

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rack/session/abstract/id'
require 'active_support/cache'
@@ -27,7 +29,8 @@ module Telegram
protected
def session
@_session ||= self.class.build_session(session_key)
@_session ||= # rubocop:disable Naming/MemoizedInstanceVariableName
self.class.build_session(session_key)
end
def session_key
@@ -41,7 +44,7 @@ module Telegram
class SessionHash < Rack::Session::Abstract::SessionHash
attr_reader :id
def initialize(store, id)
def initialize(store, id) # rubocop:disable Lint/MissingSuper
@store = store
@id = id
end
@@ -65,13 +68,13 @@ module Telegram
def commit
return unless loaded?
data = to_hash.delete_if { |_, v| v.nil? }
data = to_hash.compact
@store.write(id, data)
end
end
class NullSessionHash < Session::SessionHash
def initialize
def initialize # rubocop:disable Lint/MissingSuper
@data = {}
@loaded = true
@exists = true

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Telegram
module Bot
class UpdatesController
@@ -16,7 +18,7 @@ module Telegram
# everything will be rewriten with #initialize.
#
# With `full` set to `true` it'll clear all cached instance variables.
def recycle!(full = false)
def recycle!(full = false) # rubocop:disable Style/OptionalBooleanParameter
return unless full
(instance_variables - IVARS_TO_KEEP).each do |ivar|
remove_instance_variable(ivar)
@@ -27,7 +29,8 @@ module Telegram
# Stubs session.
def session
@_session ||= Session::NullSessionHash.new
@_session ||= # rubocop:disable Naming/MemoizedInstanceVariableName
Session::NullSessionHash.new
end
end
end

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Telegram
module Bot
class UpdatesController

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

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Telegram
module Bot
class UpdatesController