refactor: clean up unused code and duplicate handlers
- Removed duplicate admin callback handlers from main.py (moved to admin_panel.py) - Removed unused methods from BotController (handle_admin_panel, handle_lottery_management, handle_conduct_lottery_admin, handle_conduct_lottery) - Removed unused keyboard methods from ui.py (get_lottery_management_keyboard, get_lottery_keyboard, get_conduct_lottery_keyboard) - Simplified IBotController interface to only essential methods - Simplified IKeyboardBuilder interface to only used methods - Fixed cmd_admin handler to directly show admin panel - Bot now uses centralized admin handlers from admin_panel.py
This commit is contained in:
@@ -59,67 +59,6 @@ class BotController(IBotController):
|
||||
reply_markup=keyboard
|
||||
)
|
||||
|
||||
async def handle_admin_panel(self, callback: CallbackQuery):
|
||||
"""Обработать админ панель"""
|
||||
if not self.is_admin(callback.from_user.id):
|
||||
await callback.answer("❌ Недостаточно прав", show_alert=True)
|
||||
return
|
||||
|
||||
text = "⚙️ **Панель администратора**\n\n"
|
||||
text += "Выберите раздел для управления:"
|
||||
|
||||
keyboard = self.keyboard_builder.get_admin_keyboard()
|
||||
|
||||
await callback.message.edit_text(
|
||||
text,
|
||||
reply_markup=keyboard,
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
|
||||
async def handle_lottery_management(self, callback: CallbackQuery):
|
||||
"""Обработать управление розыгрышами"""
|
||||
if not self.is_admin(callback.from_user.id):
|
||||
await callback.answer("❌ Недостаточно прав", show_alert=True)
|
||||
return
|
||||
|
||||
text = "🎯 **Управление розыгрышами**\n\n"
|
||||
text += "Выберите действие:"
|
||||
|
||||
keyboard = self.keyboard_builder.get_lottery_management_keyboard()
|
||||
|
||||
await callback.message.edit_text(
|
||||
text,
|
||||
reply_markup=keyboard,
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
|
||||
async def handle_conduct_lottery_admin(self, callback: CallbackQuery):
|
||||
"""Обработать выбор розыгрыша для проведения"""
|
||||
if not self.is_admin(callback.from_user.id):
|
||||
await callback.answer("❌ Недостаточно прав", show_alert=True)
|
||||
return
|
||||
|
||||
# Получаем активные розыгрыши
|
||||
lotteries = await self.lottery_service.get_active_lotteries()
|
||||
|
||||
if not lotteries:
|
||||
await callback.answer("❌ Нет активных розыгрышей", show_alert=True)
|
||||
return
|
||||
|
||||
text = "🎯 **Выберите розыгрыш для проведения:**\n\n"
|
||||
|
||||
for lottery in lotteries:
|
||||
participants_count = await self.participation_repo.get_count_by_lottery(lottery.id)
|
||||
text += f"🎲 {lottery.title} ({participants_count} участников)\n"
|
||||
|
||||
keyboard = self.keyboard_builder.get_conduct_lottery_keyboard(lotteries)
|
||||
|
||||
await callback.message.edit_text(
|
||||
text,
|
||||
reply_markup=keyboard,
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
|
||||
async def handle_active_lotteries(self, callback: CallbackQuery):
|
||||
"""Показать активные розыгрыши"""
|
||||
lotteries = await self.lottery_repo.get_active()
|
||||
@@ -152,40 +91,4 @@ class BotController(IBotController):
|
||||
text,
|
||||
reply_markup=keyboard,
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
|
||||
async def handle_conduct_lottery(self, callback: CallbackQuery):
|
||||
"""Провести конкретный розыгрыш"""
|
||||
if not self.is_admin(callback.from_user.id):
|
||||
await callback.answer("❌ Недостаточно прав", show_alert=True)
|
||||
return
|
||||
|
||||
try:
|
||||
lottery_id = int(callback.data.split("_")[1])
|
||||
except (ValueError, IndexError):
|
||||
await callback.answer("❌ Неверный формат данных", show_alert=True)
|
||||
return
|
||||
|
||||
# Проводим розыгрыш
|
||||
results = await self.lottery_service.conduct_draw(lottery_id)
|
||||
|
||||
if not results:
|
||||
await callback.answer("❌ Не удалось провести розыгрыш", show_alert=True)
|
||||
return
|
||||
|
||||
# Форматируем результаты
|
||||
text = "🎉 **Розыгрыш завершен!**\n\n"
|
||||
|
||||
winners = [result['winner'] for result in results.values()]
|
||||
winners_text = self.message_formatter.format_winners_list(winners)
|
||||
text += winners_text
|
||||
|
||||
keyboard = self.keyboard_builder.get_admin_keyboard()
|
||||
|
||||
await callback.message.edit_text(
|
||||
text,
|
||||
reply_markup=keyboard,
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
|
||||
await callback.answer("✅ Розыгрыш успешно проведен!", show_alert=True)
|
||||
)
|
||||
Reference in New Issue
Block a user