diff --git a/data/config.py b/data/config.py
index bf54a843..0d67c08a 100644
--- a/data/config.py
+++ b/data/config.py
@@ -40,6 +40,7 @@ class Miscellaneous:
client_id: str
redirect_url: URL
yoomoney_key: str
+ production: bool
@dataclass(frozen=True)
@@ -98,10 +99,11 @@ def load_config() -> Config:
client_id=env.str("CLIENT_ID"),
redirect_url=env.str("REDIRECT_URI"),
yoomoney_key=env.str("YOOMONEY_KEY"),
+ production=env.bool("PRODUCTION"),
),
)
-# TODO: Переместить в dataclass
+# TODO: Move to dataclass
BASE_DIR = Path(__file__).parent.parent
LOCALES_DIR = BASE_DIR / "locales"
diff --git a/django_project/telegrambot/usersmanage/models/user.py b/django_project/telegrambot/usersmanage/models/user.py
index ee04a540..30edfa64 100644
--- a/django_project/telegrambot/usersmanage/models/user.py
+++ b/django_project/telegrambot/usersmanage/models/user.py
@@ -76,6 +76,8 @@ class Meta:
"self", through="ViewedProfile", symmetrical=False
)
limit_of_views = models.PositiveIntegerField(default=10, null=True)
+ counter_of_report = models.PositiveIntegerField(default=0, null=True)
+ on_check_by_admin = models.BooleanField(default=False, null=True)
def __str__(self):
return f"№{self.id} ({self.telegram_id}) - {self.name}"
diff --git a/functions/dating/reaction_strategies.py b/functions/dating/reaction_strategies.py
index 154f6a16..c982c9a6 100644
--- a/functions/dating/reaction_strategies.py
+++ b/functions/dating/reaction_strategies.py
@@ -194,21 +194,39 @@ async def execute(
self, call: CallbackQuery, state: FSMContext, callback_data: dict[str, str]
):
target_id = int(callback_data["target_id"])
+ target_user = await db_commands.select_user(telegram_id=target_id)
+
+ counter_of_report = target_user.counter_of_report
+ username = call.from_user.username
+ user_id = call.from_user.id
+ report_reason = await get_report_reason(call)
+
text = _(
"Жалоба от пользователя: [@{username}
| {tg_id}
]\n\n"
"На пользователя: [{owner_id}]
\n"
- "Причина жалобы: {reason}
"
+ "Причина жалобы: {reason}
\n"
+ "Количество жалоб на пользователя: {counter_of_report}
"
).format(
- username=call.from_user.username,
- tg_id=call.from_user.id,
+ username=username,
+ tg_id=user_id,
owner_id=target_id,
- reason=await get_report_reason(call),
+ reason=report_reason,
+ counter_of_report=counter_of_report,
)
- await create_questionnaire(
- form_owner=target_id,
- chat_id=load_config().tg_bot.moderate_chat,
- report_system=True,
- add_text=text,
+ await db_commands.update_user_data(
+ telegram_id=target_id, counter_of_report=counter_of_report + 1
)
- await asyncio.sleep(1)
+
+ moderate_chat = load_config().tg_bot.moderate_chat
+ if counter_of_report >= 5 and not target_user.on_check_by_admin:
+ await db_commands.update_user_data(
+ telegram_id=target_id, on_check_by_admin=True
+ )
+ await create_questionnaire(
+ form_owner=target_id,
+ chat_id=moderate_chat,
+ report_system=True,
+ add_text=text,
+ )
+ await asyncio.sleep(0.5)
diff --git a/handlers/users/view_ques.py b/handlers/users/view_ques.py
index 09c6cd0a..8d499d79 100644
--- a/handlers/users/view_ques.py
+++ b/handlers/users/view_ques.py
@@ -2,6 +2,7 @@
from aiogram.types import CallbackQuery
from django.db import IntegrityError
+from data.config import load_config
from functions.dating import (
StartFindingSuccess,
StartFindingFailure,
@@ -50,8 +51,8 @@ async def handle_start_finding(call: CallbackQuery, state: FSMContext) -> None:
@dp.callback_query_handler(
action_report_keyboard.filter(
- action=["adults_only", "drugs", "scam", "another", "cancel_report"]
- )
+ action=["adults_only", "drugs", "scam", "another", "cancel_report"],
+ ),
)
async def handle_report(
call: CallbackQuery, state: FSMContext, callback_data: dict[str, str]
@@ -65,16 +66,18 @@ async def handle_report(
"cancel_report": GoBackToViewing(),
}
strategy = strategy_mapping.get(action)
- await strategy.execute(call, state, callback_data)
- await call.message.answer(text=_("Жалоба успешно отправлена"))
- strategy = GoBackToViewing()
await strategy.execute(call, state, callback_data)
+ if action != "cancel_report":
+ await call.message.answer(text=_("Жалоба успешно отправлена"))
+ strategy = GoBackToViewing()
+ await strategy.execute(call, state, callback_data)
+
@dp.callback_query_handler(
action_keyboard.filter(action=["like", "dislike", "stopped", "report"]),
- state="finding",
+ state="*",
)
async def handle_action(
call: CallbackQuery, state: FSMContext, callback_data: dict[str, str]
@@ -83,13 +86,15 @@ async def handle_action(
profile_id = callback_data["target_id"]
user = await db_commands.select_user_object(telegram_id=call.from_user.id)
viewed_profile = await db_commands.select_user_object(telegram_id=profile_id)
- try:
- await db_commands.add_profile_to_viewed(
- user=user, viewed_profile=viewed_profile
- )
- except IntegrityError:
- logger.error("Дубликаты профилей")
-
+ if load_config().misc.production:
+ try:
+ await db_commands.add_profile_to_viewed(
+ user=user, viewed_profile=viewed_profile
+ )
+ except IntegrityError:
+ logger.error("Дубликаты профилей")
+ else:
+ pass
strategy_mapping = {
"like": LikeAction(),
"dislike": DislikeAction(),