Exemplo n.º 1
0
    def test_username_blank(self):

        profile = User(user_profile=TELEGRAM_INFO)
        assert profile.is_username_blank()

        TELEGRAM_INFO.update(dict(username='******'))
        profile = User(user_profile=TELEGRAM_INFO)
        assert profile.is_username_blank() is False
def start(bot, update, *args, **kwargs):
    user = User(telegram_user=update.effective_user)
    redis.clean_all(user.user_id, 'start')
    if user.is_username_blank():
        update.message.reply_text(conversations.MAIN_PANEL_USERNAME_MISSING)
        return stages.END

    access_pass = auth_helper.auth(user)
    if access_pass['is_admin']:
        pass

    elif access_pass['is_blacklist']:
        update.message.reply_text(conversations.MAIN_PANEL_YELLOWCOW)
        return stages.END

    update.message.reply_text(conversations.MAIN_PANEL_REMINDER)
    time.sleep(0.3)

    tickets = query_helper.search_by_user_id(user.user_id)
    if tickets:
        bot.send_message(
            text=update_helper.tickets_tostr(
                [ticket.to_human_readable() for ticket in tickets],
                conversations.TICKET),
            chat_id=user.user_id,
            reply_markup=update_helper.list_tickets_on_reply_keyboard(tickets))
        return stages.UPDATE_SELECT_TICKET
    bot.send_message(chat_id=user.user_id, text=conversations.NONE_RECORD)
    return stages.SEARCH_SELECT_FIELD
Exemplo n.º 3
0
def start(bot, update, *args, **kwargs):
    user = User(telegram_user=update.effective_user)
    redis.clean_all(user.user_id, 'start')

    if user.is_username_blank():
        update.message.reply_text(conversations.MAIN_PANEL_USERNAME_MISSING)
        return stages.END

    access_pass = auth_helper.auth(user)
    if access_pass['is_admin']:
        pass

    elif access_pass['is_blacklist']:
        update.message.reply_text(conversations.MAIN_PANEL_YELLOWCOW)
        return stages.END

    update.message.reply_text(conversations.MAIN_PANEL_REMINDER)
    time.sleep(0.3)

    query = search_helper.reset_cache(user.user_id)
    bot.send_message(text=conversations.SEARCH_TICKET_START.format_map(
        query.to_human_readable()),
                     chat_id=user.user_id,
                     reply_markup=KEYBOARDS.search_ticket_keyboard_markup)
    return stages.SEARCH_SELECT_FIELD
Exemplo n.º 4
0
def start(bot, update, *args, **kwargs):
    user = User(telegram_user=update.effective_user)

    category = post_helper.get_category_id_from_cache(user.user_id)
    redis.clean_all(user.user_id, 'start')

    if user.is_username_blank():
        update.message.reply_text(conversations.MAIN_PANEL_USERNAME_MISSING)
        return stages.END

    access_pass = auth_helper.auth(user)
    if access_pass['is_admin']:
        pass

    elif access_pass['is_blacklist']:
        update.message.reply_text(conversations.MAIN_PANEL_YELLOWCOW)
        return stages.END

    ticket = post_helper.reset_cache(user.user_id, user.username)
    logger.info(ticket.to_dict())
    update.message.reply_text(conversations.MAIN_PANEL_REMINDER)
    time.sleep(0.3)
    bot.send_message(
        text=conversations.POST_TICKET_START.format_map(ticket.to_human_readable()),
        chat_id=user.user_id,
        reply_markup=KEYBOARDS.post_ticket_keyboard_markup.get(category))
    return stages.POST_SELECT_FIELD
Exemplo n.º 5
0
    def test_convert_telegram_user_to_user(self):
        tg_user = TelegramUser(id=123456789,
                               first_name='test',
                               last_name='pytest',
                               username='******',
                               language_code='ZH',
                               is_bot=False)

        user = User(telegram_user=tg_user)

        assert user.user_id == tg_user.id
        assert user.username == tg_user.username
        assert user.is_username_blank() is False
Exemplo n.º 6
0
def start(bot, update, *args, **kwargs):
    user = User(telegram_user=update.effective_user)
    redis.clean_all(user.user_id, 'start')

    if user.is_username_blank():
        update.message.reply_text(conversations.MAIN_PANEL_USERNAME_MISSING)
        return stages.END

    access_pass = auth_helper.auth(user)
    if access_pass['is_admin']:
        pass

    elif access_pass['is_blacklist']:
        update.message.reply_text(conversations.MAIN_PANEL_YELLOWCOW)
        return stages.END

    update.message.reply_text(conversations.MAIN_PANEL_REMINDER)
    time.sleep(0.3)

    bot.send_message(text=conversations.QUICK_SEARCH_START,
                     chat_id=user.user_id,
                     reply_markup=KEYBOARDS.quick_search_start_keyboard_markup,
                     parse_mode=telegram.ParseMode.MARKDOWN)
    return stages.QUICK_SEARCH_MODE_SELECTION