Beispiel #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}"
    )
Beispiel #2
0
def saveDetail():
    logger.info("Refreshing detail of users and groups.")
    groupList: List[Dict[str, Any]] = callModuleAPI("get_group_list")
    groupData: Dict[int, Dict[str, Any]] = {}
    usersData: Dict[int, List[Dict[str, Any]]] = {}
    for group in groupList:
        groupID: int = group["group_id"]
        groupName: str = group["group_name"]
        data = callModuleAPI("get_group_member_list",
                             params={"group_id": groupID},
                             ignoreError=True)
        if not data:
            continue
        groupData[groupID] = data
        DatabaseIO.groupCreate(models.Groups(gid=groupID,
                                             name=groupName,
                                             members=data),
                               updateIfExist=True)
        for user in data:
            userID: int = user["user_id"]
            userGroups = usersData.get(userID, [])
            for i in userGroups:
                if i["group_id"] == groupID:
                    userGroups.remove(i)
            userGroups.append(user)
            usersData[userID] = userGroups
    for userID, user in usersData.items():
        DatabaseIO.userCreate(
            models.Users(uid=userID, nickname=user[0]["nickname"], data=user),
            updateIfExist=True,
        )
Beispiel #3
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 #4
0
def _(session: CommandSession):
    banID = extract_numbers(session.current_arg_text)
    groupUsers = [
        i["user_id"]
        for i in callModuleAPI("get_group_member_list",
                               params={"group_id": session.event.group_id})
    ]
    banID = [*set([int(i) for i in banID]).intersection({*groupUsers})]
    if not banID:
        session.pause("请输入被拉黑者的QQ")
    nowBlacklist: list = PluginManager.settings(__plugin_name__,
                                                session.event).settings
    nowBlacklist.extend(map(int, banID))
    PluginManager.settings(__plugin_name__,
                           session.event).settings = [*set(nowBlacklist)]
    return "已经为" + "".join(map(lambda x: str(MessageSegment.at(x)),
                               banID)) + "添加黑名单"
Beispiel #5
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
                },
            )