示例#1
0
文件: bot.py 项目: NVDMkPr/T_M
def Account(u, c):
    print("Account Calling")
    SearchData = SearchUserID(u.effective_user.id, "AddrGenByUser")
    reply_markup = IKM([[IKB("Địa Chỉ Nhận Tiền", None, 141)],
                        [IKB("Trở Lại", None, 1)]])
    if SearchData != None:
        if GetBalance(SearchData[0][1]) == False:
            verified = "Chưa Xác Minh"
        else:
            verified = "Đã Xác Minh"
        if SearchData[0][2] == 0.0:
            text = f"Địa Chỉ Token: {SearchData[0][1]}\nSố Dư TRX: {SearchData[0][2]} ( ❗ Không Đủ Số Dư Để Chuyển Token )\nTình Trạng Xác Minh: {verified}"
        else:
            text = f"Địa Chỉ Token: {SearchData[0][1]}\nSố Dư TRX: {GetBalance(SearchData[0][1])}\nTình Trạng Xác Minh: {verified}"
        Send(text, reply_markup, u, c)
    elif SearchData == None:
        text = "Đang Tạo Địa Chỉ Token Cho Bạn, Có Thể Mất Tối Đa 1 Phút"
        reply_markup = IKM([[IKB("Trở Lại", None, 1)]])
        Send(text, reply_markup, u, c)
        New = GenAddr()
        user_id = u.effective_user.id
        InsertData("AddrGenByUser", "",
                   f'''{user_id},"{New[0]}",0.0,"{New[1]}",False''')
        time.sleep(5)
        c.bot.delete_message(u.effective_chat.id,
                             u.effective_message.message_id + 1)
        Account(u, c)
def menu(upd, context):
    print('entrei no menu')
    text = 'MENU PRINCIPAL - Selecione uma das opções:\n\r'
    buttons = bt.buttons(MENU)
    if context.user_data.get(START_OVER):
        upd.callback_query.answer()
        upd.callback_query.edit_message_text(text=text,
                                             reply_markup=IKM(buttons))
        return MENU
    else:
        user_id = upd.message.chat_id
        try:
            query = db.get_info(user_id)
            print(query)
            user_allowed = int(query[0][4])
            if user_allowed:
                upd.message.reply_text('Olá! Se precisar de ajuda, '
                                       'contate o @DanMMoreira.')
                upd.message.reply_text(text=text, reply_markup=IKM(buttons))
                context.user_data[START_OVER] = True
                return MENU
            else:
                text = 'Você ainda não está autorizado. Fale com o administrador!'
                upd.message.reply_text(text=text)
        except:
            pass
 def modify_document(self, bot, ids, action, args):
     chat, message_id = ids
     if action == 'order':
         doc_id, doc_type = args
         status, report = self.controller.check_out_doc(chat, int(doc_id), type_bd=doc_type)
         message = "Your order was successful.\nYou may take the document during library working hours." if status else "You already have this document"
         bot.edit_message_text(text=message, chat_id=chat, message_id=message_id)
     elif action == 'queue':
         doc_id, doc_type = args
         status, report = self.controller.add_queue_order(chat, doc_type, int(doc_id))
         message = "You was added in queue.\nYou will be notified when the document be available" if status else report
         bot.edit_message_text(text=message, chat_id=chat, message_id=message_id)
     elif action == 'del':
         message = "Are you sure want to delete this document?"
         markup = IKM([[IKB('Yes', callback_data='yes {} {} library'.format(*args[1:])),
                        IKB('No', callback_data='cancel {} {} library'.format(args[0], args[-1]))]])
         bot.edit_message_text(chat_id=chat, message_id=message_id, text=message, reply_markup=markup)
     elif action == 'yes':
         message = 'Document was deleted successfully'
         self.controller.delete_document(*args)
         bot.edit_message_text(text=message, chat_id=chat, message_id=message_id)
     elif action == 'edit':
         doc_type = args[-1]
         callback = ['e{} {} {} {} library'.format(i, *args) for i in range(9)]
         keyboard = [[IKB("Title", callback_data=callback[0]), IKB("Author", callback_data=callback[1])]]
         if doc_type == 'book':
             keyboard += [
                 [IKB("Description", callback_data=callback[2]), IKB("Keywords", callback_data=callback[3])],
                 [IKB("Price", callback_data=callback[4]), IKB("Count", callback_data=callback[5])]]
         elif doc_type == 'article':
             keyboard += [[IKB("Journal", callback_data=callback[2]), IKB("Issue", callback_data=callback[3])],
                          [IKB("Editors", callback_data=callback[4]), IKB("Date", callback_data=callback[5])],
                          [IKB("Keywords", callback_data=callback[6]), IKB("Price", callback_data=callback[7])],
                          IKB("Count", callback_data=callback[8])]
         elif doc_type == 'media':
             keyboard += [[IKB("Keywords", callback_data=callback[2]), [IKB("Price", callback_data=callback[3])],
                           IKB("Count", callback_data=callback[4])]]
         keyboard += [[IKB('Cancel️', callback_data='cancel {} {} library'.format(args[0], args[-1]))]]
         text = "Choose edited parameter"
         bot.edit_message_text(text=text, chat_id=chat, message_id=message_id,
                               reply_markup=IKM(keyboard))
     elif action in ['e{}'.format(i) for i in range(9)]:
         doc_type = args[-1]
         doc_id = args[1]
         parameter = func_data.lists[doc_type][int(action[1])]
         parameter_db = func_data.lists[doc_type + "_bd"][int(action[1])]
         doc = self.controller.get_document(doc_id, doc_type)
         keyboard = [[IKB('Cancel️', callback_data='cancel {} {} library'.format(args[0], args[-1]))]]
         text = 'Enter new {}.\nOld value - {}.'.format(parameter, doc[parameter_db])
         self.location[chat] = "doc_modify"
         self.user_data[chat] = [doc, parameter_db, doc_type]
         bot.edit_message_text(text=text, chat_id=chat, message_id=message_id, reply_markup=IKM(keyboard))
def track_upd(upd, context):
    print('entrei no track_upd')
    context.user_data[PREV_LEVEL] = menu_track
    user_id = upd.effective_user.id
    choice = int(upd.callback_query.data)
    context.user_data['choice'] = choice
    if choice < 4:
        text = 'Digite o índice a ser adicionado para monitorar seu preço de venda ' \
            'ou selecione uma das opções ' \
            '(para adicionar vários, digite os índices separados por vírgula):'
    else:
        t_list = fc.func_get_tickers_user(user_id, False)
        reply_markup = json.dumps({
            'keyboard': [[x] for x in t_list],
            'one_time_keyboard': True
        })
        text = 'Escolha o índice a ser removido ou selecione uma das opções:'
        fc.func_send_msg(chat_id=user_id,
                         text='Carteira:',
                         reply_markup=reply_markup)
    #keyboard com os índices
    #elif retirar alerta
    #text = RETI+'Os alertas da carteira foram removidos até o preço mudar novamente.'
    buttons = bt.buttons(EXIT)
    upd.callback_query.answer()
    send = upd.callback_query.edit_message_text(text=text,
                                                reply_markup=IKM(buttons))
    context.user_data['msg_id'] = send.message_id
    return TRACK_EXIT
def portf_upd(upd, context):
    print('entrei no portf_upd')
    context.user_data[PREV_LEVEL] = menu_portf
    user_id = upd.effective_user.id
    choice = int(upd.callback_query.data)
    context.user_data['choice'] = choice
    if choice == 3:
        text = 'Tem certeza que deseja zerar o valor do capital?'
        keyboard = [['Sim'], ['Cancelar']]
        reply_markup = json.dumps({
            'keyboard': keyboard,
            'one_time_keyboard': True
        })
        query_markup = ''
        forward = PORTF_CLEAR
        fc.func_send_msg(chat_id=user_id,
                         text='Escolha abaixo:',
                         reply_markup=reply_markup)
    else:
        opts = ['adicionar', 'subtrair', 'substituir']
        text = 'CAPITAL - Digite o valor a '+opts[choice]+' ' \
            '(somente números) ou selecione uma das opções:'
        buttons = bt.buttons(EXIT)
        query_markup = IKM(buttons)
        forward = PORTF_CHANGE
    upd.callback_query.answer()
    send = upd.callback_query.edit_message_text(text=text,
                                                reply_markup=query_markup)
    context.user_data['msg_id'] = send.message_id
    return forward
示例#6
0
    def online_init(self, bot, update):
        chat_id = update.message.chat_id
        loc = self.location[chat_id]
        text = update.message.text
        add_data, text = (
            text, self.user_data[chat_id][0]) if loc == 'search' else ('',
                                                                       text)
        data_list, max_page = self.get_data(bot, chat_id, loc, text, add_data)
        if not data_list:
            return
        text_message = func_data.text_gen(data_list, loc, add_text=add_data)
        if loc == 'library':
            loc = func_data.analog[text] + ' ' + loc
        if loc == 'search':
            loc = '{} {} {}'.format(add_data, text, loc)

        keyboard = [[
            IKB(str(i + 1), callback_data='item {} {} {}'.format(i, 0, loc))
            for i in range(len(data_list[0]))
        ]]
        keyboard += [[
            IKB('⬅', callback_data='prev 0 {} ' + loc),
            IKB('➡️', callback_data='next 0 ' + loc)
        ]]
        update.message.reply_text(text=text_message + '\n\nCurrent page: 1/' +
                                  str(max_page + 1),
                                  reply_markup=IKM(keyboard))
示例#7
0
    def online_button_checker(self, bot, update):
        query = update.callback_query
        chat_id = query.message.chat.id
        message_id = query.message.message_id
        action, *args, loc = query.data.split(' ')
        add_data = args[-2] if loc == 'search' else ''
        data_list, max_page = self.get_data(bot, chat_id, loc, args[-1],
                                            add_data)
        if not data_list:
            return

        if action in ['prev', 'next'] and max_page or action == 'cancel':
            page = int(args[0])
            if action == 'next':
                page = 0 if page == max_page else page + 1
            if action == 'prev':
                page = max_page if page == 0 else page - 1
            text_message = func_data.text_gen(data_list, loc, page, add_data)
            if loc == 'library':
                loc = args[-1] + ' ' + loc
            if loc == 'search':
                loc = '{} {} {}'.format(*args[-2:], loc)
            keyboard = [[
                IKB(str(i + 1),
                    callback_data='item {} {} {}'.format(i, page, loc))
                for i in range(len(data_list[page]))
            ]]
            keyboard += [[
                IKB('⬅', callback_data='prev {} {}'.format(page, loc)),
                IKB('➡️', callback_data='next {} {}'.format(page, loc))
            ]]
            bot.edit_message_text(
                text=text_message +
                '\n\nCurrent page: {}/{}'.format(page + 1, max_page + 1),
                chat_id=chat_id,
                message_id=message_id,
                reply_markup=IKM(keyboard))
        elif action == 'item':
            k = int(args[0])
            page = int(args[1])
            item = data_list[page][k]
            message = self.get_message(loc, page, item, args[-1], chat_id,
                                       add_data)
            bot.edit_message_text(chat_id=chat_id,
                                  message_id=message_id,
                                  text=message[0],
                                  reply_markup=message[1])
        elif action in ['accept', 'reject'] and loc == 'confirm':
            user_id = int(args[0])
            ids = [chat_id, message_id]
            self.conf_user(bot, ids, user_id, action)
        elif loc in ['library', 'search']:
            ids = [chat_id, message_id]
            self.modify_document(bot, ids, action, args)
        elif loc == 'users':
            ids = [chat_id, message_id]
            self.user_flip(bot, ids, action, args)
        elif loc == 'my_orders':
            ids = [chat_id, message_id]
            self.manage_orders(bot, ids, action, args)
示例#8
0
def Start(update, context):
    bot = context.bot
    chat_id = update.effective_chat.id
    text = '''<b><i>Deposit Now And Receive 120% Profits In 20 Days</i>\n<u>Minium 10$ Maximum 500$</u>
🔥 <i>Bonus Up To 140% Profits From Now To <u>15/11/2020</u></i></b>'''
    reply_markup = IKM([[IKB("Account", None, 1),
                         IKB("Support", None, 2)], [IKB("Stat", None, 3)]])
    bot.send_message(chat_id, text, "HTML", True, True, None, reply_markup)
def set_time(upd, context):
    print('entrei no set_time')
    context.user_data[PREV_LEVEL] = menu_set
    text = 'MUDAR HORA/DIA - Selecione uma das opções.'
    buttons = bt.buttons(SET_TIME)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    return TIME_UPD
def set_mode(upd, context):
    print('entrei no set_mode')
    context.user_data[PREV_LEVEL] = menu_set
    text = 'CONFIGURAÇÕES DE MODO - Selecione a classe de ativos ' \
           'e a escala temporal a serem usados no alerta automático.'
    buttons = bt.buttons(SET_MODE)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    return MODE_UPD
def help_exit(upd, context):
    print('entrei no help_exit')
    context.user_data[PREV_LEVEL] = menu_help
    text = 'AJUDA - TITULO QUALQUER'
    buttons = bt.buttons(EXIT)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    context.user_data[START_OVER] = True
    return MENU_HELP
def set_risk(upd, context):
    print('entrei no set_risk')
    context.user_data[PREV_LEVEL] = menu_set
    text = 'CONFIGURAÇÕES DE RISCO - Selecione o gerenciamento de risco a ' \
           'ser utilizado no cálculo do volume:'
    buttons = bt.buttons(SET_RISK)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    return RISK_UPD
def menu_help(upd, context):
    print('entrei no menu_help')
    context.user_data[PREV_LEVEL] = menu
    text = 'AJUDA - Selecione um tópico:'
    buttons = bt.buttons(MENU_HELP)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    context.user_data[START_OVER] = True
    return MENU_HELP
示例#14
0
def Deposit(bot, chat_id):
    text = '''<b>Choose One Currency Type Available For Deposit<i>
❗ Auto Withdraw Will Send Your Profit To Deposit Address|Account!</i>
Payeer: <code>P1031638149</code>
BTC: <code>1LxudDaPdWjdp8RW7xyNpjdWL4J1AZZdQe</code>
ETH: <code>0x94f29C62DaDea7fB6a34E65C4446fE54E94151CF</code>
LTC: <code>LY6iiqXWv1njZFtay5BKjgeMVJsyvpCLC4</code></b>'''
    reply_markup = IKM([[IKB("Back", None, 1)]])
    bot.send_message(chat_id, text, "HTML", True, False, None, reply_markup)
示例#15
0
def Stat(bot, chat_id):
    text = '''<b>Bot Statistics
    👥 Total User: {function}
    ➕ Total Investments: {function}$
    ➖ Total Withdrawals: {function}$
    ⬆️ Total Profit To Admin From All Investor: {function}$</b>
    <u>Version: {function}</u>'''
    reply_markup = IKM([[IKB("Back", None, 0)]])
    bot.send_message(chat_id, text, "HTML", True, True, None, reply_markup)
def menu_set(upd, context):
    print('entrei no menu_set')
    context.user_data[PREV_LEVEL] = menu
    text = 'CONFIGURAÇÕES - Selecione uma das opções.'
    buttons = bt.buttons(MENU_SET)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    context.user_data[START_OVER] = True
    return SET_TIME
示例#17
0
def Account(bot, chat_id):
    text = '''👤 <b>Account Balance:
    💵 Withdrawable Balance: {function}$
    💎 Active Investment: {function}$
    🚧 Pending Withdraw: {function}$
    ✔️ Total Withdrawn: {function}$</b>'''
    reply_markup = IKM(
        [[IKB("Invest", None, 11),
          IKB("Auto Withdraw", None, 12)], [IKB("Back", None, 0)]])
    bot.send_message(chat_id, text, "HTML", True, True, None, reply_markup)
示例#18
0
文件: bot.py 项目: NVDMkPr/T_M
def Start(u, c):
    print("Start Calling")
    reply_markup = IKM(
        [[IKB("Danh Sách Airdrop", None, 11)],
         [IKB("Thông Báo Mới Nhất", channel_link),
          IKB("Hỗ Trợ", group_link)], [IKB("Thông Tin Tài Khoản", None, 14)]])
    Send(test, reply_markup, u, c)
    if u.effective_message.text == "/start":
        c.bot.delete_message(u.effective_chat.id,
                             u.effective_message.message_id)
示例#19
0
文件: bot.py 项目: NVDMkPr/T_M
def Set(u, c):
    reply_markup = IKM([[IKB("Menu Chính", None, 1)]])
    Addr = re.split("^/set ", u.effective_message.text)
    if len(Addr) == 2:
        InsertData("AddrByUser", "", f"{u.effective_user.id},'{Addr[1]}'")
    else:
        Send("Địa Chỉ Bạn Vừa Nhập Sai Hoặc Lỗi Gì Đó!", reply_markup, u, c)
        return None
    Send(
        f"Địa Chỉ Rút Tiền Của Bạn Sẽ Được Lưu Sau 2-60 giây Nữa!\nĐể Tránh Tình Trạng Quá Tải!",
        reply_markup, u, c)
def menu_track(upd, context):
    print('entrei no menu_track')
    context.user_data[PREV_LEVEL] = menu
    user_id = upd.effective_user.id
    text = 'CARTEIRA - Selecione uma das opções.\n\r' \
           'Composição atual da carteira:\n\r'+fc.func_get_tickers_user(user_id)
    buttons = bt.buttons(MENU_TRACK)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    context.user_data[START_OVER] = True
    return TRACK_UPD
def menu_portf(upd, context):
    print('entrei no menu_portf')
    context.user_data[PREV_LEVEL] = menu
    user_id = upd.effective_user.id
    portf = db.get_info(user_id)[0][6]
    text = 'CAPITAL - Selecione uma das opções.\n\r' \
           'Valor atual de carteira: R$'+portf+''
    buttons = bt.buttons(MENU_PORTF)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    context.user_data[START_OVER] = True
    return PORTF_UPD
def menu_radar(upd, context):
    print('entrei no menu_radar')
    context.user_data[PREV_LEVEL] = menu
    user_id = upd.effective_user.id
    order = fc.func_order(user_id)
    text = 'RELATÓRIOS - Selecione a análise ' \
        'ou modifique a ordenação dos resultados.\n\r' \
        'Atual: ordenar por '+order
    buttons = bt.buttons(MENU_RADAR)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    context.user_data['choice'] = 'track'
    context.user_data[START_OVER] = True
    return RADAR_A
def radar_a(upd, context):
    print('entrei no radar_a')
    choice = upd.callback_query.data
    if choice == 'buy':
        context.user_data['choice'] = 'buy'
        text = 'Selecione o modo:'
        buttons = bt.buttons(RADAR_BUY)
    elif choice == 'order':
        context.user_data['choice'] = 'order'
        text = 'Selecione a referência:'
        buttons = bt.buttons(RADAR_ORDER)
    upd.callback_query.answer()
    upd.callback_query.edit_message_text(text=text, reply_markup=IKM(buttons))
    return RADAR_B
示例#24
0
    def online_init(self, bot, update):
        chat = update.message.chat_id
        loc = self.location[chat]
        text = update.message.text
        data_list, max_page = self.get_data(bot, chat, loc, text)
        if not data_list:
            return
        text_message = func_data.text_gen(data_list, loc)
        if loc == 'library':
            loc = func_data.analog[text] + " " + loc

        keyboard = [
            [IKB(str(i + 1), callback_data="item {} {} {}".format(i, 0, loc)) for i in range(len(data_list[0]))]]
        keyboard += [[IKB("⬅", callback_data='prev 0 {} ' + loc), IKB("➡️", callback_data='next 0 ' + loc)]]
        update.message.reply_text(text=text_message + "\n\nCurrent page: 1/" + str(max_page + 1),
                                  reply_markup=IKM(keyboard))
def time_upd(upd, context):
    print('entrei no time_upd')
    context.user_data[PREV_LEVEL] = set_time
    user_id = upd.effective_user.id
    choice = int(upd.callback_query.data)
    context.user_data['choice'] = choice
    cb_text, text, keyboard = fc.func_time_upd(user_id, int(choice))
    buttons = bt.buttons(EXIT)
    upd.callback_query.answer()
    send = upd.callback_query.edit_message_text(text=cb_text,
                                                reply_markup=IKM(buttons))
    context.user_data['msg_id'] = send.message_id
    if keyboard:
        reply_markup = json.dumps({
            'keyboard': keyboard,
            'one_time_keyboard': True
        })
        fc.func_send_msg(chat_id=user_id, text=text, reply_markup=reply_markup)
    return TIME_EXIT
def admin_c(upd, context):
    print('entrei no admin c')
    msg_id = upd.message.message_id
    msg = upd.message.text
    choice = context.user_data['selection']
    admin_text, success = fc.func_admin(msg, choice)
    fc.func_send_msg(chat_id=curr_admin_id,
                     text=admin_text,
                     reply_to_message_id=msg_id)
    if success:
        if choice == 0:
            msg = msg.split(', ')
            context.user_data['user_id'] = msg[0]
            buttons = bt.buttons(ADMIN_C)
            admin_text = 'Deseja enviar o formulário de configs iniciais para o usuário?'
            upd.message.reply_text(text=admin_text, reply_markup=IKM(buttons))
            return ADMIN_D
        else:
            return -1
    else:
        return ADMIN_C
示例#27
0
    def show_nations_menu(self, bot, game):
        players = game.players.values()

        try:
            player = random.choice([p for p in players if p.nation is None])

        except IndexError:
            self.nations_menu_finalize(bot, game)
            return

        taken = {p.nation for p in players}
        available = [n for n in nations if n not in taken]
        available.append("RANDOM")

        keyboard = IKM([[IKB(n, callback_data="NATION_" + n)]
                        for n in available])

        handle = player.get_handle(bot, game.chat_id)
        message = bot.send_message(game.chat_id,
                                   handle + " choose a nation",
                                   reply_markup=keyboard)

        game.assigning = player.id
        game.assigning_message = message
示例#28
0
文件: bot.py 项目: NVDMkPr/T_M
def WithdrawAddr(u, c):
    print("WithdrawAddr Calling")
    Data = "Hãy Nhập Theo Mẫu '/set <Địa Chỉ Của Bạn>' Để Đặt Địa Chỉ Rút Tiền!"
    reply_markup = IKM([[IKB("Trở Lại", None, 14)]])
    Send(Data, reply_markup, u, c)
示例#29
0
文件: bot.py 项目: NVDMkPr/T_M
def AirdropList(u, c):
    print("AirdropList Calling", end="\r")
    reply_markup = IKM([[IKB("Airdrop Link", channel_link)],
                        [IKB("Trở Lại", None, 1)]])
    Send(test, reply_markup, u, c)
示例#30
0
    def get_message(self,
                    loc,
                    page,
                    item,
                    doc_type=None,
                    chat_id=None,
                    add_text=''):
        message = [0, 0]
        if loc == 'confirm':
            message[0] = 'Check whether all data is correct:\nName: {name}' \
                         '\nAddress: {address}\nPhone: {phone}\nStatus: {status}'.format(**item)
            message[1] = IKM([[
                IKB('Accept✅',
                    callback_data='accept {} {}'.format(item['id'], loc)),
                IKB('Reject️❌',
                    callback_data='reject {} {}'.format(item['id'], loc)),
                IKB('Cancel⤵️', callback_data='cancel {} {}'.format(page, loc))
            ]])
        elif loc in ['library', 'search']:
            text = 'Title: {title}\nAuthors: {authors}\n'
            if doc_type == 'book':
                text += 'Description: {description}\nFree copy: {free_count}'
            elif doc_type == 'article':
                text += 'Journal: {journal}\nIssue: {issue}\nDate: {date}\nFree copy: {free_count}'
            elif doc_type == 'media':
                text += 'Free copy: {free_count}'
            c = add_text + " " + doc_type if add_text else doc_type
            cancel = IKB('Cancel',
                         callback_data='cancel {} {} {}'.format(page, c, loc))
            edit = IKB('Edit',
                       callback_data='edit {} {} {} library'.format(
                           page, item['id'], doc_type))
            delete = IKB('Delete',
                         callback_data='del {} {} {} library'.format(
                             page, item['id'], doc_type))
            if self.controller.user_type(chat_id) == 2:
                cb = 'order {} {} library' if item[
                    'free_count'] > 0 else 'queue {} {} library'
                keyboard = [[
                    IKB('Order the document',
                        callback_data=cb.format(item['id'], doc_type)), cancel
                ]]
            elif self.controller.user_type(chat_id) == 3:
                if item['free_count'] == item['count']:
                    keyboard = [[edit, delete, cancel]]
                else:
                    keyboard = [[edit, cancel]]
            else:
                keyboard = [[cancel]]
            message[0] = text.format(**item)
            message[1] = IKM(keyboard)
        if loc == 'my_orders':
            keys = [
                'user_id', 'doc', 'table', 'time', 'time_out', 'active', 'id'
            ]
            user, doc, doc_type, time, time_out, active, order_id = [
                item[i] for i in keys
            ]
            message[0] = 'Title: {}\nAuthors: {}\nAvailable till: {}'.format(
                doc['title'], doc['authors'], time_out)
            keyboard = []
            if active and not [
                    j for i in utils.to_list(doc['queue']) for j in i
            ]:
                keyboard += [
                    IKB('Renew🔄',
                        callback_data='renew {} {}'.format(order_id, loc))
                ]
            elif not active:
                keyboard += [
                    IKB('Repeal❌',
                        callback_data='repeal {} {}'.format(order_id, loc))
                ]
            keyboard += [
                IKB('Cancel⤵️', callback_data='cancel {} {}'.format(page, loc))
            ]
            message[1] = IKM([keyboard])
        if loc == 'users':
            user = item
            user_id = user['id']
            orders = self.controller.get_user_orders(user_id)
            text = 'Name: {name}\nAddress: {address}\nPhone: {phone}\nStatus: {status}\nTaken documents: '.format(
                **user)
            text += '{}\nOverdue documents: '.format(len(orders))
            overdue = filter(
                lambda i: datetime.strptime(i['time_out'], '%Y-%m-%d') <
                datetime.today(), orders)
            text += str(len(list(overdue)))
            keyboard = [[
                IKB('Edit',
                    callback_data='edit {} {} {}'.format(page, user_id, loc)),
                IKB('Cancel️',
                    callback_data='cancel {} {} {}'.format(
                        page, doc_type, loc))
            ]]
            if orders:
                keyboard[0].insert(
                    1,
                    IKB('Orders',
                        callback_data='orders {} {} {}'.format(
                            page, user_id, loc)))
            else:
                keyboard[0].insert(
                    1,
                    IKB('Delete',
                        callback_data='delete {} {} {}'.format(
                            page, user_id, loc)))
            message[0] = text.format(**user)
            message[1] = IKM(keyboard)

        return message