Beispiel #1
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
Beispiel #2
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
Beispiel #3
0
def _(session: CommandSession):
    session.send("开始生成词云")
    latestTime = datetime.datetime.now() - DELTA_TIME
    if "group_id" in session.ctx:
        messageIter = messageGenterator(group_id=session.ctx["group_id"],
                                        latestTime=latestTime)
    else:
        messageIter = messageGenterator(user_id=session.ctx["user_id"],
                                        latestTime=latestTime)
    wordcloud = WordcloudMaker()
    for data in messageIter:
        data: models.RecordsRead
        sentence = data.content
        wordcloud.update(sentence)
    imageData = wordcloud.save()
    return MessageSegment.image(f"base64://{b64encode(imageData).decode()}")
Beispiel #4
0
def _(session: CommandSession):
    session.send("开始获取一图")
    randomRank = random.choice(["day", "week", "month"])
    apiParse = parseMultiImage(pixiv.getRank(randomRank))
    choiceResult = random.choice(
        [data for data in apiParse["result"] if data["type"] == "illust"]
    )
    imageLinks = [i["large"] for i in choiceResult["download"]][: Config.customize.size]
    images = downloadMutliImage(imageLinks)
    messageRepeat = [str(MessageSegment.image(images[i])) for i in imageLinks]
    fullMessage = (
        str(Config.customize.rank_prefix).format(**choiceResult)
        + "\n".join(messageRepeat)
        + "\n"
        + str(Config.customize.rank_suffix).format(**choiceResult)
    )
    return fullMessage
Beispiel #5
0
def NSFWImage(session: CommandSession):
    rank: str = session.get_optional("rank", Config.send.default)
    pictureCount: int = session.get_optional("num", 1)
    pictureCount = (
        pictureCount if pictureCount <= Config.send.size else Config.send.size
    )
    session.send(f"{rank.upper()}级涩图加载中,将发送最多{pictureCount}张")
    imageInfoList: List[Dict[str, Any]] = getImageList()
    imageList: List[str] = [
        i.get("sample_url", i.get("file_url"))
        for i in imageInfoList
        if i["rating"].upper() in rank.upper()
    ]
    random.shuffle(imageList)
    images = downloadMultiImage([i for i in imageList if i][:pictureCount])
    imageSent = [str(MessageSegment.image(i)) for i in images.values()]
    return "\n".join(imageSent) + f"\n共筛选出{len(imageList)}张图片"
Beispiel #6
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"
Beispiel #7
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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
0
def _(session: CommandSession):
    session.send("开始生成统计")
    latestTime = datetime.datetime.now() - DELTA_TIME
    newestTime = _datetimeRound(datetime.datetime.now())
    frameMaker = DataFrameMaker({"date": str, "time": float})
    if "group_id" in session.ctx:
        messageIter = messageGenterator(
            group_id=session.ctx["group_id"],
            newestTime=newestTime,
            latestTime=latestTime,
        )
    else:
        messageIter = messageGenterator(user_id=session.ctx["user_id"],
                                        newestTime=newestTime,
                                        latestTime=latestTime)
    for data in messageIter:
        date = str(data.time.date())
        time = _time2Int(data.time.time())
        frameMaker.update({"date": date, "time": time})
    imageData = Chart.chatFrequency(frameMaker.read())
    return MessageSegment.image(f"base64://{b64encode(imageData).decode()}")
Beispiel #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
Beispiel #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
Beispiel #13
0
def _(session: CommandSession):
    session: CommandSession = SyncWrapper(session)
    groupID = session.ctx["group_id"]
    getSettings = PluginManager.settings(__plugin_name__, ctx=session.ctx)
    getSettings.status = False
    session.send(f"群{groupID}复读已经关闭")