예제 #1
0
파일: new_bot.py 프로젝트: cz303/web
def show_cart(msg):
    info = db().get_user_cart(msg.chat.id)
    try:
        lng = db().get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    items = info[1]
    text = ''
    key = types.ReplyKeyboardMarkup(resize_keyboard=True)
    key.row(types.KeyboardButton(locales[lng][15]),
            types.KeyboardButton(locales[lng][44]))
    if len(items) == 0:
        text = locales[lng][42]
        bot.send_message(msg.chat.id, text)
        catalog(msg)
        return
    text = '{}:\n\n'.format(locales[lng][43])
    keys = []
    goods = []
    for i in items:
        if i not in goods:
            goods.append(i)
            try:
                info1 = db().get_item_by_id(i[1])[0]
            except IndexError:
                continue
            text += '{}\n{} x {} = {}\n\n'.format(info1[1], items.count(i),
                                                  i[2],
                                                  float(i[2]) * items.count(i))
            if '❌ {}'.format(info1[1]) not in keys:
                key.add(types.KeyboardButton('❌ {}'.format(info1[1])))
                keys.append('❌ {}'.format(info1[1]))
    key.row(types.KeyboardButton('🚖 ' + locales[lng][13]))
    text += '{}: {}'.format(locales[lng][22], info[0][0])
    bot.send_message(msg.chat.id, text, reply_markup=key)
예제 #2
0
def keygen(cat_id, uid):
    key = types.InlineKeyboardMarkup()
    cats = db().get_categories(cat_id)
    for c in cats:
        key.add(
            types.InlineKeyboardButton(c[1], callback_data='cat_' + str(c[0])))
    items = db().get_items(cat_id)
    for i in items:
        key.add(
            types.InlineKeyboardButton(i[1], callback_data='it_' + str(i[0])))
    if uid in config.admin_id:
        key.add(
            types.InlineKeyboardButton('[Добавить категорию]',
                                       callback_data='add_cat_' + str(cat_id)),
            types.InlineKeyboardButton('[Добавить товар]',
                                       callback_data='add_it_' + str(cat_id)))
        if int(cat_id) > 0:
            key.add(
                types.InlineKeyboardButton('[Удалить категорию]',
                                           callback_data='del_cat_' +
                                           str(cat_id)))
    if int(cat_id) > 0:
        parent = db().get_parent(cat_id)[0][0]
        key.add(
            types.InlineKeyboardButton('Назад',
                                       callback_data='cat_' + str(parent)))
    return key
예제 #3
0
파일: new_bot.py 프로젝트: cz303/web
def feedback_send(msg):
    db().set_state(msg.from_user.id, '0')
    try:
        lng = db().get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return

    for i in config.admin_id:
        try:
            lng = db().get_user_lang(i)[0][0]
        except IndexError:
            continue
        text = '[{}](tg://user?id={}) {}\n\n{}'.format(
            msg.from_user.first_name, msg.from_user.id, locales[lng][64],
            msg.text)
        key = types.InlineKeyboardMarkup()
        key.add(
            types.InlineKeyboardButton(locales[lng][65],
                                       callback_data='reply_{}'.format(
                                           msg.from_user.id)))
        try:
            bot.send_message(i, text, reply_markup=key, parse_mode='markdown')
        except Exception:
            continue
    bot.send_message(msg.chat.id, locales[lng][66], reply_markup=std_key(msg))
예제 #4
0
def order_finish(call):
    d = db()
    provided = d.what_is_provided(call.from_user.id)
    method = 'картой' if call.data.split('_')[2] == 'card' else 'наличными'
    info = d.get_user_cart(call.from_user.id)
    items = info[1]
    order = ''
    for i in items:
        info1 = db().get_item_by_id(i[1])[0]
        order += '{} {}\n'.format(info1[1], i[2])
    order += '\nИтого: {}'.format(info[0][0])
    text = 'Пользователь [{}](tg://user?id={}) сделал заказ\n\n{}\n\nОплата {}'.format(
        call.from_user.first_name, call.from_user.id, order, method)
    loc = [0, 0]
    if provided == 'addr':
        addr = d.get_addr(call.from_user.id)
        text += '\nАдрес: {}'.format(addr)
    else:
        text += '\nЛокация отправлена следующим сообщением'
        loc = d.get_loc(call.from_user.id)
    bot.edit_message_text('Заказ отправлен', call.message.chat.id,
                          call.message.message_id)
    d.set_state(call.from_user.id, '0')
    for i in config.admin_id:
        try:
            bot.send_message(i, text, parse_mode='markdown')
            if provided == 'loc':
                bot.send_location(i, loc[0], loc[1])
        except Exception:
            continue
예제 #5
0
def set_title(msg):
    global state
    global status
    status[msg.chat.id] = 'desc'
    db().set_title(msg.text, msg.chat.id)
    bot.send_message(
        msg.chat.id,
        'Введите описание   \n\n Для отмены нажмите на на /cancel')
예제 #6
0
파일: new_bot.py 프로젝트: cz303/web
def del_item(call):
    item_id = call.data.split('_')[2]
    try:
        parent = db().get_item_by_id(item_id)[0][4]
    except IndexError:
        return
    db().del_item(item_id)
    catalog1(call.message, parent, edit=False, uid=call.from_user.id)
예제 #7
0
def start(msg):
    db().try_add_user(msg.from_user.id)
    key = types.ReplyKeyboardMarkup(one_time_keyboard=False,
                                    resize_keyboard=True)
    key.add(types.KeyboardButton('Каталог'), types.KeyboardButton('Корзина'))
    bot.send_message(msg.chat.id,
                     'Добро пожаловать в каталог всевозможных товаров',
                     reply_markup=key)
예제 #8
0
파일: new_bot.py 프로젝트: cz303/web
def clear_cart(msg):
    db().clear_cart(msg.from_user.id)
    try:
        lng = db().get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    bot.send_message(msg.chat.id, locales[lng][42])
    catalog(msg)
예제 #9
0
def add_category(msg):
    global state
    global status
    cat_id = status[msg.chat.id].split('_')[2]
    name = msg.text
    db().add_cat(cat_id, name)
    status[msg.chat.id] = '0'
    catalog(msg, cat_id)
예제 #10
0
def add_item_start(call):
    global state
    global status
    status[call.from_user.id] = call.data
    parent = call.data.split('_')[2]
    db().create_item(parent, call.from_user.id)
    bot.send_message(
        call.message.chat.id,
        'Введите название товара   \n\n Для отмены нажмина на /cancel')
예제 #11
0
파일: new_bot.py 프로젝트: cz303/web
def start_lang(msg):
    if msg.text == 'Русский':
        lang = 'ru'
    elif msg.text == 'English':
        lang = 'en'
    else:
        lang = 'uz'
    db().try_add_user(msg.from_user.id, lang)
    catalog(msg)
예제 #12
0
파일: new_bot.py 프로젝트: cz303/web
def feedback_start(msg):
    db().set_state(msg.from_user.id, 'fb_write')
    try:
        lng = db().get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    key = types.ReplyKeyboardMarkup(resize_keyboard=True)
    key.add(types.KeyboardButton('⬅️' + locales[lng][1]))
    bot.send_message(msg.chat.id, locales[lng][63], reply_markup=key)
예제 #13
0
파일: new_bot.py 프로젝트: cz303/web
def cancel_add_cat(msg):
    try:
        lng = db().get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    db().cancel_item(msg.chat.id)
    global status
    status[msg.chat.id] = '0'
    bot.send_message(msg.chat.id, locales[lng][9])
예제 #14
0
파일: new_bot.py 프로젝트: cz303/web
def reply_start(call):
    db().set_state(call.from_user.id, call.data)
    try:
        lng = db().get_user_lang(call.from_user.id)[0][0]
    except IndexError:
        return
    key = types.ReplyKeyboardMarkup(resize_keyboard=True)
    key.add(types.KeyboardButton('⬅️' + locales[lng][1]))
    bot.send_message(call.from_user.id, locales[lng][67], reply_markup=key)
예제 #15
0
파일: new_bot.py 프로젝트: cz303/web
def set_title(msg):
    global state
    global status
    status[msg.chat.id] = 'desc'
    db().set_title(msg.text, msg.chat.id)
    try:
        lng = db().get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    bot.send_message(msg.chat.id, locales[lng][56].replace('\\n', '\n'))
예제 #16
0
def set_desc(msg):
    global state
    global status
    if len(msg.text) > 120:
        bot.send_message(msg.chat.id,
                         'Описание должно быть не длиннее 120 символов')
        return
    status[msg.chat.id] = 'price'
    db().set_desc(msg.text, msg.chat.id)
    bot.send_message(msg.chat.id,
                     'Введите цену   \n\n Для отмены нажмите на на /cancel')
예제 #17
0
파일: new_bot.py 프로젝트: cz303/web
def add_item_start(call):
    global state
    global status
    status[call.from_user.id] = call.data
    parent = call.data.split('_')[2]
    db().create_item(parent, call.from_user.id)
    try:
        lng = db().get_user_lang(call.from_user.id)[0][0]
    except IndexError:
        return
    bot.send_message(call.message.chat.id,
                     locales[lng][55].replace('\\n', '\n'))
예제 #18
0
파일: new_bot.py 프로젝트: cz303/web
def set_desc(msg):
    global state
    global status
    try:
        lng = db().get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    if len(msg.text) > 120:
        bot.send_message(msg.chat.id, locales[lng][57])
        return
    status[msg.chat.id] = 'price'
    db().set_desc(msg.text, msg.chat.id)
    bot.send_message(msg.chat.id, locales[lng][58].replace('\\n', '\n'))
예제 #19
0
def set_price(msg):
    global state
    global status
    try:
        price = float(msg.text)
    except ValueError:
        bot.send_message(msg.chat.id, 'Введите число')
        return
    status[msg.chat.id] = 'photo'
    db().set_price(msg.text, msg.chat.id)
    bot.send_message(
        msg.chat.id,
        'Пришлите ссылку на фото товара   \n\n Для отмены нажмите на на /cancel'
    )
예제 #20
0
def item_page(msg, item_id, edit=False):
    if not db().check_item(item_id):
        bot.send_message(msg.chat.id, 'Товар не найден')
        start_catalog(msg)
    else:
        info = db().get_item_by_id(item_id)[0]
        title, desc, photo, parent, price = info[1], info[2], info[3], info[
            4], info[6]
        text = '[​​​​​​​​​​​]({}) *{}*\n\n{}\n\nСтоимсоть: {}'.format(
            photo, title, desc, price)
        key = item_keygen(item_id, msg.chat.id, parent)
        bot.send_message(msg.chat.id,
                         text,
                         reply_markup=key,
                         parse_mode='markdown')
예제 #21
0
파일: new_bot.py 프로젝트: cz303/web
def set_price(msg):
    global state
    global status
    try:
        lng = db().get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    try:
        float(msg.text)
    except ValueError:
        bot.send_message(msg.chat.id, locales[lng][59])
        return
    status[msg.chat.id] = 'photo'
    db().set_price(msg.text, msg.chat.id)
    bot.send_message(msg.chat.id, locales[lng][60].replace('\\n', '\n'))
예제 #22
0
파일: new_bot.py 프로젝트: cz303/web
def add_to_cart(call):
    try:
        lng = db().get_user_lang(call.from_user.id)[0][0]
    except IndexError:
        return
    key = types.ReplyKeyboardMarkup(resize_keyboard=True)
    key.row(types.KeyboardButton('1'), types.KeyboardButton('2'),
            types.KeyboardButton('3'))
    key.row(types.KeyboardButton('4'), types.KeyboardButton('5'),
            types.KeyboardButton('6'))
    key.row(types.KeyboardButton('7'), types.KeyboardButton('8'),
            types.KeyboardButton('9'))
    key.row(types.KeyboardButton('📥 ' + locales[lng][12]),
            types.KeyboardButton('⬅️' + locales[lng][1]))
    db().set_state(call.from_user.id, call.data)
    bot.send_message(call.message.chat.id, locales[lng][40], reply_markup=key)
예제 #23
0
파일: new_bot.py 프로젝트: cz303/web
def add_cat(msg):
    key = keygen(0, msg.from_user.id)
    try:
        lng = db().get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    bot.send_message(msg.chat.id, locales[lng][49], reply_markup=key)
예제 #24
0
파일: new_bot.py 프로젝트: cz303/web
def std_key(msg, parent=0):
    dbw = db()
    cats = dbw.get_categories(parent)
    try:
        lng = dbw.get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    dbw.set_state(msg.from_user.id, '0')
    key = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True)
    row = []
    for c in cats:
        row.append(types.KeyboardButton(c[1]))
        categories[c[1]] = c[0]
        if len(row) == 2:
            key.row(*row)
            row.clear()
    if len(row) > 0:
        key.row(*row)
    key.row(types.KeyboardButton('📥 ' + locales[lng][12]),
            types.KeyboardButton('🚖 ' + locales[lng][13]))
    if parent == 0:
        key.row(types.KeyboardButton(locales[lng][14]))
    else:
        dbw.set_state(msg.from_user.id, 'sub')
        key.row(types.KeyboardButton('⬅️' + locales[lng][1]))

    if msg.from_user.id in config.admin_id:
        key.row(types.KeyboardButton(locales[lng][70]),
                types.KeyboardButton('Stats'))
    return key
예제 #25
0
def prev_item(call):
    a, iid, cat_id = call.data.split('_')
    items = db().get_items(cat_id)
    for i in range(len(items)):
        if int(iid) == items[i][0]:
            item_page(call.message, items[i - 1][0])
            del_msg(call)
예제 #26
0
파일: new_bot.py 프로젝트: cz303/web
def catalog1(msg, cat_id, uid, edit=False):
    try:
        lng = db().get_user_lang(uid)[0][0]
    except IndexError:
        print('Index in cat1')
        return
    if not db().check_cat(cat_id):
        bot.send_message(msg.chat.id, locales[lng][61])
        catalog(msg)
    else:
        text = locales[lng][62]
        key = keygen(cat_id, msg.chat.id)
        if not edit:
            bot.send_message(msg.chat.id, text, reply_markup=key)
        else:
            bot.edit_message_reply_markup(msg.chat.id,
                                          msg.message_id,
                                          reply_markup=key)
예제 #27
0
파일: new_bot.py 프로젝트: cz303/web
def catalog(msg):
    key = std_key(msg)
    dbw = db()
    try:
        lng = dbw.get_user_lang(msg.from_user.id)[0][0]
    except IndexError:
        return
    dbw.update_last(msg.from_user.id, int(time()))
    bot.send_message(msg.chat.id, locales[lng][16], reply_markup=key)
예제 #28
0
파일: new_bot.py 프로젝트: cz303/web
def item_page(msg, item_id, user_id):
    try:
        lng = db().get_user_lang(user_id)[0][0]
    except IndexError:
        return
    if not db().check_item(item_id):
        bot.send_message(msg.chat.id, locales[lng][6])
    else:
        info = db().get_item_by_id(item_id)[0]
        title, desc, photo, parent, price = info[1], info[2], info[3], info[
            4], info[6]
        text = '[​​​​​​​​​​​]({}) *{}*\n\n{}\n\n{}: {}'.format(
            photo, title, desc, locales[lng][7], price)
        key = item_keygen(item_id, msg.chat.id, parent)
        bot.send_message(msg.chat.id,
                         text,
                         reply_markup=key,
                         parse_mode='markdown')
예제 #29
0
def show_cart(msg):
    info = db().get_user_cart(msg.chat.id)
    items = info[1]
    text = ''
    if len(items) == 0:
        text = 'Ваша корзина пуста'
        bot.send_message(msg.chat.id, text)
        return
    for i in items:
        info1 = db().get_item_by_id(i[1])[0]
        text += '{} {}\n'.format(info1[1], i[2])
    text += '\nИтого: {}'.format(info[0][0])
    key = types.InlineKeyboardMarkup()
    key.add(
        types.InlineKeyboardButton('Оформить заказ', callback_data='form'),
        types.InlineKeyboardButton('Очистить корзину',
                                   callback_data='clear_cart'))
    bot.send_message(msg.chat.id, text, reply_markup=key)
예제 #30
0
파일: new_bot.py 프로젝트: cz303/web
def add_cat(call):
    global state
    global status
    try:
        lng = db().get_user_lang(call.from_user.id)[0][0]
    except IndexError:
        return
    status[call.message.chat.id] = call.data
    bot.send_message(call.message.chat.id,
                     locales[lng][50].replace('\\n', '\n'))