Ejemplo n.º 1
0
async def translate(session: CommandSession):
    text = session.get('text')
    if text:
        translation = await get_translation(text)
        await session.send(f'机翻译文:\n{translation}')
    else:
        await session.send('翻译姬待命中...')
Ejemplo n.º 2
0
def rssSubscribe(session: CommandSession):
    rssLink: str = session.get("link")
    session.send(f'开始检查订阅源:"{rssLink}"')
    # Get feed data
    rssResource: str = downloadFeed(rssLink)
    rssResourceParse: dict = rssParser(rssResource)
    # Check for duplicates with existing subscriptions
    subscribeToken = rssResourceParse["token"]
    getSettings = PluginManager.settings(__plugin_name__, session.ctx).settings
    if getSettings["subscribed"].get(subscribeToken):
        raise BotExistError(reason="此订阅已存在!")
    else:
        getSettings["subscribed"][subscribeToken] = {
            "link": rssLink,
            "last_update": rssResourceParse["last_update_stamp"],
        }
    # Processing messages
    repeatMessage = "\n".join(
        [
            str(CONFIG.customize.subscribe_repeat).format(**i)
            for i in rssResourceParse["content"][: CONFIG.customize.size]
        ]
    )
    fullMessage = (
        str(CONFIG.customize.subscribe_prefix).format(**rssResourceParse)
        + f"{repeatMessage}\n"
        + str(CONFIG.customize.subscribe_suffix).format(**rssResourceParse)
    )
    PluginManager.settings(__plugin_name__, session.ctx).settings = getSettings
    return fullMessage
Ejemplo n.º 3
0
def catch(session: CommandSession):
    stackID: str = session.get("id")
    returnData = """
    追踪ID:{stack_id}
    出错时间:{time_format}(时间戳{time})
    错误堆栈:\n{stack}""".format(
        **ExceptionProcess.read(stackID.upper())
    )
    return returnData
Ejemplo n.º 4
0
def enable(session: CommandSession):
    key: str = session.get("key")
    realKey: str = PluginManager.settings(
        pluginName=OPERATING_METHOD, ctx=session.ctx
    ).settings.get("key", "")
    if key.upper() == realKey.upper():
        PluginManager.settings(
            pluginName=__plugin_name__, ctx=session.ctx
        ).status = True
        return "涩图功能已启用", False
    else:
        return "此激活密钥无效", False
Ejemplo n.º 5
0
def enableR18(session: CommandSession):
    key = session.get("key")
    settings = PluginManager.settings(OPERATING_METHOD, ctx=session.ctx)
    if str(settings.settings.get("key", "")).upper() != str(key).upper():
        session.finish(f"密钥{key}无法激活该功能")
    PluginManager.settings(MEMBER_IMAGE_METHOD, ctx=session.ctx).settings = {
        "r-18": True
    }
    PluginManager.settings(SEARCH_IMAGE_METHOD, ctx=session.ctx).settings = {
        "r-18": True
    }
    PluginManager.settings(GET_IMAGE_METHOD, ctx=session.ctx).settings = {"r-18": True}
    return "封印已成功解除", False
Ejemplo n.º 6
0
def illustSearch(session: CommandSession):
    imageURL = session.get("image")
    session.send("开始以图搜图")
    searchContent = searchImage(imageURL)
    searchParse = getCorrectInfo(searchContent)
    messageRepeat = [
        str(Config.customize.repeat).format(**subject)
        for subject in searchParse["subject"]
    ]
    fullMessage = (str(Config.customize.prefix).format(**searchParse) +
                   "".join(messageRepeat[:Config.customize.size]) +
                   str(Config.customize.suffix).format(**searchParse))
    return fullMessage
Ejemplo n.º 7
0
def broadcast(session: CommandSession):
    broadcastContent = session.get("content")
    session.send(f"开始广播消息,内容如下:\n{broadcastContent}")
    beginTime = time()
    groupsList: List[int] = [
        i["group_id"] for i in callModuleAPI("get_group_list")
    ]
    totalSend = 0
    for groupID in groupsList:
        enabled = PluginManager._getSettings(__plugin_name__,
                                             type="group",
                                             id=groupID).status
        if not enabled:
            continue
        sendParams = {"group_id": groupID, "message": broadcastContent}
        callModuleAPI("send_msg", params=sendParams, ignoreError=True)
        totalSend += 1
    return f"消息广播完成,已广播到{totalSend}个群聊\n耗时{time() - beginTime:.3f}s"
Ejemplo n.º 8
0
def searchImage(session: CommandSession):
    enableR18 = PluginManager.settings(SEARCH_IMAGE_METHOD, session.ctx).settings[
        "r-18"
    ]
    keywords = session.get("keyword")
    page = session.get_optional("page", 1)
    session.send(f'开始搜索"{keywords}"的第{page}页')
    apiGet = pixiv.searchIllust(keyword=keywords, page=page)
    apiParse = parseMultiImage(apiGet, mosaicR18=not enableR18)
    sortResult = sorted(apiParse["result"], key=lambda x: x["ratio"], reverse=True)
    messageRepeat = [
        str(Config.customize.search_repeat).format(**data) for data in sortResult
    ]
    fullMessage = (
        str(Config.customize.search_prefix).format(**apiParse)
        + "".join(messageRepeat[: Config.customize.size])
        + str(Config.customize.search_suffix).format(**apiParse)
    )
    return fullMessage
Ejemplo n.º 9
0
def memberImage(session: CommandSession):
    memberID = session.get("id")
    enableR18 = PluginManager.settings(MEMBER_IMAGE_METHOD, session.ctx).settings[
        "r-18"
    ]
    page = session.get_optional("page", 1)
    session.send(f"开始获取Pixiv用户ID为{memberID}的作品第{page}页")
    apiGet = pixiv.getMemberIllust(memberID, page)
    apiParse = parseMultiImage(apiGet, mosaicR18=not enableR18)
    sortResult = sorted(apiParse["result"], key=lambda x: x["ratio"], reverse=True)
    messageRepeat = [
        str(Config.customize.member_repeat).format(**data) for data in sortResult
    ]
    fullMessage = (
        str(Config.customize.member_prefix).format(**apiParse)
        + "".join(messageRepeat[: Config.customize.size])
        + str(Config.customize.member_suffix).format(**apiParse)
    )
    return fullMessage
Ejemplo n.º 10
0
def animeSearch(session: CommandSession):
    imageLink = session.get("image")
    session.send("开始以图搜番")
    imageRes = imageDownload(imageLink)
    if determineImageType(imageRes) == "GIF":
        session.send("检测到GIF图片格式,自动截取第一帧上传")
        imageRes = processGIF(imageRes)
    if len(imageRes) >= 1024**2:
        raise BotProgramError("图片大小超过限制,必须小于1MiB," +
                              f"您的图片大小为{len(imageRes)/1024**2:.3f}MiB")
    searchResult = whatanimeUpload(imageRes)
    messageRepeat = [
        str(Config.customize.repeat).format(**perAnime)
        for perAnime in searchResult["docs"]
    ]
    fullMessage = (str(Config.customize.prefix).format(**searchResult) +
                   "".join(messageRepeat[:Config.customize.size]) +
                   str(Config.customize.suffix).format(**searchResult))
    return fullMessage
Ejemplo n.º 11
0
def wikipedia(session: CommandSession):
    keyword = session.get("keyword")
    session.send(f"开始Wiki搜索:{keyword}")
    pages = getWiki(keyword)["query"]["pages"]
    finalResult = {"keyword": keyword, "size": len(pages)}
    finalResult["result"] = []
    for page in pages.values():
        finalResult["result"].append({
            "title":
            page["title"],
            "introduce":
            page["extract"],
            "link":
            NetworkUtils.shortLink([page["fullurl"]])[page["fullurl"]],
        })
    repeatMessage = [
        str(CONFIG_READ.customize.repeat).format(**result)
        for result in finalResult["result"]
    ]
    fullMessage = (str(CONFIG_READ.customize.prefix).format(**finalResult) +
                   "".join(repeatMessage[:CONFIG_READ.size]) +
                   str(CONFIG_READ.customize.suffix).format(**finalResult))
    return fullMessage
Ejemplo n.º 12
0
def getImage(session: CommandSession):
    allowR18: bool = PluginManager.settings(GET_IMAGE_METHOD, ctx=session.ctx).settings[
        "r-18"
    ]
    imageID: int = session.get("id")
    imageResloution: str = session.get_optional("res", "large")
    session.send(f"开始获取Pixiv ID为{imageID}的{imageResloution}")
    apiGet = pixiv.getImageDetail(imageID)
    apiParse = parseSingleImage(apiGet, mosaicR18=not allowR18)
    imageURLs = [p[imageResloution] for p in apiParse["download"]][
        : Config.customize.size
    ]
    imageDownloaded = downloadMutliImage(
        imageURLs, mosaic=((not allowR18) and apiParse["r-18"])
    )
    images = [str(MessageSegment.image(imageDownloaded[i])) for i in imageURLs]
    repeatMessage = "\n".join(images)
    finalMessage = (
        str(Config.customize.image_prefix).format(**apiParse)
        + f"{repeatMessage}\n"
        + str(Config.customize.image_suffix).format(**apiParse)
    )
    return finalMessage