Добавление работы с конфликтными частями и исправление вайтлиста
This commit is contained in:
@@ -7,7 +7,6 @@ from aiogram.types import Message, CallbackQuery
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from aiogram.exceptions import TelegramBadRequest
|
||||
|
||||
from bot.filters.admin import IsAdmin
|
||||
from configs import settings, COMMANDS
|
||||
from database import get_manager
|
||||
from middleware.loggers import logger
|
||||
@@ -27,7 +26,7 @@ def get_refresh_kb(page: int = 0):
|
||||
return ikb.as_markup()
|
||||
|
||||
|
||||
async def format_banwords_list(page: int = 0) -> str:
|
||||
async def format_banwords_list() -> str:
|
||||
"""
|
||||
Форматирует список всех банвордов с разбивкой по типам.
|
||||
|
||||
@@ -46,13 +45,14 @@ async def format_banwords_list(page: int = 0) -> str:
|
||||
stats = await manager.get_stats()
|
||||
|
||||
# Извлекаем данные из словаря
|
||||
permanent_words = list(data.get('substring', set()))
|
||||
permanent_words = list(data.get('word', set()))
|
||||
permanent_lemmas = list(data.get('lemma', set()))
|
||||
permanent_parts = list(data.get('part', set()))
|
||||
temp_words = list(data.get('temp_substring', set()))
|
||||
temp_words = list(data.get('temp_word', set()))
|
||||
temp_lemmas = list(data.get('temp_lemma', set()))
|
||||
conflict_words = list(data.get('conflict_substring', set()))
|
||||
conflict_words = list(data.get('conflict_word', set()))
|
||||
conflict_lemmas = list(data.get('conflict_lemma', set()))
|
||||
conflict_parts = list(data.get('conflict_part', set()))
|
||||
exceptions = list(data.get('whitelist', set()))
|
||||
|
||||
except Exception as e:
|
||||
@@ -67,7 +67,7 @@ async def format_banwords_list(page: int = 0) -> str:
|
||||
total_count = (
|
||||
len(permanent_words) + len(permanent_lemmas) + len(permanent_parts) +
|
||||
len(temp_words) + len(temp_lemmas) +
|
||||
len(conflict_words) + len(conflict_lemmas)
|
||||
len(conflict_words) + len(conflict_lemmas) + len(conflict_parts)
|
||||
)
|
||||
|
||||
output += f"📊 <b>Общая статистика:</b>\n"
|
||||
@@ -81,21 +81,21 @@ async def format_banwords_list(page: int = 0) -> str:
|
||||
output += "🔴 <b>ПОСТОЯННЫЕ ПРАВИЛА:</b>\n\n"
|
||||
|
||||
if permanent_words:
|
||||
output += f"📝 <b>Подстроки</b> ({len(permanent_words)}):\n"
|
||||
output += f"📝 <b>Слова</b> ({len(permanent_words)}):\n"
|
||||
words_str = ', '.join([f"<code>{w}</code>" for w in sorted(permanent_words)[:20]])
|
||||
if len(permanent_words) > 20:
|
||||
words_str += f" ... <i>(+{len(permanent_words) - 20} ещё)</i>"
|
||||
output += f"{words_str}\n\n"
|
||||
|
||||
if permanent_lemmas:
|
||||
output += f"🔤 <b>Леммы</b> ({len(permanent_lemmas)}):\n"
|
||||
output += f"🔤 <b>Леммы (морф.формы)</b> ({len(permanent_lemmas)}):\n"
|
||||
lemmas_str = ', '.join([f"<code>{w}</code>" for w in sorted(permanent_lemmas)[:20]])
|
||||
if len(permanent_lemmas) > 20:
|
||||
lemmas_str += f" ... <i>(+{len(permanent_lemmas) - 20} ещё)</i>"
|
||||
output += f"{lemmas_str}\n\n"
|
||||
|
||||
if permanent_parts:
|
||||
output += f"🧩 <b>Части</b> ({len(permanent_parts)}):\n"
|
||||
output += f"🧩 <b>Части в сообщении</b> ({len(permanent_parts)}):\n"
|
||||
parts_str = ', '.join([f"<code>{w}</code>" for w in sorted(permanent_parts)[:20]])
|
||||
if len(permanent_parts) > 20:
|
||||
parts_str += f" ... <i>(+{len(permanent_parts) - 20} ещё)</i>"
|
||||
@@ -106,7 +106,7 @@ async def format_banwords_list(page: int = 0) -> str:
|
||||
output += "⏱ <b>ВРЕМЕННЫЕ ПРАВИЛА:</b>\n\n"
|
||||
|
||||
if temp_words:
|
||||
output += f"📝 <b>Временные подстроки</b> ({len(temp_words)}):\n"
|
||||
output += f"📝 <b>Временные слова</b> ({len(temp_words)}):\n"
|
||||
# Для временных слов нужна дополнительная информация о времени истечения
|
||||
# Пока просто выводим список
|
||||
words_str = ', '.join([f"<code>{w}</code>" for w in sorted(temp_words)[:15]])
|
||||
@@ -122,7 +122,7 @@ async def format_banwords_list(page: int = 0) -> str:
|
||||
output += f"{lemmas_str}\n\n"
|
||||
|
||||
# === КОНФЛИКТНЫЕ ПРАВИЛА ===
|
||||
if conflict_words or conflict_lemmas:
|
||||
if conflict_words or conflict_lemmas or conflict_parts:
|
||||
output += "⚔️ <b>КОНФЛИКТНЫЕ ПРАВИЛА:</b>\n"
|
||||
output += "<i>(работают только в режиме <code>/stopconflict</code> <code>время</code>)</i>\n\n"
|
||||
|
||||
@@ -140,10 +140,17 @@ async def format_banwords_list(page: int = 0) -> str:
|
||||
lemmas_str += f" ... <i>(+{len(conflict_lemmas) - 15} ещё)</i>"
|
||||
output += f"{lemmas_str}\n\n"
|
||||
|
||||
if conflict_parts:
|
||||
output += f"🧩 <b>Конфликтные части</b> ({len(conflict_parts)}):\n"
|
||||
parts_str = ', '.join([f"<code>{w}</code>" for w in sorted(conflict_parts)[:15]])
|
||||
if len(conflict_parts) > 15:
|
||||
parts_str += f" ... <i>(+{len(conflict_parts) - 15} ещё)</i>"
|
||||
output += f"{parts_str}\n\n"
|
||||
|
||||
# === ИСКЛЮЧЕНИЯ (WHITELIST) ===
|
||||
if exceptions:
|
||||
output += f"✅ <b>ИСКЛЮЧЕНИЯ</b> ({len(exceptions)}):\n"
|
||||
exc_str = ', '.join([f"<code>{exceptions}</code>" for w in sorted(exceptions)[:15]])
|
||||
exc_str = ', '.join([f"<code>{w}</code>" for w in sorted(exceptions)[:15]])
|
||||
if len(exceptions) > 15:
|
||||
exc_str += f" ... <i>(+{len(exceptions) - 15} ещё)</i>"
|
||||
output += f"{exc_str}\n\n"
|
||||
@@ -183,7 +190,7 @@ async def format_banwords_list(page: int = 0) -> str:
|
||||
|
||||
|
||||
@router.callback_query(F.data.startswith("listwords:refresh"))
|
||||
@router.message(Command(*COMMANDS[CMD], prefix=settings.PREFIX, ignore_case=True), IsAdmin())
|
||||
@router.message(Command(*COMMANDS[CMD], prefix=settings.PREFIX, ignore_case=True))
|
||||
@log_action(action_name="LISTWORDS_COMMAND")
|
||||
async def listwords_cmd(update: Message | CallbackQuery) -> None:
|
||||
"""
|
||||
@@ -209,7 +216,7 @@ async def listwords_cmd(update: Message | CallbackQuery) -> None:
|
||||
|
||||
# Формируем список
|
||||
try:
|
||||
text = await format_banwords_list(page)
|
||||
text = await format_banwords_list()
|
||||
keyboard = get_refresh_kb(page)
|
||||
|
||||
if is_callback:
|
||||
|
||||
Reference in New Issue
Block a user