Ejemplo n.º 1
0
async def search_by_gender(message: Message, sex):
    user_id = message.from_user.id
    gender, rating, language = await db.user_data(
        message.from_user.id,
        "gender",
        "rating",
        "language",
    )
    sort = "ASC" if rating >= 0 else "DESC"
    text = texts.female_search if sex == "F" else texts.male_search
    await message.answer(
        f"<i>{text[language][1]}</i>",
        reply_markup=await default.exit_btn(language),
    )
    while True:
        partner = await db.select(
            f'SELECT * FROM main WHERE user_id != "{user_id}" AND (rating <= "{rating}"+10'
            f' AND rating >= "{rating}"-10) AND gender = "{sex}" AND (IsSearching = "Y" '
            f'OR (isSearchingByGender = "Y" AND partner_gender = "{gender}")) ORDER BY rating {sort}',
        )
        if partner is None:
            partner = await db.select(
                f'SELECT * FROM main WHERE user_id != "{user_id}" AND gender = "{sex}" AND (IsSearching = "Y" '
                f'OR (isSearchingByGender = "Y" AND partner_gender = "{gender}")) ORDER BY rating {sort}',
            )
            if partner is None:
                await db.update(
                    f'UPDATE main SET isSearchingByGender = "Y", partner_gender = "{sex}"  WHERE user_id = "{user_id}"',
                )
                return
        try:
            x = ('isChattingByGender = "Y"'
                 if partner[3] == "Y" else 'isChattingByGender = "N"')
            await db.update(
                f'UPDATE main SET isSearching = "N", isSearchingByGender = "N", isChatting = "Y", {x}, partner_id = "{user_id}",'
                f'partner_gender = "{gender}", partner_language = "{language}" WHERE user_id = "{partner[0]}"',
            )
            await db.update(
                'UPDATE main SET isSearching = "N", isSearchingByGender = "N", isChatting = "Y", isChattingByGender = "Y",'
                f'partner_id = "{partner[0]}", partner_gender = "{partner[5]}", partner_language = "{partner[8]}" WHERE user_id = "{user_id}"',
            )
            await bot.send_message(
                partner[0],
                f"<i>{text[partner[8]][0]}</i>",
                reply_markup=ReplyKeyboardRemove(),
            )
            await message.answer(
                f"<i>{text[language][0]}</i>",
                reply_markup=ReplyKeyboardRemove(),
            )

            return
        except:
            await db.update(
                'UPDATE main SET isSearchingByGender = "Y", isChatting = "N", isChattingByGender = "N",'
                f'partner_gender = "{sex}"  WHERE user_id = "{user_id}"', )
            await db.delete_user(partner[0])
Ejemplo n.º 2
0
async def get_price(message: Message):
    if message.text == "💸BTCUSD":
        await message.answer(text=await message_to_send(currency='bitcoin'),
                             reply_markup=ReplyKeyboardRemove())
    elif message.text == "💸ETHUSD":
        await message.answer(text=await message_to_send(currency='ethereum'),
                             reply_markup=ReplyKeyboardRemove())
    elif message.text == "💸XRPUSD":
        await message.answer(text=await message_to_send(currency='xrp'),
                             reply_markup=ReplyKeyboardRemove())
    else:
        await message.answer(text=await
                             message_to_send(currency='binance-coin'),
                             reply_markup=ReplyKeyboardRemove())
Ejemplo n.º 3
0
async def set_access(user: User, data: dict):
    bot_user = User.get(User.user_id == data['user_id'])
    bot_user.access = data['mode']

    keyboard = InlineKeyboardMarkup()
    callback_data = {
        'action': 'set_access',
        'user_id': bot_user.user_id,
        'mode': not bot_user.access
    }
    if bot_user.access:
        btn_text = STRESS['access_granted_btn']
        msg_text = STRESS['access_granted_msg']
    else:
        btn_text = STRESS['access_denied_btn']
        msg_text = STRESS['access_denied_msg']
    keyboard.insert(
        InlineKeyboardButton(text=btn_text,
                             callback_data=json.dumps(callback_data)))
    await bot.edit_message_reply_markup(ACCESS_CONTROL_CHANNEL_ID,
                                        bot_user.access_msg_id,
                                        reply_markup=keyboard)

    if bot_user.access:
        bot_user.state = 'default'
        keyboard = ReplyKeyboardMarkup(resize_keyboard=True,
                                       one_time_keyboard=True)
        keyboard.add(KeyboardButton('Главное меню'))
    else:
        keyboard = ReplyKeyboardRemove()
    bot_user.save()
    await bot.send_message(bot_user.user_id, msg_text, reply_markup=keyboard)
Ejemplo n.º 4
0
async def ban_handler(query: CallbackQuery):
    language = await db.user_data(query.from_user.id, "language")
    _, reason, day, user_id, ids = query.data.split("_")
    days = timedelta(int(day))
    now = datetime.now()
    date = now + days
    x = {"Selling": 0, "Advertising": 1, "CP": 2, "Insult": 3, "Violence": 4}

    if await db.is_chatting(user_id):
        (
            partner_id,
            partner_language,
        ) = await db.user_data(user_id, "partner_id", "partner_language")
        await db.disconnect(user_id, partner_id)
        await bot.send_message(
            partner_id,
            f"<i>{texts.stop_chat[partner_language][1]}</i>",
            reply_markup=await default.start_btn(partner_language),
        )
        await bot.send_message(
            user_id,
            f"<i>{texts.stop_chat[language][1]}</i>",
            reply_markup=ReplyKeyboardRemove(),
        )

    if not await db.is_banned(user_id):
        await db.ban_user(user_id, reason, date)
    await query.message.edit_text(
        f"[banned](tg://user?id={user_id})_ for {day} days, reason: {texts.reasons[language][x[reason]]}._",
        parse_mode="Markdown",
    )
    for id in ids.split("-")[:-1]:
        await bot.delete_message(BD_ANON_ID, int(id))
    await bot.send_message(
        user_id,
        f"<i>{texts.user_banned[language]}</i>".format(
            texts.reasons[language][x[reason]],
            str(date)[:16],
        ),
    )
Ejemplo n.º 5
0
def remove_btn():
    return ReplyKeyboardRemove()
Ejemplo n.º 6
0
async def add_location(msg: types.Message, state: FSMContext):
    loc = [msg.location.latitude, msg.location.longitude]
    await state.update_data(location=loc)
    await msg.answer('Круто, теперь шли фотку!',
                     reply_markup=ReplyKeyboardRemove())
    await Form.Photo.set()
Ejemplo n.º 7
0
async def take_city_a(message: Message):
    await message.reply(
        "Введите название города, из которого Вы хотите перевезти посылку",
        reply_markup=ReplyKeyboardRemove())
    await States.Take_City_A.set()
Ejemplo n.º 8
0
async def send_city_a(message: Message):
    await message.reply(
        "Введите название города, из которого Вы хотите отправить посылку",
        reply_markup=ReplyKeyboardRemove())
    await States.Send_City_A.set()