Exemple #1
0
async def your_advice(message: types.Message, state: FSMContext):
    chat_id = message.chat.id
    try:
        last_message = (await state.get_data()).get("last_message")
        await bot.edit_message_reply_markup(chat_id, last_message)
    except Exception as e:
        logging.error(f"{e}")
    await state.update_data(advice=message.text)
    last_message = await bot.send_message(chat_id, _("""
Your advice: 

{advice}

Write your advice in the next message.
""").format(advice=message.text),
                                          reply_markup=ListOfButtons(
                                              text=[
                                                  _("Publish"),
                                                  _("Cancel")],
                                              callback=[
                                                  "publish",
                                                  "cancel"]
                                          ).inline_keyboard)

    await state.update_data(last_message=last_message.message_id)
async def g_auth(call: types.CallbackQuery, state: FSMContext):
    chat_id = call.message.chat.id
    try:
        await bot.edit_message_reply_markup(chat_id,
                                            message_id=call.message.message_id)
    except Exception as e:
        logging.error(f"{e}")

    if has_g_auth(chat_id):
        await bot.send_message(
            chat_id,
            _("You have already received the Google Authenticator code"))
        return

    await bot.send_message(
        chat_id,
        _("""
Please ensure you have the app installed.
<a href= "https://itunes.apple.com/gb/app/google-authenticator/id388497605?mt=8">IOS</a>
<a href= "https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en_GB">Android</a>

Press continue when you done. After you receive the code - write it down somewhere.
"""),
        reply_markup=ListOfButtons(text=[_("Continue")],
                                   callback=["continue"]).inline_keyboard)
    await GoogleAuth.ONE.set()
async def g_auth(call: types.CallbackQuery, state: FSMContext):
    chat_id = call.message.chat.id
    try:
        await bot.edit_message_reply_markup(chat_id,
                                            message_id=call.message.message_id)
    except Exception as e:
        logging.error(f"{e}")
    if has_g_auth(chat_id):
        await bot.send_message(
            chat_id,
            _("You have already received the Google Authenticator code"))
        return

    code, link, qr_code = create_google_auth(chat_id)
    await bot.send_message(
        chat_id,
        _("""
You will receive a recovery code and a link below.
<b>IT WILL BE AUTOMATICALLY DELETED AFTER YOU CONFIRM</b>
"""))
    message_1 = (await bot.send_message(chat_id, code)).message_id

    message_2 = (await bot.send_photo(chat_id, qr_code, f"{link}")).message_id
    await bot.send_message(
        chat_id,
        _("Please enter the code from the Google Authenticator\n"
          "Pay attention that it updates every 30 sec."))

    await state.update_data(message_1=message_1, message_2=message_2)
    await GoogleAuth.next()
async def g_auth(call: types.CallbackQuery, state: FSMContext):
    chat_id = call.message.chat.id
    enabled = call.data.split()[1]
    sql.update(table="users", enabled=enabled, condition={"chat_id": chat_id})
    try:
        await bot.edit_message_text(text=_("That is done"),
                                    chat_id=chat_id,
                                    message_id=call.message.message_id)
    except Exception as e:
        logging.error(f"{e}")
Exemple #5
0
async def cancel_or_publish(call: types.CallbackQuery, state: FSMContext):
    chat_id = call.message.chat.id

    try:
        last_message = (await state.get_data()).get("last_message")
        await bot.edit_message_reply_markup(chat_id, last_message)
    except Exception as e:
        logging.error(f"{e}")

    if call.data == "cancel":
        await bot.send_message(chat_id, _("Cancelled"))
        await state.finish()
        return
    elif call.data == "publish":
        advice = (await state.get_data()).get("advice")
        await bot.send_message(config.review_channel, _("""
#Reviews Post:

<b>{}</b>
""").format(advice))