def leaderboard(bot, update): c_id = update.message.chat_id lb = databasemanager.ROOMS_TABLE cnt = 10 if len(update.message.text.split(' ')) >= 2: lb = update.message.text.split(' ')[1] if len(update.message.text.split(' ')) >= 3: try: cnt_ = int(update.message.text.split(' ')[2]) if cnt_ > 0: cnt = cnt_ except: pass res = databasemanager.get_leaderboard(lb, count=cnt) msg = '' if lb == 'death': for i, r in enumerate(res): msg += '{0}. {1}: {2}\n'.format(i + 1, r['death_reason'], round(r['count'])) else: for i, r in enumerate(res): uid = r['uid'] name = r['name'] score = round(r['score']) username = bot.getChat(uid)['username'] death_reason = None if 'death_reason' in r: death_reason = r['death_reason'] table_name = "{0}".format(name) if len(username) > 0: table_name += ' (@{0})'.format(username) msg += '{0}. {1}: {2}'.format(i + 1, table_name, score) if death_reason is not None: msg += '\nПричина смерти: ' + death_reason msg += '\n' bot.sendMessage(update.message.chat_id, text=msg)