From d9ec43469993052dd416a2fbce00bccf254749a8 Mon Sep 17 00:00:00 2001 From: Moyuyanli <572490972@qq.com> Date: Tue, 11 Mar 2025 17:08:33 +0800 Subject: [PATCH 01/52] =?UTF-8?q?feat:gewe=E7=9A=84client=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20=E6=B7=BB=E5=8A=A0=E5=A5=BD=E5=8F=8B=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20feat:gewe=E7=9A=84client=E6=B7=BB=E5=8A=A0=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=BE=A4=E4=BF=A1=E6=81=AF/=E7=BE=A4?= =?UTF-8?q?=E6=88=90=E5=91=98=E6=8E=A5=E5=8F=A3=20feat:gewe=E7=9A=84client?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E6=B7=BB=E5=8A=A0=E7=BE=A4=E6=88=90?= =?UTF-8?q?=E5=91=98=E4=B8=BA=E5=A5=BD=E5=8F=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/platform/sources/gewechat/client.py | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index 7268efded..de7762b2d 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -487,3 +487,75 @@ class SimpleGewechatClient: ) as resp: json_blob = await resp.json() logger.debug(f"发送文件结果: {json_blob}") + + async def add_friend(self, v3: str, v4: str, content: str): + """申请添加好友""" + payload = { + "appId": self.appid, + "scene": 3, + "content": content, + "v4": v4, + "v3": v3, + "option": 2, + } + + async with aiohttp.ClientSession() as session: + async with session.post( + f"{self.base_url}/contacts/addContacts", + headers=self.headers, + json=payload, + ) as resp: + json_blob = await resp.json() + logger.debug(f"申请添加好友结果: {json_blob}") + return json_blob + + async def get_group(self, group_id: str): + payload = { + "appId": self.appid, + "chatroomId": group_id, + } + + async with aiohttp.ClientSession() as session: + async with session.post( + f"{self.base_url}/group/getChatroomInfo", + headers=self.headers, + json=payload, + ) as resp: + json_blob = await resp.json() + logger.debug(f"获取群信息结果: {json_blob}") + return json_blob + + async def get_group_member(self, group_id: str): + payload = { + "appId": self.appid, + "chatroomId": group_id, + } + + async with aiohttp.ClientSession() as session: + async with session.post( + f"{self.base_url}/group/getChatroomMemberList", + headers=self.headers, + json=payload, + ) as resp: + json_blob = await resp.json() + logger.debug(f"获取群信息结果: {json_blob}") + return json_blob + + + async def add_group_member_to_friend(self, group_id: str,to_wxid: str,content: str): + payload = { + "appId": self.appid, + "chatroomId": group_id, + "content": content, + "memberWxid": to_wxid + } + + async with aiohttp.ClientSession() as session: + async with session.post( + f"{self.base_url}/group/addGroupMemberAsFriend", + headers=self.headers, + json=payload, + ) as resp: + json_blob = await resp.json() + logger.debug(f"获取群信息结果: {json_blob}") + return json_blob \ No newline at end of file From 76cfc31a1d992f6bf9dea23f2f1a71d9fbb7124d Mon Sep 17 00:00:00 2001 From: Moyuyanli <572490972@qq.com> Date: Tue, 11 Mar 2025 17:10:04 +0800 Subject: [PATCH 02/52] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=20Group=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/astrbot_message.py | 48 +++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/astrbot/core/platform/astrbot_message.py b/astrbot/core/platform/astrbot_message.py index ea55eaf4b..cb399bacf 100644 --- a/astrbot/core/platform/astrbot_message.py +++ b/astrbot/core/platform/astrbot_message.py @@ -1,5 +1,5 @@ import time -from typing import List +from typing import List, Dict, Any from dataclasses import dataclass from astrbot.core.message.components import BaseMessageComponent from .message_type import MessageType @@ -10,6 +10,52 @@ class MessageMember: user_id: str # 发送者id nickname: str = None + def __str__(self): + # 使用 f-string 来构建返回的字符串表示形式 + return (f"User ID: {self.user_id}\n" + f"Nickname: {self.nickname if self.nickname else 'N/A'}") + +@dataclass +class Group: + group_id: str + group_name: str = None + + # 群头像 + group_avatar: str = None + + # 群主id + group_owner: str = None + + # 群管理员id + group_admin: str = None + + # 群成员 + members: List[MessageMember] = None + + def __str__(self): + # 使用 f-string 来构建返回的字符串表示形式 + return (f"Group ID: {self.group_id}\n" + f"Name: {self.group_name if self.group_name else 'N/A'}\n" + f"Avatar: {self.group_avatar if self.group_avatar else 'N/A'}\n" + f"Owner ID: {self.group_owner if self.group_owner else 'N/A'}\n" + f"Admin ID: {self.group_admin if self.group_admin else 'N/A'}") + + @classmethod + def from_dict(cls, data: Dict[str, Any]) -> "Group": + # 提取members信息并转换为MessageMember对象 + members = [ + MessageMember(user_id=member["wxid"], nickname=member["nickName"]) + for member in data.get("memberList", []) + ] + + return cls( + group_id=data["chatroomId"], + group_name=data.get("nickName"), + group_avatar=data.get("smallHeadImgUrl"), + group_owner=data.get("chatRoomOwner"), + members=members, + ) + class AstrBotMessage: """ From 4a8309ed1f77e6921be5bd81a63806ca0ea7ba60 Mon Sep 17 00:00:00 2001 From: Moyuyanli <572490972@qq.com> Date: Tue, 11 Mar 2025 17:10:55 +0800 Subject: [PATCH 03/52] =?UTF-8?q?style:idea=E9=BB=98=E8=AE=A4=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BA=86=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=20feat:=E6=B7=BB=E5=8A=A0=E6=A0=B9=E6=8D=AE=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E8=8E=B7=E5=8F=96=E7=BE=A4=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/astr_message_event.py | 75 +++++++++++++++------ 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/astrbot/core/platform/astr_message_event.py b/astrbot/core/platform/astr_message_event.py index 72e4414b6..a85ec0b9b 100644 --- a/astrbot/core/platform/astr_message_event.py +++ b/astrbot/core/platform/astr_message_event.py @@ -1,11 +1,9 @@ import abc import asyncio from dataclasses import dataclass -from .astrbot_message import AstrBotMessage -from .platform_metadata import PlatformMetadata -from astrbot.core.message.message_event_result import MessageEventResult, MessageChain -from astrbot.core.platform.message_type import MessageType -from typing import List, Union +from typing import List, Union, Optional + +from astrbot.core.db.po import Conversation from astrbot.core.message.components import ( Plain, Image, @@ -15,9 +13,12 @@ from astrbot.core.message.components import ( AtAll, Forward, ) -from astrbot.core.utils.metrics import Metric +from astrbot.core.message.message_event_result import MessageEventResult, MessageChain +from astrbot.core.platform.message_type import MessageType from astrbot.core.provider.entites import ProviderRequest -from astrbot.core.db.po import Conversation +from astrbot.core.utils.metrics import Metric +from .astrbot_message import AstrBotMessage, Group +from .platform_metadata import PlatformMetadata @dataclass @@ -37,11 +38,11 @@ class MessageSesion: class AstrMessageEvent(abc.ABC): def __init__( - self, - message_str: str, - message_obj: AstrBotMessage, - platform_meta: PlatformMetadata, - session_id: str, + self, + message_str: str, + message_obj: AstrBotMessage, + platform_meta: PlatformMetadata, + session_id: str, ): self.message_str = message_str """纯文本的消息""" @@ -320,14 +321,14 @@ class AstrMessageEvent(abc.ABC): """LLM 请求相关""" def request_llm( - self, - prompt: str, - func_tool_manager=None, - session_id: str = None, - image_urls: List[str] = [], - contexts: List = [], - system_prompt: str = "", - conversation: Conversation = None, + self, + prompt: str, + func_tool_manager=None, + session_id: str = None, + image_urls: List[str] = [], + contexts: List = [], + system_prompt: str = "", + conversation: Conversation = None, ) -> ProviderRequest: """ 创建一个 LLM 请求。 @@ -363,3 +364,37 @@ class AstrMessageEvent(abc.ABC): system_prompt=system_prompt, conversation=conversation, ) + + async def get_group(self, group_id: str = None) -> Optional[Group]: + """ + 获取群聊,如果不填写group_id,且消息是私聊消息,则返回 None + 目前只实现了 GeweChat 协议 + """ + # 确定有效的 group_id + if group_id is None: + group_id = self.message_obj.group_id + + if group_id is None: + return None + + # 检查平台是否为 gewechat + if self.platform_meta.name != "gewechat": + return None + + from astrbot.core.platform.sources.gewechat.gewechat_event import ( + GewechatPlatformEvent, + ) + + assert isinstance(self, GewechatPlatformEvent) + client = self.client + + # 从客户端获取群信息 + res = await client.get_group(group_id) + + data = res["data"] + + # 检查 chatroomId 是否为空 + if data["chatroomId"] == "": + return None + + return Group.from_dict(data) From 00f5189f58cab395512ec670f21d7d395d3fc1ad Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 Mar 2025 09:16:43 +0000 Subject: [PATCH 04/52] :balloon: auto fixes by pre-commit hooks --- astrbot/core/platform/astr_message_event.py | 26 +++++++++---------- astrbot/core/platform/astrbot_message.py | 19 +++++++++----- .../core/platform/sources/gewechat/client.py | 9 ++++--- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/astrbot/core/platform/astr_message_event.py b/astrbot/core/platform/astr_message_event.py index a85ec0b9b..02d600768 100644 --- a/astrbot/core/platform/astr_message_event.py +++ b/astrbot/core/platform/astr_message_event.py @@ -38,11 +38,11 @@ class MessageSesion: class AstrMessageEvent(abc.ABC): def __init__( - self, - message_str: str, - message_obj: AstrBotMessage, - platform_meta: PlatformMetadata, - session_id: str, + self, + message_str: str, + message_obj: AstrBotMessage, + platform_meta: PlatformMetadata, + session_id: str, ): self.message_str = message_str """纯文本的消息""" @@ -321,14 +321,14 @@ class AstrMessageEvent(abc.ABC): """LLM 请求相关""" def request_llm( - self, - prompt: str, - func_tool_manager=None, - session_id: str = None, - image_urls: List[str] = [], - contexts: List = [], - system_prompt: str = "", - conversation: Conversation = None, + self, + prompt: str, + func_tool_manager=None, + session_id: str = None, + image_urls: List[str] = [], + contexts: List = [], + system_prompt: str = "", + conversation: Conversation = None, ) -> ProviderRequest: """ 创建一个 LLM 请求。 diff --git a/astrbot/core/platform/astrbot_message.py b/astrbot/core/platform/astrbot_message.py index cb399bacf..be49ba18e 100644 --- a/astrbot/core/platform/astrbot_message.py +++ b/astrbot/core/platform/astrbot_message.py @@ -12,8 +12,11 @@ class MessageMember: def __str__(self): # 使用 f-string 来构建返回的字符串表示形式 - return (f"User ID: {self.user_id}\n" - f"Nickname: {self.nickname if self.nickname else 'N/A'}") + return ( + f"User ID: {self.user_id}\n" + f"Nickname: {self.nickname if self.nickname else 'N/A'}" + ) + @dataclass class Group: @@ -34,11 +37,13 @@ class Group: def __str__(self): # 使用 f-string 来构建返回的字符串表示形式 - return (f"Group ID: {self.group_id}\n" - f"Name: {self.group_name if self.group_name else 'N/A'}\n" - f"Avatar: {self.group_avatar if self.group_avatar else 'N/A'}\n" - f"Owner ID: {self.group_owner if self.group_owner else 'N/A'}\n" - f"Admin ID: {self.group_admin if self.group_admin else 'N/A'}") + return ( + f"Group ID: {self.group_id}\n" + f"Name: {self.group_name if self.group_name else 'N/A'}\n" + f"Avatar: {self.group_avatar if self.group_avatar else 'N/A'}\n" + f"Owner ID: {self.group_owner if self.group_owner else 'N/A'}\n" + f"Admin ID: {self.group_admin if self.group_admin else 'N/A'}" + ) @classmethod def from_dict(cls, data: Dict[str, Any]) -> "Group": diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index de7762b2d..6c7bd0a23 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -541,13 +541,14 @@ class SimpleGewechatClient: logger.debug(f"获取群信息结果: {json_blob}") return json_blob - - async def add_group_member_to_friend(self, group_id: str,to_wxid: str,content: str): + async def add_group_member_to_friend( + self, group_id: str, to_wxid: str, content: str + ): payload = { "appId": self.appid, "chatroomId": group_id, "content": content, - "memberWxid": to_wxid + "memberWxid": to_wxid, } async with aiohttp.ClientSession() as session: @@ -558,4 +559,4 @@ class SimpleGewechatClient: ) as resp: json_blob = await resp.json() logger.debug(f"获取群信息结果: {json_blob}") - return json_blob \ No newline at end of file + return json_blob From d177b9f7fab89678d479888603034ec8f6591816 Mon Sep 17 00:00:00 2001 From: Moyuyanli <572490972@qq.com> Date: Fri, 14 Mar 2025 17:11:10 +0800 Subject: [PATCH 05/52] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E4=B8=BB=E5=8A=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A5=BD=E5=8F=8B=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../core/platform/sources/gewechat/client.py | 155 +++++++++++------- requirements.txt | 44 ++--- 3 files changed, 124 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index a863e36ec..4b683ee8b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ venv/* packages/python_interpreter/workplace .venv/* .conda/ +.idea \ No newline at end of file diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index 6c7bd0a23..985185b12 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -1,17 +1,19 @@ -import threading import asyncio -import aiohttp -import quart import base64 import datetime -import re import os +import re +import threading + +import aiohttp import anyio -from astrbot.api.platform import AstrBotMessage, MessageMember, MessageType -from astrbot.api.message_components import Plain, Image, At, Record +import quart + from astrbot.api import logger, sp -from .downloader import GeweDownloader +from astrbot.api.message_components import Plain, Image, At, Record +from astrbot.api.platform import AstrBotMessage, MessageMember, MessageType from astrbot.core.utils.io import download_image_by_url +from .downloader import GeweDownloader class SimpleGewechatClient: @@ -22,12 +24,12 @@ class SimpleGewechatClient: """ def __init__( - self, - base_url: str, - nickname: str, - host: str, - port: int, - event_queue: asyncio.Queue, + self, + base_url: str, + nickname: str, + host: str, + port: int, + event_queue: asyncio.Queue, ): self.base_url = base_url if self.base_url.endswith("/"): @@ -137,8 +139,8 @@ class SimpleGewechatClient: # at msg_source = d["MsgSource"] if ( - f"" in msg_source - or f"" in msg_source + f"" in msg_source + or f"" in msg_source ): at_me = True if "在群聊中@了你" in d.get("PushContent", ""): @@ -155,8 +157,8 @@ class SimpleGewechatClient: user_real_name = "unknown" if abm.group_id: if ( - abm.group_id not in self.userrealnames - or user_id not in self.userrealnames[abm.group_id] + abm.group_id not in self.userrealnames + or user_id not in self.userrealnames[abm.group_id] ): # 获取群成员列表,并且缓存 if abm.group_id not in self.userrealnames: @@ -250,9 +252,9 @@ class SimpleGewechatClient: await asyncio.sleep(3) async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/tools/setCallback", - headers=self.headers, - json={"token": self.token, "callbackUrl": self.callback_url}, + f"{self.base_url}/tools/setCallback", + headers=self.headers, + json={"token": self.token, "callbackUrl": self.callback_url}, ) as resp: json_blob = await resp.json() logger.info(f"设置回调结果: {json_blob}") @@ -280,9 +282,9 @@ class SimpleGewechatClient: # /login/checkOnline async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/login/checkOnline", - headers=self.headers, - json={"appId": appid}, + f"{self.base_url}/login/checkOnline", + headers=self.headers, + json={"appId": appid}, ) as resp: json_blob = await resp.json() return json_blob["data"] @@ -293,9 +295,9 @@ class SimpleGewechatClient: if online: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/login/logout", - headers=self.headers, - json={"appId": self.appid}, + f"{self.base_url}/login/logout", + headers=self.headers, + json={"appId": self.appid}, ) as resp: json_blob = await resp.json() logger.info(f"登出结果: {json_blob}") @@ -327,9 +329,9 @@ class SimpleGewechatClient: try: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/login/getLoginQrCode", - headers=self.headers, - json=payload, + f"{self.base_url}/login/getLoginQrCode", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() if json_blob["ret"] != 200: @@ -378,9 +380,9 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/login/checkLogin", - headers=self.headers, - json=payload, + f"{self.base_url}/login/checkLogin", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.info(f"检查登录状态: {json_blob}") @@ -419,9 +421,9 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/group/getChatroomMemberList", - headers=self.headers, - json=payload, + f"{self.base_url}/group/getChatroomMemberList", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() return json_blob["data"] @@ -437,7 +439,7 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/message/postText", headers=self.headers, json=payload + f"{self.base_url}/message/postText", headers=self.headers, json=payload ) as resp: json_blob = await resp.json() logger.debug(f"发送消息结果: {json_blob}") @@ -451,7 +453,7 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/message/postImage", headers=self.headers, json=payload + f"{self.base_url}/message/postImage", headers=self.headers, json=payload ) as resp: json_blob = await resp.json() logger.debug(f"发送图片结果: {json_blob}") @@ -468,7 +470,7 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/message/postVoice", headers=self.headers, json=payload + f"{self.base_url}/message/postVoice", headers=self.headers, json=payload ) as resp: json_blob = await resp.json() logger.debug(f"发送语音结果: {json_blob}") @@ -483,7 +485,7 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/message/postFile", headers=self.headers, json=payload + f"{self.base_url}/message/postFile", headers=self.headers, json=payload ) as resp: json_blob = await resp.json() logger.debug(f"发送文件结果: {json_blob}") @@ -501,9 +503,9 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/contacts/addContacts", - headers=self.headers, - json=payload, + f"{self.base_url}/contacts/addContacts", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"申请添加好友结果: {json_blob}") @@ -517,9 +519,9 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/group/getChatroomInfo", - headers=self.headers, - json=payload, + f"{self.base_url}/group/getChatroomInfo", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"获取群信息结果: {json_blob}") @@ -533,29 +535,68 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/group/getChatroomMemberList", - headers=self.headers, - json=payload, + f"{self.base_url}/group/getChatroomMemberList", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"获取群信息结果: {json_blob}") return json_blob - async def add_group_member_to_friend( - self, group_id: str, to_wxid: str, content: str - ): + async def accept_group_invite(self, url: str): + """同意进群""" payload = { "appId": self.appid, - "chatroomId": group_id, - "content": content, - "memberWxid": to_wxid, + "url": url } async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/group/addGroupMemberAsFriend", - headers=self.headers, - json=payload, + f"{self.base_url}/group/agreeJoinRoom", + headers=self.headers, + json=payload, + ) as resp: + json_blob = await resp.json() + logger.debug(f"获取群信息结果: {json_blob}") + return json_blob + + async def add_group_member_to_friend(self, group_id: str, to_wxid: str, content: str): + payload = { + "appId": self.appid, + "chatroomId": group_id, + "content": content, + "memberWxid": to_wxid + } + + async with aiohttp.ClientSession() as session: + async with session.post( + f"{self.base_url}/group/addGroupMemberAsFriend", + headers=self.headers, + json=payload, + ) as resp: + json_blob = await resp.json() + logger.debug(f"获取群信息结果: {json_blob}") + return json_blob + + async def get_user_or_group_info(self, *ids): + """ + 获取用户或群组信息。 + + :param ids: 可变数量的 wxid 参数 + """ + + wxids_str = list(ids) + + payload = { + "appId": self.appid, + "wxids": wxids_str # 使用逗号分隔的字符串 + } + + async with aiohttp.ClientSession() as session: + async with session.post( + f"{self.base_url}/contacts/getDetailInfo", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"获取群信息结果: {json_blob}") diff --git a/requirements.txt b/requirements.txt index 07b168cc1..ac56e3db4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,27 +1,33 @@ pydantic~=2.10.3 -aiohttp -openai -anthropic +aiohttp~=3.11.13 +openai~=1.65.5 +anthropic~=0.49.0 qq-botpy chardet~=5.1.0 -Pillow -beautifulsoup4 +Pillow~=11.1.0 +beautifulsoup4~=4.13.3 googlesearch-python -readability-lxml -quart +readability-lxml~=0.8.1 +quart~=0.20.0 lxml_html_clean -colorlog -aiocqhttp -pyjwt -apscheduler -docstring_parser -aiodocker +colorlog~=6.9.0 +aiocqhttp~=1.4.4 +pyjwt~=2.10.1 +apscheduler~=3.11.0 +docstring_parser~=0.16 +aiodocker~=0.24.0 silk-python psutil>=5.8.0 lark-oapi -ormsgpack -cryptography -dashscope -python-telegram-bot -wechatpy -dingtalk-stream \ No newline at end of file +ormsgpack~=1.8.0 +cryptography~=44.0.2 +dashscope~=1.22.2 +python-telegram-bot~=21.11.1 +wechatpy~=1.8.18 +dingtalk-stream +PyYAML~=6.0.2 +pip~=23.2.1 +typing_extensions~=4.12.2 +requests~=2.32.3 +anyio~=4.8.0 +httpx~=0.28.1 \ No newline at end of file From c95682a0c7f5a8e5d3802d0ebc56edb8b19739dc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Mar 2025 09:11:21 +0000 Subject: [PATCH 06/52] :balloon: auto fixes by pre-commit hooks --- .../core/platform/sources/gewechat/client.py | 119 +++++++++--------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index 985185b12..abaf1a877 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -24,12 +24,12 @@ class SimpleGewechatClient: """ def __init__( - self, - base_url: str, - nickname: str, - host: str, - port: int, - event_queue: asyncio.Queue, + self, + base_url: str, + nickname: str, + host: str, + port: int, + event_queue: asyncio.Queue, ): self.base_url = base_url if self.base_url.endswith("/"): @@ -139,8 +139,8 @@ class SimpleGewechatClient: # at msg_source = d["MsgSource"] if ( - f"" in msg_source - or f"" in msg_source + f"" in msg_source + or f"" in msg_source ): at_me = True if "在群聊中@了你" in d.get("PushContent", ""): @@ -157,8 +157,8 @@ class SimpleGewechatClient: user_real_name = "unknown" if abm.group_id: if ( - abm.group_id not in self.userrealnames - or user_id not in self.userrealnames[abm.group_id] + abm.group_id not in self.userrealnames + or user_id not in self.userrealnames[abm.group_id] ): # 获取群成员列表,并且缓存 if abm.group_id not in self.userrealnames: @@ -252,9 +252,9 @@ class SimpleGewechatClient: await asyncio.sleep(3) async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/tools/setCallback", - headers=self.headers, - json={"token": self.token, "callbackUrl": self.callback_url}, + f"{self.base_url}/tools/setCallback", + headers=self.headers, + json={"token": self.token, "callbackUrl": self.callback_url}, ) as resp: json_blob = await resp.json() logger.info(f"设置回调结果: {json_blob}") @@ -282,9 +282,9 @@ class SimpleGewechatClient: # /login/checkOnline async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/login/checkOnline", - headers=self.headers, - json={"appId": appid}, + f"{self.base_url}/login/checkOnline", + headers=self.headers, + json={"appId": appid}, ) as resp: json_blob = await resp.json() return json_blob["data"] @@ -295,9 +295,9 @@ class SimpleGewechatClient: if online: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/login/logout", - headers=self.headers, - json={"appId": self.appid}, + f"{self.base_url}/login/logout", + headers=self.headers, + json={"appId": self.appid}, ) as resp: json_blob = await resp.json() logger.info(f"登出结果: {json_blob}") @@ -329,9 +329,9 @@ class SimpleGewechatClient: try: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/login/getLoginQrCode", - headers=self.headers, - json=payload, + f"{self.base_url}/login/getLoginQrCode", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() if json_blob["ret"] != 200: @@ -380,9 +380,9 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/login/checkLogin", - headers=self.headers, - json=payload, + f"{self.base_url}/login/checkLogin", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.info(f"检查登录状态: {json_blob}") @@ -421,9 +421,9 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/group/getChatroomMemberList", - headers=self.headers, - json=payload, + f"{self.base_url}/group/getChatroomMemberList", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() return json_blob["data"] @@ -439,7 +439,7 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/message/postText", headers=self.headers, json=payload + f"{self.base_url}/message/postText", headers=self.headers, json=payload ) as resp: json_blob = await resp.json() logger.debug(f"发送消息结果: {json_blob}") @@ -453,7 +453,7 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/message/postImage", headers=self.headers, json=payload + f"{self.base_url}/message/postImage", headers=self.headers, json=payload ) as resp: json_blob = await resp.json() logger.debug(f"发送图片结果: {json_blob}") @@ -470,7 +470,7 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/message/postVoice", headers=self.headers, json=payload + f"{self.base_url}/message/postVoice", headers=self.headers, json=payload ) as resp: json_blob = await resp.json() logger.debug(f"发送语音结果: {json_blob}") @@ -485,7 +485,7 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/message/postFile", headers=self.headers, json=payload + f"{self.base_url}/message/postFile", headers=self.headers, json=payload ) as resp: json_blob = await resp.json() logger.debug(f"发送文件结果: {json_blob}") @@ -503,9 +503,9 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/contacts/addContacts", - headers=self.headers, - json=payload, + f"{self.base_url}/contacts/addContacts", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"申请添加好友结果: {json_blob}") @@ -519,9 +519,9 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/group/getChatroomInfo", - headers=self.headers, - json=payload, + f"{self.base_url}/group/getChatroomInfo", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"获取群信息结果: {json_blob}") @@ -535,9 +535,9 @@ class SimpleGewechatClient: async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/group/getChatroomMemberList", - headers=self.headers, - json=payload, + f"{self.base_url}/group/getChatroomMemberList", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"获取群信息结果: {json_blob}") @@ -545,34 +545,33 @@ class SimpleGewechatClient: async def accept_group_invite(self, url: str): """同意进群""" - payload = { - "appId": self.appid, - "url": url - } + payload = {"appId": self.appid, "url": url} async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/group/agreeJoinRoom", - headers=self.headers, - json=payload, + f"{self.base_url}/group/agreeJoinRoom", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"获取群信息结果: {json_blob}") return json_blob - async def add_group_member_to_friend(self, group_id: str, to_wxid: str, content: str): + async def add_group_member_to_friend( + self, group_id: str, to_wxid: str, content: str + ): payload = { "appId": self.appid, "chatroomId": group_id, "content": content, - "memberWxid": to_wxid + "memberWxid": to_wxid, } async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/group/addGroupMemberAsFriend", - headers=self.headers, - json=payload, + f"{self.base_url}/group/addGroupMemberAsFriend", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"获取群信息结果: {json_blob}") @@ -580,23 +579,23 @@ class SimpleGewechatClient: async def get_user_or_group_info(self, *ids): """ - 获取用户或群组信息。 + 获取用户或群组信息。 - :param ids: 可变数量的 wxid 参数 - """ + :param ids: 可变数量的 wxid 参数 + """ wxids_str = list(ids) payload = { "appId": self.appid, - "wxids": wxids_str # 使用逗号分隔的字符串 + "wxids": wxids_str, # 使用逗号分隔的字符串 } async with aiohttp.ClientSession() as session: async with session.post( - f"{self.base_url}/contacts/getDetailInfo", - headers=self.headers, - json=payload, + f"{self.base_url}/contacts/getDetailInfo", + headers=self.headers, + json=payload, ) as resp: json_blob = await resp.json() logger.debug(f"获取群信息结果: {json_blob}") From 135dbb8f07e3af4e11d7c400da6c18ba289461fd Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 14 Mar 2025 18:01:52 +0800 Subject: [PATCH 07/52] style: clean codes --- dashboard/src/components/shared/AstrBotConfig.vue | 7 ++++--- dashboard/src/components/shared/ExtensionCard.vue | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dashboard/src/components/shared/AstrBotConfig.vue b/dashboard/src/components/shared/AstrBotConfig.vue index cc39f7ff0..39d5812dc 100644 --- a/dashboard/src/components/shared/AstrBotConfig.vue +++ b/dashboard/src/components/shared/AstrBotConfig.vue @@ -1,10 +1,10 @@