Ejemplo n.º 1
0
def read_trans(bot, update):
    trans = update.callback_query.data
    chat_id = update.callback_query.message.chat_id
    ad_id = get_ad_id(chat_id, conn)
    trans = int(trans)
    update_field(ad_id, 'transmission', trans, conn)
    return start(bot, update)
Ejemplo n.º 2
0
def enter_release_year(bot, update):
    release_year = update.message.text
    chat_id = update.message.chat_id
    ad_id = get_ad_id(chat_id, conn)
    release_year = int(release_year)
    update_field(ad_id, 'release_year', release_year, conn)
    return start(bot, update)
Ejemplo n.º 3
0
def read_ad_title(bot, update):
    chat_id = update.message.chat_id
    title = update.message.text
    member_id = update.message.chat_id
    insert_ad(member_id, title, conn)
    ad_id = get_ad_id(chat_id, conn)
    update_state(member_id, ad_id, conn)
    return start(bot, update)
Ejemplo n.º 4
0
def enter_model(bot, update):
    model = update.message.text
    chat_id = update.message.chat_id
    ad_id = get_ad_id(chat_id, conn)
    model = str(model)
    print(model)
    update_field(ad_id, 'model', model, conn)
    return start(bot, update)
Ejemplo n.º 5
0
def enter_mileage(bot, update):
    mileage = update.message.text
    chat_id = update.message.chat_id
    ad_id = get_ad_id(chat_id, conn)
    mileage = int(mileage)
    print(mileage)
    update_field(ad_id, 'mileage', mileage, conn)
    return start(bot, update)
Ejemplo n.º 6
0
def enter_brand(bot, update):
    brand = update.message.text
    chat_id = update.message.chat_id
    ad_id = get_ad_id(chat_id, conn)
    brand = str(brand)
    print(brand)
    update_field(ad_id, 'brand', brand, conn)
    return start(bot, update)
Ejemplo n.º 7
0
def enter_price(bot, update):
    price = update.message.text
    chat_id = update.message.chat_id
    ad_id = get_ad_id(chat_id, conn)
    price = int(price)
    print(price)
    update_field(ad_id, 'price', price, conn)
    return start(bot, update)
Ejemplo n.º 8
0
def start(bot, update):
    global conn
    conn = create_connection()
    try:
        member_id = update.message.chat_id
    except AttributeError:
        member_id = update.callback_query.message.chat_id
    if is_new_member(conn, member_id):
        add_new_member(conn, member_id)
        keyboard = [
            [InlineKeyboardButton(u"افزودن آگهی", callback_data='1')],
            [InlineKeyboardButton(u"انصراف", callback_data='2')],
            [InlineKeyboardButton(u"جستوجوی آگهی", callback_data='3')],
        ]
        reply_markup = InlineKeyboardMarkup(keyboard)
        update.message.reply_text(u"گزینه مورد نظر را انتخاب کنید",
                                  reply_markup=reply_markup)
        return PROCESS_OPTION
    else:
        member_state = fetch_state(member_id, conn)
        if member_state == 0:
            keyboard = [
                [InlineKeyboardButton(u"افزودن آگهی", callback_data='1')],
                [InlineKeyboardButton(u"انصراف", callback_data='2')],
                [InlineKeyboardButton(u"جستوجوی آگهی", callback_data='3')],
            ]
            reply_markup = InlineKeyboardMarkup(keyboard)
            update.message.reply_text(u"گزینه مورد نظر را انتخاب کنید",
                                      reply_markup=reply_markup)
            return PROCESS_OPTION
        elif member_state == 1:
            update.message.reply_text(u'عنوان آگهی خود را وارد کنید')
            return READ_AD_TITLE
        else:
            ad_id = get_ad_id(member_id, conn)
            null_values = list_null_fields(ad_id, conn)
            if len(null_values) == 0:
                return cancel_state(bot, update)
            button_list = [KeyboardButton(s) for s in null_values]
            reply_markup = ReplyKeyboardMarkup(
                build_menu(button_list, n_cols=2))
            bot.send_message(chat_id=member_id,
                             text=u"کدام اطلاعات را وارد میکنید؟",
                             reply_markup=reply_markup)
            return PROCESS_NULLS
Ejemplo n.º 9
0
def cancel_state(bot, update):
    if update.callback_query:
        query = update.callback_query
    else:
        query = update
    chat_id = query.message.chat_id

    #He must start from the scratch
    ad_id = get_ad_id(chat_id, conn)
    if ad_id is None:
        update_state(chat_id, 0, conn)
    else:
        nulls = list_null_fields(ad_id, conn)
        if len(nulls) == 0:
            update_state(chat_id, 0, conn)
            update.message.reply_text(u'آگهی شما با موفقیت افزوده شد')
        else:
            update_state(chat_id, ad_id, conn)
    user = query.message.from_user
    logger.info(u"User %s canceled the conversation.", user.first_name)
    query.message.reply_text(u'باز هم به ما سر بزن!',
                             reply_markup=ReplyKeyboardRemove())
    conn.close()
    return ConversationHandler.END