Example #1
0
def batchSend():
    global _IMAGE_LIST_CACHE
    _IMAGE_LIST_CACHE = None
    logger.debug("Begin to start daily greeting")
    groupsList = [i["group_id"] for i in callModuleAPI("get_group_list")]
    successSend = 0
    for groupID in groupsList:

        enabled = PluginManager._getSettings(__plugin_name__,
                                             type="group",
                                             id=groupID).status
        if not enabled:
            continue
        try:
            callModuleAPI(
                "send_msg",
                params={
                    "group_id": groupID,
                    "message": timeTelling()
                },
            )
        except Exception:
            eid = ExceptionProcess.catch()
            logger.exception(
                f"Failed to greeting in group {groupID},traceback id:{eid}")
        else:
            successSend += 1
    logger.info(
        f"Daily greeting finished,total send:{len(groupsList)},success:{successSend}"
    )
Example #2
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"
Example #3
0
    def run(self):
        subscribedFeeds: List[dict] = []
        friendList: List[int] = [
            i["user_id"] for i in callModuleAPI("get_friend_list")
        ]
        groupList: List[int] = [
            i["group_id"] for i in callModuleAPI("get_group_list")
        ]
        for friend in friendList:
            for key, value in (PluginManager._getSettings(
                    pluginName=__plugin_name__, type="user",
                    id=friend).settings["subscribed"].items()):
                subscribedFeeds.append({
                    "type": "user",
                    "id": friend,
                    "address": value["link"],
                    "last_update": value["last_update"],
                    "token": key,
                })
        for group in groupList:
            for key, value in (PluginManager._getSettings(
                    pluginName=__plugin_name__, type="group",
                    id=group).settings["subscribed"].items()):
                subscribedFeeds.append({
                    "type": "group",
                    "id": group,
                    "address": value["link"],
                    "last_update": value["last_update"],
                    "token": key,
                })

        for perFeed in self._executor.map(self._getFeed, subscribedFeeds):
            feedData: dict = perFeed.get("data")
            if not feedData:
                continue
            if feedData["last_update_stamp"] <= perFeed["last_update"]:
                continue
            newFeeds = [
                i for i in feedData["content"]
                if i["published_stamp"] > perFeed["last_update"]
            ]
            feedSettings: dict = PluginManager._getSettings(
                pluginName=__plugin_name__,
                type=perFeed["type"],
                id=perFeed["id"]).settings
            feedSettings.update({
                perFeed["token"]: {
                    "link": perFeed["address"],
                    "last_update": feedData["last_update_stamp"],
                }
            })
            PluginManager._getSettings(
                pluginName=__plugin_name__,
                type=perFeed["type"],
                id=perFeed["id"]).settings = feedSettings

            repeatMessage = "\n".join([
                str(CONFIG.customize.subscribe_repeat).format(**i)
                for i in newFeeds[:CONFIG.customize.size]
            ])
            fullMessage = (
                str(CONFIG.customize.subscribe_prefix).format(**feedData) +
                f"{repeatMessage}\n" +
                str(CONFIG.customize.subscribe_suffix).format(**feedData))

            callModuleAPI(
                "send_msg",
                params={
                    "group_id": perFeed["id"],
                    "message": fullMessage
                } if perFeed["type"] == "group" else {
                    "user_id": perFeed["id"],
                    "message": fullMessage
                },
            )