Beispiel #1
0
def command_auth(update: Update, context: CallbackContext) -> None:
    if not update.message or not update.message.text or " " not in update.message.text:
        update.message.reply_text(
            "☝️ Нужно прислать мне секретный код. "
            "Напиши /auth и код из <a href=\"https://vas3k.club/user/me/edit/bot/\">профиля в Клубе</a> "
            "через пробел. Только не публикуй его в публичных чатах!",
            parse_mode=ParseMode.HTML)
        return None

    secret_code = update.message.text.split(" ", 1)[1].strip()
    user = User.objects.filter(secret_hash=secret_code).first()

    if not user:
        update.message.reply_text("Пользователь с таким кодом не найден")
        return None

    user.telegram_id = update.effective_user.id
    user.telegram_data = {
        "id": update.effective_user.id,
        "username": update.effective_user.username,
        "first_name": update.effective_user.first_name,
        "last_name": update.effective_user.last_name,
        "language_code": update.effective_user.language_code,
    }
    user.save()

    update.message.reply_text(
        f"Отличный код! Приятно познакомиться, {user.slug}")
    update.message.delete()

    # Refresh the cache by deleting and requesting it again
    flush_users_cache()
    cached_telegram_users()

    return None
Beispiel #2
0
    def wrapper(update: Update, context: CallbackContext, *args, **kwargs):
        club_users = cached_telegram_users()

        if str(update.effective_user.id) not in set(club_users):
            update.message.reply_text(
                f"☝️ Привяжи <a href=\"https://vas3k.club/user/me/edit/bot/\">бота</a> к профилю, братишка",
                parse_mode=ParseMode.HTML)
            return None

        return callback(update, context, *args, **kwargs)
Beispiel #3
0
def private_message(update: Update, context: CallbackContext) -> None:
    club_users = cached_telegram_users()
    if str(update.effective_user.id) not in set(club_users):
        update.effective_chat.send_message(
            "Привет! Мы пока не знакомы. Привяжи меня к аккаунту командой /auth с "
            "<a href=\"https://vas3k.club/user/me/edit/bot/\">кодом из профиля</a> через пробел",
            parse_mode=ParseMode.HTML)
    else:
        update.effective_chat.send_message(
            "Йо! Полный список моих команд покажет /help,"
            "а еще мне можно отвечать на посты и уведомления, всё это будет поститься прямо в Клуб!",
            parse_mode=ParseMode.HTML)