Skip to content

Commit

Permalink
⚡️ Directly addressing model object
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRomanovizc committed Aug 27, 2023
1 parent d4bb1db commit 9d80bc1
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 152 deletions.
60 changes: 30 additions & 30 deletions functions/dating/send_form_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,54 @@ async def send_questionnaire(
) -> None:
user = await db_commands.select_user(owner_id)
text_template = _("{}, {} лет, {} {verification}\n\n")
user_verification = "✅" if user["verification"] else ""
user_verification = "✅" if user.verification else ""

text_without_inst = _(text_template + "{commentary}").format(
user.get("varname"),
user.get("age"),
user.get("city"),
commentary=user.get("commentary"),
user.varname,
user.age,
user.city,
commentary=user.commentary,
verification=user_verification,
)

text_with_inst_template = text_template + _(
"<b>Инстаграм</b> - <code>{instagram}</code>\n"
)
text_with_inst = _(text_with_inst_template).format(
user.get("varname"),
user.get("age"),
user.get("city"),
user.get("commentary"),
user.varname,
user.age,
user.city,
user.commentary,
verification=user_verification,
instagram=user.get("instagram"),
instagram=user.instagram,
)

caption_with_add_text = _("{}\n\n" + text_template + "{}").format(
add_text,
user.get("varname"),
user.get("age"),
user.get("city"),
user.get("commentary"),
user.varname,
user.age,
user.city,
user.commentary,
verification=user_verification,
)

add_text_with_inst = _(
"{}\n\n" + text_template + "<b>Инстаграм</b> - <code>{instagram}</code>\n"
).format(
add_text,
user.get("varname"),
user.get("age"),
user.get("city"),
user.get("commentary"),
user.varname,
user.age,
user.city,
user.commentary,
verification=user_verification,
instagram=user.get("instagram"),
instagram=user.instagram,
)
try:
if add_text is None and user.get("instagram") is None:
if add_text is None and user.instagram is None:
await bot.send_photo(
chat_id=chat_id,
caption=text_without_inst,
photo=user.get("photo_id"),
photo=user.photo_id,
reply_markup=await questionnaires_keyboard(
target_id=owner_id, monitoring=monitoring
),
Expand All @@ -79,43 +79,43 @@ async def send_questionnaire(
await bot.send_photo(
chat_id=chat_id,
caption=text_with_inst,
photo=user.get("photo_id"),
photo=user.photo_id,
reply_markup=await questionnaires_keyboard(
target_id=owner_id, monitoring=monitoring
),
)
elif markup is None and user.get("instagram") is None:
elif markup is None and user.instagram is None:
await bot.send_photo(
chat_id=chat_id,
caption=caption_with_add_text,
photo=user.get("photo_id"),
photo=user.photo_id,
)
elif markup is None:
await bot.send_photo(
chat_id=chat_id, caption=add_text_with_inst, photo=user.get("photo_id")
chat_id=chat_id, caption=add_text_with_inst, photo=user.photo_id
)

elif user.get("instagram") is None:
elif user.instagram is None:
await bot.send_photo(
chat_id=chat_id,
caption=caption_with_add_text,
photo=user.get("photo_id"),
photo=user.photo_id,
reply_markup=await reciprocity_keyboard(user_for_like=owner_id),
)
elif report_system:
await bot.send_photo(
chat_id=chat_id,
caption=add_text,
photo=user.get("photo_id"),
photo=user.photo_id,
reply_markup=await user_blocking_keyboard(
user_id=owner_id, is_banned=user["is_banned"]
user_id=owner_id, is_banned=user.is_banned
),
)
else:
await bot.send_photo(
chat_id=chat_id,
caption=add_text_with_inst,
photo=user.get("photo_id"),
photo=user.photo_id,
reply_markup=await reciprocity_keyboard(user_for_like=owner_id),
)
except BadRequest as err:
Expand Down
16 changes: 8 additions & 8 deletions functions/event/extra_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def add_events_to_user(call: CallbackQuery, event_id: int) -> None:
Функция, сохраняющая id мероприятий, которые лайкнул пользователь
"""
user = await db_commands.select_user(telegram_id=call.from_user.id)
event_list = user.get("events", [])
event_list = user.events

if str(event_id) not in event_list:
await db_commands.update_user_events(
Expand All @@ -34,7 +34,7 @@ async def check_event_date(telegram_id: int) -> None:
Функция, которая проверяет - прошло мероприятие или нет
"""
event = await db_commands.select_user_meetings(telegram_id)
event_time = event.get("time_event")
event_time = event.time_event
if event_time is None:
return
event_datetime, now_datetime = (
Expand Down Expand Up @@ -66,11 +66,11 @@ async def create_form(
try:
owner = await db_commands.select_user_meetings(telegram_id=form_owner)
document = {
"title": owner.get("event_name"),
"date": owner.get("time_event"),
"place": owner.get("venue"),
"description": owner.get("commentary"),
"photo_id": owner.get("photo_id"),
"title": owner.event_name,
"date": owner.time_event,
"place": owner.venue,
"description": owner.commentary,
"photo_id": owner.photo_id,
"telegram_id": form_owner,
}
if view:
Expand Down Expand Up @@ -113,5 +113,5 @@ async def get_next_random_event_id(telegram_id: int) -> Optional[int]:

async def get_next_registration(telegram_id: int) -> List[int]:
user = await db_commands.select_user(telegram_id=telegram_id)
events: list = user.get("events")
events: list = user.events
return events
4 changes: 2 additions & 2 deletions functions/main_app/app_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
async def send_message_week(message: Message) -> None:
user = await db_commands.select_user(telegram_id=message.from_user.id)

user_gender = "Парней" if user.get("need_partner_sex") == "Мужской" else "Девушек"
user_gender = "Парней" if user.need_partner_sex == "Мужской" else "Девушек"
text = _(
"Несколько {} из города {} хотят познакомиться с тобой прямо сейчас"
).format(user_gender, user.get("need_city"))
).format(user_gender, user.need_city)

await bot.send_message(
chat_id=message.chat.id, text=text, reply_markup=await viewing_ques_keyboard()
Expand Down
44 changes: 20 additions & 24 deletions functions/main_app/auxiliary_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from keyboards.inline.settings_menu import information_keyboard
from loader import _, bot, scheduler
from utils.db_api import db_commands
from utils.db_api.db_commands import check_user_exists, check_user_meetings_exists
from utils.db_api.db_commands import check_user_meetings_exists


async def delete_message(message: Message) -> None:
Expand Down Expand Up @@ -66,25 +66,25 @@ async def display_profile(call: CallbackQuery, markup: InlineKeyboardMarkup) ->
count_referrals = await db_commands.count_all_users_kwarg(
referrer_id=call.from_user.id
)
user_verification = "✅" if user["verification"] else ""
user_verification = "✅" if user.verification else ""

user_info_template = _(
"{name}, {age} лет, {city}, {verification}\n\n{commentary}\n\n"
"<u>Партнерка:</u>\nКоличество приглашенных друзей: {reff}\nРеферальная ссылка:\n {link}"
)
info = await bot.get_me()
user_info = user_info_template.format(
name=user["varname"],
age=user["age"],
city=user["city"],
name=user.varname,
age=user.age,
city=user.city,
verification=user_verification,
commentary=user["commentary"],
commentary=user.commentary,
reff=count_referrals,
link=f"https://t.me/{info.username}?start={call.from_user.id}",
)

await call.message.answer_photo(
caption=user_info, photo=user["photo_id"], reply_markup=markup
caption=user_info, photo=user.photo_id, reply_markup=markup
)


Expand All @@ -99,10 +99,10 @@ async def show_dating_filters(obj: Union[CallbackQuery, Message]) -> None:
"🔞 Возрастной диапазон: {}-{} лет\n\n"
"🏙️ Город партнера: {}"
).format(
user.get("need_partner_sex"),
user.get("need_partner_age_min"),
user.get("need_partner_age_max"),
user.get("need_city"),
user.need_partner_sex,
user.need_partner_age_min,
user.need_partner_age_max,
user.need_city,
)
try:
await obj.message.edit_text(text, reply_markup=markup)
Expand All @@ -127,7 +127,7 @@ async def registration_menu(
"Если у вас есть предложение о сотрудничестве, пишите агенту поддержки - "
"@{supports}\n\n"
).format(
fullname=obj.from_user.full_name, heart=heart, supports=support["username"]
fullname=obj.from_user.full_name, heart=heart, supports=support.username
)
try:
await obj.message.edit_text(text=text, reply_markup=markup)
Expand All @@ -150,7 +150,7 @@ async def registration_menu(


async def check_user_in_db(telegram_id: int, message: Message, username: str) -> None:
if not await check_user_exists(
if not await db_commands.check_user_exists(
telegram_id
) and not await check_user_meetings_exists(telegram_id):
user = await db_commands.select_user_object(telegram_id=telegram_id)
Expand Down Expand Up @@ -200,13 +200,12 @@ async def finished_registration(
"{}\n\n"
"<b>О себе</b> - {}"
).format(
user.get("varname"), user.get("age"), user.get("city"), user.get("commentary")
user.varname, user.age, user.city, user.commentary
)

await message.answer_photo(
caption=text, photo=user.get("photo_id"), reply_markup=ReplyKeyboardRemove()
caption=text, photo=user.photo_id, reply_markup=markup
)
await message.answer("Меню: ", reply_markup=markup)


async def saving_normal_photo(
Expand All @@ -218,7 +217,7 @@ async def saving_normal_photo(
try:
await db_commands.update_user_data(telegram_id=telegram_id, photo_id=file_id)

await message.answer(text=_("Фото принято!"))
await message.answer(text=_("Фото принято!"), reply_markup=ReplyKeyboardRemove())
except:
await message.answer(
text=_(
Expand Down Expand Up @@ -264,11 +263,8 @@ async def saving_censored_photo(
)
if flag == "change_datas":
await message.answer(
text=_("Фото принято!"), reply_markup=ReplyKeyboardRemove()
)
await asyncio.sleep(3)
await message.answer(
text=_("Выберите, что вы хотите изменить: "), reply_markup=markup
text=_("<u>Фото принято!</u>\n"
"Выберите, что вы хотите изменить: "), reply_markup=markup
)
await state.reset_state()
elif flag == "registration":
Expand Down Expand Up @@ -351,7 +347,7 @@ async def handle_guide_callback(
)


async def information_menu(call: CallbackQuery):
async def information_menu(call: CallbackQuery) -> None:
start_date = datetime.datetime(2021, 8, 10, 14, 0)
now_date = datetime.datetime.now()
delta = now_date - start_date
Expand All @@ -370,7 +366,7 @@ async def information_menu(call: CallbackQuery):
await call.message.answer(text=txt, reply_markup=markup)


async def get_report_reason(call: CallbackQuery):
async def get_report_reason(call: CallbackQuery) -> None:
match = re.search(r"report:(.*?):", call.data)
reason_key = match.group(1)
reason_mapping = {
Expand Down
2 changes: 1 addition & 1 deletion functions/main_app/language_ware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

async def get_lang(user_id) -> Optional[str]:
user = await db_commands.select_user(telegram_id=user_id)
return user.get("language") if user else None
return user.language if user else None


class ACLMiddleware(I18nMiddleware):
Expand Down
12 changes: 6 additions & 6 deletions handlers/admins/customers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ async def search_handler(message: Message, state: FSMContext):

if user:
text = (
f"<b>ℹ️ Пользователь: </b><code>{user['telegram_id']}</code>\n\n"
f"<b>👤 Полное имя: </b><code>{user['varname']}</code>\n"
f"<b>🚹 Юзернейм: </b><code>{user['username']}</code>\n"
f"<b>📅 Дата регистрации в боте: </b><code>{user['created_at'].date()}</code>\n"
f"<b>ℹ️ Пользователь: </b><code>{user.telegram_id}</code>\n\n"
f"<b>👤 Полное имя: </b><code>{user.varname}</code>\n"
f"<b>🚹 Юзернейм: </b><code>{user.username}</code>\n"
f"<b>📅 Дата регистрации в боте: </b><code>{user.created_at.date()}</code>\n"
)

await message.answer_photo(
photo=user["photo_id"],
photo=user.photo_id,
caption=text,
reply_markup=await user_blocking_keyboard(
user_id=user["telegram_id"], is_banned=user["is_banned"]
user_id=user.telegram_id, is_banned=user.is_banned
),
)

Expand Down
2 changes: 1 addition & 1 deletion handlers/admins/settings/tech_works.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def command_start(message: Message, state: FSMContext):
@dp.message_handler(IsAdmin(), text="🛑 Тех.Работа")
async def tech_works_menu(message: Message) -> None:
settings = await db_commands.select_setting(message.from_user.id)
tech_works = settings.get("technical_works")
tech_works = settings.technical_works

await message.answer(
text=_("Чтобы включить/выключить технические работы, нажмите на кнопку ниже"),
Expand Down
3 changes: 2 additions & 1 deletion handlers/groups/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from aiogram.types import Message

from filters.FiltersChat import IsGroup
from filters.IsAdminFilter import IsAdmin
from loader import dp, _


@dp.message_handler(IsGroup(), Command("start"))
@dp.message_handler(IsGroup(), IsAdmin(), Command("start"))
async def start_group_handler(message: Message) -> None:
await message.answer(
text=_(
Expand Down
Loading

0 comments on commit 9d80bc1

Please sign in to comment.