Esempio n. 1
0
async def inline(iq):
    msg = iq.query.split(" type:")
    art = msg[0].split('>')
    if (len(art) == 2):
        if (len(msg) == 2):
            logger.info("%s 搜尋了 %s 格式的 %s 的 %s", iq.sender, msg[1].upper(),
                        art[0], art[1])
            await bot.send_message(
                os.environ.get("LOGCHN_ID"),
                str(iq.sender) + " 搜尋了 " + msg[1].upper() + " 格式的 " + art[0] +
                "的" + art[1])
            cursor = text_search(iq.query)
            results = [
                inline_result(iq.query, t) for t in await cursor.to_list(10)
            ]
            await iq.answer(results)
        elif (len(msg) == 1):
            logger.info("%s 搜尋了 %s 的 %s", iq.sender, art[0], art[1])
            await bot.send_message(
                os.environ.get("LOGCHN_ID"),
                str(iq.sender) + " 搜尋了 " + art[0] + "的" + art[1])
            cursor = text_search(iq.query)
            results = [
                inline_result(iq.query, t) for t in await cursor.to_list(10)
            ]
            await iq.answer(results)
    elif (len(msg) == 2):
        logger.info("%s 搜尋了 %s 格式的 %s", iq.sender, msg[1].upper(), msg[0])
        await bot.send_message(
            os.environ.get("LOGCHN_ID"),
            str(iq.sender) + " 搜尋了 " + msg[1].upper() + " 格式的 " + msg[0])
        cursor = text_search(iq.query)
        results = [
            inline_result(iq.query, t) for t in await cursor.to_list(10)
        ]
        await iq.answer(results)
    elif (len(msg) == 1):
        logger.info("%s 搜尋了 %s", iq.sender, iq.query)
        await bot.send_message(os.environ.get("LOGCHN_ID"),
                               str(iq.sender) + " 搜尋了 " + str(iq.query))
        cursor = text_search(iq.query)
        results = [
            inline_result(iq.query, t) for t in await cursor.to_list(10)
        ]
        await iq.answer(results)
    else:
        logger.info("元素個數有問題RR")
        await bot.send_message(os.environ.get("LOGCHN_ID"), "元素個數有問題RRR")
        await bot.send_message(
            os.environ.get("LOGCHN_ID"), "(iq.query , msg , len(msg)) = " +
            str(iq.query) + " , " + str(msg) + " , " + str(len(msg)))
        logger.info("(iq.query , msg , len(msg)) = (%s , %s , %d)",
                    str(iq.query), str(msg), len(msg))
Esempio n. 2
0
async def search_tracks(chat, query, page=1):
    logger.info("%s searching for %s", chat.sender, query)

    limit = 3
    offset = (page - 1) * limit

    cursor = text_search(query).skip(offset).limit(limit)
    count = await cursor.count()
    results = await cursor.to_list(limit)

    if count == 0:
        await chat.send_text(not_found)
        return

    # Return single result if we have exact match for title and performer
    if results[0]['score'] > 2:
        limit = 1
        results = results[:1]

    newoff = offset + limit
    show_more = count > newoff

    if show_more:
        pages = math.ceil(count / limit)
        kb = [['(%d/%d) Show more for "%s"' % (page, pages, query)]]
        keyboard = {"keyboard": kb, "resize_keyboard": True}
    else:
        keyboard = {"hide_keyboard": True}

    for track in results:
        await send_track(chat, keyboard, track)
Esempio n. 3
0
async def search_tracks(chat, query, page=1):
    logger.info("%s searching for %s", chat.sender, query)

    limit = 3
    offset = (page - 1) * limit

    cursor = text_search(query).skip(offset).limit(limit)
    count = await cursor.count()
    results = await cursor.to_list(limit)

    if count == 0:
        await chat.send_text(not_found)
        return

    # Return single result if we have exact match for title and performer
    if results[0]['score'] > 2:
        limit = 1
        results = results[:1]

    newoff = offset + limit
    show_more = count > newoff

    if show_more:
        pages = math.ceil(count / limit)
        kb = [['(%d/%d) Show more for "%s"' % (page, pages, query)]]
        keyboard = {
            "keyboard": kb,
            "resize_keyboard": True
        }
    else:
        keyboard = { "hide_keyboard": True }

    for track in results:
        await send_track(chat, keyboard, track)
Esempio n. 4
0
async def search_tracks(chat, query, page=1):
    if (str(chat.sender) != "N/A"):
        typel = query.split(" type:")
        if (query.find(">") != -1):
            art = typel[0].split('>')
            author = art[0]
            song = art[1]
            if (len(typel) == 1):
                logger.info("%s 搜尋了 %s 的 %s", chat.sender, author, song)
                await bot.send_message(
                    os.environ.get("LOGCHN_ID"),
                    str(chat.sender) + " 搜尋了 " + author + " 的 " + song)
            else:
                logger.info("%s 搜尋了 %s 格式的 %s 的 %s", chat.sender,
                            typel[1].upper(), author, song)
                await bot.send_message(
                    os.environ.get("LOGCHN_ID"),
                    str(chat.sender) + " 搜尋了 " + typel[1].upper() + " 格式的 " +
                    author + " 的 " + song)
        elif (len(typel) == 1):
            logger.info("%s 搜尋了 %s", chat.sender, query)
            await bot.send_message(os.environ.get("LOGCHN_ID"),
                                   str(chat.sender) + " 搜尋了 " + str(query))
        else:
            logger.info("%s 搜尋了 %s 格式的 %s", chat.sender, typel[1].upper(),
                        typel[0])
            await bot.send_message(
                os.environ.get("LOGCHN_ID"),
                str(chat.sender) + " 搜尋了 " + typel[1].upper() + " 格式的 " +
                str(typel[0]))

        limit = 3
        offset = (page - 1) * limit

        cursor = text_search(query).skip(offset).limit(limit)
        count = await cursor.count()
        results = await cursor.to_list(limit)

        if count == 0:
            await chat.send_text(not_found)
            return

        # Return single result if we have exact match for title and performer
        if results[0]['score'] > 2:
            limit = 1
            results = results[:1]

        newoff = offset + limit
        show_more = count > newoff

        if show_more:
            pages = math.ceil(count / limit)
            kb = [['(%d/%d) 下一頁 "%s"' % (page + 1, pages, query)]]
            keyboard = {"keyboard": kb, "resize_keyboard": True}
        else:
            keyboard = {"hide_keyboard": True}

        for track in results:
            await send_track(chat, keyboard, track)
Esempio n. 5
0
    async def search(self, request):
        text = request.GET.get("text")
        offset = int(request.GET.get("offset", 0))
        limit = int(request.GET.get("limit", 10))

        cursor = text_search(text) if text else db.tracks.find({})
        total = await cursor.count()
        results = await cursor.skip(offset).limit(limit).to_list(limit)
        for r in results:
            del r["_id"]

        return web.json_response({
            "tracks": results,
            "offset": offset,
            "limit": limit,
            "total": total
        })
Esempio n. 6
0
    async def search(self, request):
        text = request.GET.get("text")
        offset = int(request.GET.get("offset", 0))
        limit = int(request.GET.get("limit", 10))

        cursor = text_search(text) if text else db.tracks.find({})
        total = await cursor.count()
        results = await cursor.skip(offset).limit(limit).to_list(limit)
        for r in results:
            del r["_id"]

        return web.json_response({
            "tracks": results,
            "offset": offset,
            "limit": limit,
            "total": total
        })
Esempio n. 7
0
async def inline(iq):
    logger.info("%s searching for %s", iq.sender, iq.query)
    cursor = text_search(iq.query)
    results = [inline_result(t) for t in await cursor.to_list(10)]
    await iq.answer(results)
Esempio n. 8
0
async def inline(iq):
    logger.info("%s searching for %s", iq.sender, iq.query)
    cursor = text_search(iq.query)
    results = [inline_result(t) for t in await cursor.to_list(10)]
    await iq.answer(results)