Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions app/controllers/concerns/telegram/admin_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def channels!(*args)
# Проверяем права доступа
unless current_user&.is_admin?
Rails.logger.warn "Unauthorized access attempt to /channels by user #{current_user&.username}"
respond_with :message, text: I18n.t('telegram_bot.channels.list.admin_only')
respond_with :message, text: I18n.t('telegram_bot.channels.admin_list.admin_only')
return
end

Expand All @@ -22,7 +22,7 @@ def channels!(*args)
channels_with_subscribers = get_channels_with_subscribers(page, per_page)

if channels_with_subscribers[:channels].empty?
respond_with :message, text: I18n.t('telegram_bot.channels.list.empty')
respond_with :message, text: I18n.t('telegram_bot.channels.admin_list.empty')
return
end

Expand All @@ -44,7 +44,7 @@ def channels!(*args)
# Callback query для пагинации списка каналов
def channels_page_callback_query(page = nil)
unless current_user&.is_admin?
answer_callback_query(I18n.t('telegram_bot.channels.list.admin_only'))
answer_callback_query(I18n.t('telegram_bot.channels.admin_list.admin_only'))
return
end

Expand All @@ -58,7 +58,7 @@ def channels_page_callback_query(page = nil)
channels_with_subscribers = get_channels_with_subscribers(page, per_page)

if channels_with_subscribers[:channels].empty?
edit_message :text, text: I18n.t('telegram_bot.channels.list.empty')
edit_message :text, text: I18n.t('telegram_bot.channels.admin_list.empty')
return
end

Expand Down Expand Up @@ -125,7 +125,7 @@ def build_channels_list_message(channels_data)
total_count = channels_data[:total_count]

message_parts = []
message_parts << "📊 Список каналов в системе (всего: #{total_count})"
message_parts << I18n.t('telegram_bot.channels.admin_list.title', count: total_count)
message_parts << ''

channels.each_with_index do |channel, index|
Expand Down Expand Up @@ -160,7 +160,7 @@ def build_channels_list_message(channels_data)
# Добавляем информацию о пагинации
if total_pages > 1
message_parts << ''
message_parts << "Страница #{current_page} из #{total_pages}"
message_parts << I18n.t('telegram_bot.channels.admin_list.pagination_info', current: current_page, total: total_pages)
end

message_parts.join("\n")
Expand All @@ -182,19 +182,19 @@ def format_subscribers_count(count)
count = count.to_i

if count == 0
'0 подписчиков'
I18n.t('telegram_bot.channels.admin_list.subscribers', count: 0)
elsif count == 1
'1 подписчик'
elsif count >= 2 && count <= 4
"#{count} подписчика"
elsif count >= 5 && count <= 20
"#{count} подписчиков"
I18n.t('telegram_bot.channels.admin_list.subscribers', count: count)
elsif count % 10 == 1
"#{count} подписчик"
elsif count % 10 >= 2 && count % 10 <= 4
"#{count} подписчика"
else
"#{count} подписчиков"
I18n.t('telegram_bot.channels.admin_list.subscribers', count: count)
end
end

Expand All @@ -203,7 +203,7 @@ def format_last_post_time(last_post_at)
return 'Нет постов' unless last_post_at

time_ago = time_ago_in_words(last_post_at)
"Последний пост: #{time_ago}"
"#{I18n.t('telegram_bot.channels.admin_list.last_post')} #{time_ago}"
end

# Создает клавиатуру для списка каналов
Expand All @@ -220,35 +220,35 @@ def build_channels_list_keyboard(channels_data, current_page)
# Кнопка "Предыдущая"
if current_page > 1
nav_buttons << callback_button(
'← Предыдущая',
I18n.t('telegram_bot.channels.admin_list.previous_page'),
"channels_page:#{current_page - 1}"
)
end

# Кнопка "Следующая"
if current_page < total_pages
nav_buttons << callback_button(
'Следующая →',
I18n.t('telegram_bot.channels.admin_list.next_page'),
"channels_page:#{current_page + 1}"
)
end

buttons << nav_buttons if nav_buttons.any?

# Кнопка закрытия
buttons << [ callback_button('✖️ Закрыть', 'close_channels_list:') ]
buttons << [ callback_button(I18n.t('telegram_bot.channels.admin_list.close'), 'close_channels_list:') ]

inline_keyboard(*buttons)
end

# Callback query для закрытия списка каналов
def close_channels_list_callback_query(*)
unless current_user&.is_admin?
answer_callback_query(I18n.t('telegram_bot.channels.list.admin_only'))
answer_callback_query(I18n.t('telegram_bot.channels.admin_list.admin_only'))
return
end

answer_callback_query('Список каналов закрыт')
answer_callback_query(I18n.t('telegram_bot.channels.admin_list.closed'))

# Удаляем сообщение или заменяем его на простое сообщение
begin
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/telegram/subscription_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def confirm_remove_callback_query(channel_id)

# Построить текст списка подписок
def build_subscriptions_list(subscriptions)
text = "#{I18n.t('telegram_bot.channels.list.title')}\n\n"
text = "#{I18n.t('telegram_bot.channels.list.title', count: subscriptions.count)}\n\n"
text += "#{I18n.t('telegram_bot.channels.list.total', count: subscriptions.count)}\n\n"

subscriptions.each do |subscription|
Expand Down
2 changes: 1 addition & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ ru:
confirm_remove: "Удалить %{channel} из подписок?"
remove_success: "Канал %{channel} удалён из подписок"

list:
admin_list:
title: "📊 Список каналов в системе (всего: %{count})"
admin_only: "🚫 У вас нет прав для выполнения этой команды. Доступно только администраторам."
empty: "📭 В системе пока нет каналов."
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/telegram/admin_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def create_test_subscriptions

message_content = extract_message_content(@bot.requests)
assert_not_nil message_content
assert_includes message_content[:text], I18n.t('telegram_bot.channels.list.admin_only')
assert_includes message_content[:text], I18n.t('telegram_bot.channels.admin_list.admin_only')
end

test 'channels list shows message with available channels' do
Expand Down
Loading