Esempio n. 1
0
async def set_google_auth(message: types.Message):
    increase_message_counter()
    chat_id = message.chat.id
    text = _(
        "https://telegra.ph/Passcypher-Google-Authenticator-06-02") + "\n\n"
    if has_g_auth(chat_id):
        if enabled_g_auth(chat_id):
            await bot.send_message(
                chat_id,
                text +
                _("Here you can enable and disable your Google Authenticator settings"
                  ),
                reply_markup=ListOfButtons(text=[_("Turn off")],
                                           callback=["turn 0"
                                                     ]).inline_keyboard)
        else:

            await bot.send_message(
                chat_id,
                text +
                _("Here you can enable and disable your Google Authenticator settings"
                  ),
                reply_markup=ListOfButtons(text=[_("Turn on")],
                                           callback=["turn 1"
                                                     ]).inline_keyboard)
    else:
        await bot.send_message(
            chat_id,
            _("Google Authenticator is not set for you. Press /g_auth_info"))
Esempio n. 2
0
async def change_language(call: types.CallbackQuery, state: FSMContext):
    chat_id = call.message.chat.id
    try:
        await bot.edit_message_reply_markup(chat_id,
                                            call.message.message_id,
                                            reply_markup=None)
    except MessageNotModified:
        pass
    language = call.data.split()[1]
    set_language(chat_id, language)
    menu = ListOfButtons(text=[
        _("🔒 Encode", locale=language),
        _("🔑 Decode", locale=language),
        _("ℹ️How to use", locale=language),
        _("🇬🇧 Set language", locale=language),
        _("🔐 Two step verification", locale=language),
        _("📝 Write a review", locale=language)
    ],
                         align=[2, 2, 2]).reply_keyboard

    await bot.send_message(chat_id,
                           _("""Language has changed to 🇬🇧<b>EN</b>

<b>{users}</b> users are using this bot. 

<b>{passwords}</b> passwords encrypted.
<b>{messages}</b> messages received.

Start using this bot: /info""",
                             locale=language).format(**get_counters()),
                           reply_markup=menu)
Esempio n. 3
0
async def starting(message: types.Message, state: FSMContext):
    increase_message_counter()
    await state.reset_state()
    chat_id = message.chat.id
    check_if_new_user(chat_id)

    menu = ListOfButtons(text=[
        _("🔒 Encode"),
        _("🔑 Decode"),
        _("ℹ️How to use"),
        _("🇬🇧 Set language"),
        _("🔐 Two step verification"),
        _("📝 Write a review")
    ],
                         align=[2, 2, 2]).reply_keyboard

    await bot.send_message(chat_id,
                           _("""
Hello, <b>{}</b>
This bot is designed to encrypt your passwords so you can store them publicly, for example in your \
<code>Telegram saved messages.</code>

You can choose your language using command /set_language
""").format(message.from_user.first_name),
                           reply_markup=menu)
Esempio n. 4
0
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()
Esempio n. 5
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)
Esempio n. 6
0
async def language_set(message: types.Message):
    increase_message_counter()

    chat_id = message.chat.id
    await bot.send_message(
        chat_id,
        _("""
Hello, <b>{}</b>
Let's choose your language
""").format(message.from_user.first_name),
        reply_markup=ListOfButtons(
            text=["English", "Русский", "Українська"],
            callback=["language en", "language ru",
                      "language uk"]).inline_keyboard)
Esempio n. 7
0
async def unknown(message: types.Message, state: FSMContext):
    increase_message_counter()

    text = (_("🔒 Encode") + f" '{message.text}'")[:20] + "..."

    await message.reply(_("""
Looks like the input is invalid...
To decode your password - forward the message with encoded password you received from bot.
<a href= 'https://telegra.ph/file/a9f99684284a92eb2a6a0.png'>ᅠ</a>
Perhaps you wanted to encrypt this message? Click """) + _("🔒 Encode") +
                        _("\n\nOr setup the language again /set_language"),
                        reply_markup=ListOfButtons(
                            text=[text],
                            callback=[f"encrypt_saved"]).inline_keyboard)
Esempio n. 8
0
async def reviews_button(message: types.Message):
    increase_message_counter()

    chat_id = message.chat.id
    await bot.send_message(chat_id, _("""Please, it is important for me to receive a response and advice from you.
How would you change the bot? Any comments are appreciated. 

Your comment will be posted <b>anonymously</b> in our channel @pcypher
Or you can just rate the bot using this link: https://t.me/pcypher/16
"""),
                           reply_markup=ListOfButtons(
                               text=[_("Give an advice to the bot")],
                               callback=["give_advice"]
                           ).inline_keyboard)
Esempio n. 9
0
async def info(message: types.Message):
    increase_message_counter()
    chat_id = message.chat.id
    if has_g_auth(chat_id):
        text = _(
            "Here you can enable and disable your Google Authenticator settings"
        )
        if enabled_g_auth(chat_id):
            await bot.send_message(chat_id,
                                   text,
                                   reply_markup=ListOfButtons(
                                       text=[_("Turn off")],
                                       callback=["turn 0"]).inline_keyboard)
        else:

            await bot.send_message(chat_id,
                                   text,
                                   reply_markup=ListOfButtons(
                                       text=[_("Turn on")],
                                       callback=["turn 1"]).inline_keyboard)
    else:
        await bot.send_message(
            chat_id,
            _("Google Authenticator is not set for you. Press /g_auth_info"))
Esempio n. 10
0
async def info(message: types.Message):
    increase_message_counter()
    chat_id = message.chat.id
    text = _(
        "To encrypt your phrase/file you need to enter a master password each time you want to encrypt or decrypt, or"
        " you can enable <b>Google Authenticator</b> and enter one-time codes from your phone <b>only to decrypt</b>"
        "  your passwords. \n"
        "(Master password will be kept in database then) \n\n"
        "Please make your choice (you can change it later with command /reset_google_auth\n"
    )
    await bot.send_message(
        chat_id,
        text,
        reply_markup=ListOfButtons(text=[_("Setup")],
                                   callback=["g_auth_setup"]).inline_keyboard)
Esempio n. 11
0
async def give_advice(call: types.CallbackQuery, state: FSMContext):
    chat_id = call.message.chat.id
    await Other.REVIEW.set()
    await bot.edit_message_reply_markup(chat_id, call.message.message_id)
    last_message = await bot.send_message(chat_id, _("""
Your advice: 

{advice}

Write your advice in the next message.
""").format(advice=" "),
                                          reply_markup=ListOfButtons(
                                              text=[_("Cancel")],
                                              callback=["cancel"]
                                          ).inline_keyboard)
    await state.update_data(last_message=last_message.message_id)
Esempio n. 12
0
async def lang_choose(message: types.Message):
    chat_id = message.chat.id

    increase_message_counter()
    try:
        await bot.send_message(
            chat_id,
            _("""
Hello, <b>{}</b>
Firstly, let's choose your language
""").format(message.from_user.first_name),
            reply_markup=ListOfButtons(
                text=["English", "Русский", "Українська"],
                callback=["language en", "language ru",
                          "language uk"]).inline_keyboard)
    except CantParseEntities as err:
        print(f"Error. CantParseEntities: {err}")
Esempio n. 13
0
async def encoded(message: types.Message, state: FSMContext):
    increase_message_counter()
    chat_id = message.chat.id
    if "/g_auth_info" == message.text:
        text = _(
            "To encrypt your phrase/file you need to enter a master password each time you want to encrypt or decrypt, or"
            " you can enable <b>Google Authenticator</b> and enter one-time codes from your phone <b>only to decrypt</b>"
            "  your passwords. \n"
            "(Master password will be kept in database then) \n\n"
            "Please make your choice (you can change it later with command /reset_google_auth\n"
        )
        await bot.send_message(chat_id,
                               text,
                               reply_markup=ListOfButtons(
                                   text=[_("Setup")],
                                   callback=["g_auth_setup"]).inline_keyboard)
        await state.finish()
        return
    async with state.proxy() as data:
        data["master_pass"] = message.text

        password = data.get("to_encrypt")
        master_pass = data.get("master_pass")

    if not data.get("encrypt_from_saved"):
        await Encode.PASSWORD.set()
        await bot.send_message(
            chat_id,
            _("""Enter phrase you want to encrypt.
It should be under 400 characters, for best results there should be only characters from this list:
<pre>{allowed_chars} </pre>
<b> THE BOT DELETES YOUR MESSAGES WITH PASSWORDS AFTER 10 SECONDS</b>
""").format(allowed_chars=allowed_chars))
    else:
        if not password:
            await message.reply(_("Password not found."))
            await state.finish()
            return
        if len(password) > 400:
            await bot.send_message(
                chat_id,
                _("Error has occurred... Too long phrase. Try to enter a phrase under 400 \
characters."))
            await state.finish()
            return
        elif not master_pass:
            await message.reply(_("Master Password not found."))
            await state.finish()
            return

        text, code = encode(password.replace("\n", "\\n"), master_pass)
        if master_pass == get_google_auth(chat_id):
            hint = "Google Authenticator"
        else:
            hint = master_pass[:2] + "***********"
        await bot.send_message(
            chat_id,
            _("""<code>----------------------------
ENCRYPTION STARTS HERE
----------------------------
{passw}
----------------------------
ENCRYPTION ENDS HERE
----------------------------
CODE
{code}
----------------------------
</code>

Hint: {hint}
Save this message wherever you want and forward it to the bot should you need to decode it.
""").format(passw=text, code=code, hint=f"{hint}"))
        await state.finish()
        increase_message_counter(password=True)

    await asyncio.sleep(10)
    await message.delete()