Skip to content

Commit

Permalink
🐛 bug fix in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRomanovizc committed Jul 5, 2024
1 parent 9b7674b commit a023d96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
15 changes: 13 additions & 2 deletions functions/dating/create_forms_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Optional,
)

from aiogram.dispatcher import FSMContext
from aiogram.types import (
CallbackQuery,
)
Expand Down Expand Up @@ -49,9 +50,19 @@ async def create_questionnaire_reciprocity(
await send_questionnaire(chat_id=chat_id, add_text=add_text, owner_id=liker)


async def monitoring_questionnaire(call: CallbackQuery) -> None:
async def monitoring_questionnaire(call: CallbackQuery, state: FSMContext) -> None:
telegram_id = call.from_user.id
user_list = await get_next_user(telegram_id, monitoring=True)
storage = await state.get_data()
user_offsets = storage.get("user_offsets", dict())
user_limits = storage.get("user_limits", dict())
offset = user_offsets.get(telegram_id, 0)
limit = user_limits.get(telegram_id, 10000)
user_list = await get_next_user(telegram_id, monitoring=True, offset=offset, limit=limit)

if user_list:
user_offsets[telegram_id] = offset + len(user_list)
user_limits[telegram_id] = limit + 100
await state.update_data(user_offsets=user_offsets)
random_user = random.choice(user_list)
await bot.edit_message_reply_markup(
chat_id=call.from_user.id, message_id=call.message.message_id
Expand Down
13 changes: 7 additions & 6 deletions handlers/admins/monitoring.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from aiogram import (
types,
)
from aiogram.dispatcher import FSMContext

from filters.IsAdminFilter import (
IsAdmin,
Expand Down Expand Up @@ -32,22 +33,22 @@ async def admin_monitoring(message: types.Message) -> None:


@dp.callback_query_handler(text="confirm_send_monitoring")
async def confirm_send_monitoring(call: types.CallbackQuery) -> None:
async def confirm_send_monitoring(call: types.CallbackQuery, state: FSMContext) -> None:
try:
await monitoring_questionnaire(call)
await monitoring_questionnaire(call, state)
except IndexError:
pass


# FIXME: мониторинг: IndexError
@dp.callback_query_handler(action_keyboard_monitoring.filter(action="ban"))
async def ban_form_owner(call: types.CallbackQuery) -> None:
async def ban_form_owner(call: types.CallbackQuery, state: FSMContext) -> None:
target_id = call.data.split(":")[2]
await db_commands.update_user_data(telegram_id=target_id, is_banned=True)
await call.answer(_("Анкета пользователя была заблокирована"))
await monitoring_questionnaire(call)
await monitoring_questionnaire(call, state)


@dp.callback_query_handler(action_keyboard_monitoring.filter(action="next"))
async def next_form_owner(call: types.CallbackQuery) -> None:
await monitoring_questionnaire(call)
async def next_form_owner(call: types.CallbackQuery, state: FSMContext) -> None:
await monitoring_questionnaire(call, state)

0 comments on commit a023d96

Please sign in to comment.