调整内容

This commit is contained in:
liuwei
2025-04-22 13:43:03 +08:00
parent 978593edd1
commit da5ce935b9
3 changed files with 76 additions and 82 deletions

View File

@@ -7,6 +7,7 @@ import json
class MessageType(Enum): class MessageType(Enum):
"""消息类型枚举""" """消息类型枚举"""
UNKNOWN = 0 # 未知类型
TEXT = 1 # 文本消息 TEXT = 1 # 文本消息
IMAGE = 3 # 图片消息 IMAGE = 3 # 图片消息
VOICE = 34 # 语音消息 VOICE = 34 # 语音消息
@@ -27,13 +28,26 @@ class MessageType(Enum):
class AppMessageType(Enum): class AppMessageType(Enum):
"""应用消息类型枚举""" """应用消息类型枚举"""
UNKNOWN = 0 # 未知类型
TEXT = 1 # 文本
IMG = 2 # 图片
AUDIO = 3 # 音频
VIDEO = 4 # 视频
LINK = 5 # 链接消息 LINK = 5 # 链接消息
FILE = 6 # 文件消息 FILE = 6 # 文件
FILE_NOTICE = 74 # 文件上传通知 QUOTE = 57 # 引用
MINIPROGRAM = 33 # 小程序消息 EMOJI = 8 # 表情
QUOTE = 57 # 引用消息 LOCATION = 17 # 位置
TRANSFER = 2000 # 转账消息 APP_MSG = 33 # APP消息
RED_PACKET = 2001 # 红包消息 MINIPROGRAM = 36 # 小程序
TRANSFER = 2000 # 转账
RED_PACKET = 2001 # 红包
CARD_TICKET = 2002 # 卡券
REAL_TIME_LOCATION_START = 17 # 实时位置共享开始
REAL_TIME_LOCATION_STOP = 18 # 实时位置共享结束
CARD = 42 # 名片
VOICE_REMIND = 43 # 语音提醒
FILE_NOTICE = 74 # 文件通知
CHANNELS = 51 # 视频号消息 CHANNELS = 51 # 视频号消息
@@ -217,6 +231,20 @@ class WxMessage:
def from_group(self) -> bool: def from_group(self) -> bool:
return self.to_user.endswith("@chatroom") return self.to_user.endswith("@chatroom")
def is_at(self, wxid) -> bool:
"""是否被 @:群消息,在 @ 名单里,并且不是 @ 所有人"""
if not self.from_group():
return False # 只有群消息才能 @
if not re.findall(f"<atuserlist>[\s|\S]*({wxid})[\s|\S]*</atuserlist>", self.msg_source):
return False # 不在 @ 清单里
if re.findall(r"@(?:所有人|all|All)", self.content):
return False # 排除 @ 所有人
return True
def get_app_message_type(self) -> Optional[AppMessageType]: def get_app_message_type(self) -> Optional[AppMessageType]:
"""获取应用消息类型""" """获取应用消息类型"""
if self.msg_type != MessageType.APP or not self.content.xml_content: if self.msg_type != MessageType.APP or not self.content.xml_content:

View File

@@ -9,18 +9,12 @@ import random
from gewechat_client import GewechatClient from gewechat_client import GewechatClient
from base.func_doubao import Doubao
from base.func_epic import is_friday, get_free from base.func_epic import is_friday, get_free
from base.func_zhipu import ZhiPu
from base.func_chatgpt import ChatGPT
from base.func_news import News from base.func_news import News
from base.func_tigerbot import TigerBot
from base.func_xinghuo_web import XinghuoWeb
from base.func_claude import Claude
from configuration import Config from configuration import Config
from constants import ChatType
from gewechat.call_back_message.message import WxMessage, MessageType from gewechat.call_back_message.message import WxMessage, MessageType
from utils.json_converter import json_to_object
from utils.wechat.message_to_db import MessageStorage from utils.wechat.message_to_db import MessageStorage
from plugin_common.event_system import EventType, EventSystem from plugin_common.event_system import EventType, EventSystem
from plugin_common.message_plugin_interface import MessagePluginInterface from plugin_common.message_plugin_interface import MessagePluginInterface
@@ -56,6 +50,13 @@ class Robot(Job):
self.allContacts = self.get_all_contacts() self.allContacts = self.get_all_contacts()
self.contact_manager.set_contacts(self.allContacts) self.contact_manager.set_contacts(self.allContacts)
# 获取个人信息
obj = json_to_object(self.client.get_profile(self.app_id))
if obj.data.wxid is None:
self.LOG.info(f"获取个人信息失败,退出程序!")
return
self.wxid = obj.data.wxid
self.LOG.info(f"DB+REDIS 连接池开始初始化") self.LOG.info(f"DB+REDIS 连接池开始初始化")
# 使用单例模式获取实例 # 使用单例模式获取实例
self.db_manager = DBConnectionManager.get_instance( self.db_manager = DBConnectionManager.get_instance(
@@ -216,7 +217,7 @@ class Robot(Job):
self.message_count_to_db() self.message_count_to_db()
if msg.content == "PDF": if msg.content == "PDF":
self.generate_sehuatang_pdf() self.generate_sehuatang_pdf()
if msg.content.startswith("清除群-"): if msg.content.raw_content.startswith("清除群-"):
self.gbm.handle_command(msg.roomid, msg.content) self.gbm.handle_command(msg.roomid, msg.content)
else: else:
self.toChitchat(msg) # 闲聊 self.toChitchat(msg) # 闲聊

View File

@@ -65,56 +65,24 @@ def json_to_object(json_data):
if __name__ == "__main__": if __name__ == "__main__":
# 示例JSON数据 # 示例JSON数据
example_json = { example_json = {
"ret": 200, "ret": 200,
"msg": "操作成功", "msg": "操作成功",
"data": { "data": {
"friends": [ "wxid": "zhangchuan2288",
"tmessage", "nickName": "朝夕。",
"medianote", "mobile": "18761670817",
"qmessage", "uin": 1042679712,
"qqmail", "sex": 1,
"wxid_910acevfm2nb21", "province": "Jiangsu",
"qqsafe", "city": "Xuzhou",
"wxid_9299552988412", "signature": ".......",
"weixin", "country": "CN",
"exmail_tool", "bigHeadImgUrl": "https://wx.qlogo.cn/mmhead/ver_1/REoLX7KfdibFAgDbtoeXGNjE6sGa8NCib8UaiazlekKjuLneCvicM4xQpuEbZWjjQooSicsKEbKdhqCOCpTHWtnBqdJicJ0I3CgZumwJ6SxR3ibuNs/0",
"wxid_mp05xmje0ctn22", "smallHeadImgUrl": "https://wx.qlogo.cn/mmhead/ver_1/REoLX7KfdibFAgDbtoeXGNjE6sGa8NCib8UaiazlekKjuLneCvicM4xQpuEbZWjjQooSicsKEbKdhqCOCpTHWtnBqdJicJ0I3CgZumwJ6SxR3ibuNs/132",
"wxid_09oq4f4j4wg912", "regCountry": "CN",
"wxid_6bfguz79h8n122", "snsBgImg": "http://shmmsns.qpic.cn/mmsns/FzeKA69P5uIdqPfQxp59LvOohoE2iaiaj86IBH1jl0F76aGvg8AlU7giaMtBhQ3bPibunbhVLb3aEq4/0"
"wxid_lyuq4hr4lrjq22", }
"wxid_a1zqyljsrsdu12", }
"wxid_lv3pb3zhna3522",
"wxid_k2biq6fuinsr22",
"wxid_ujredjhxz9y712",
"wxid_uwb7989u0jea12",
"wxid_in46ey732vxu12",
"wxid_3rvervwohj6921",
"wxid_4wkls7tu62ua12",
"wxid_g0bdknnotx2f12",
"wxid_ce5fgp0icb3y21",
"wxid_1482424825211",
"wxid_vw3p4f6jy7bm12",
"wxid_o2m8xm71c23522",
"wxid_bclqpc2ho6o412",
"wxid_98pjjzpiisi721",
"wxid_noq2wsn5c8h222"
],
"chatrooms": [
"2180313478@chatroom",
"14358945067@chatroom",
"17362526147@chatroom",
"11685224357@chatroom",
"17522822550@chatroom"
],
"ghs": [
"gh_7aac992b0363",
"gh_d7293b5f14f4",
"gh_f51ce3ef83a4",
"gh_7d20df86e26b",
"gh_69bfb92a3e43"
]
}
}
# 转换为对象 # 转换为对象
obj = json_to_object(example_json) obj = json_to_object(example_json)
@@ -122,10 +90,7 @@ if __name__ == "__main__":
# 通过属性访问 # 通过属性访问
print(f"返回码: {obj.ret}") print(f"返回码: {obj.ret}")
print(f"消息: {obj.msg}") print(f"消息: {obj.msg}")
print(f"好友数量: {len(obj.data.friends)}") print(f"wxid: {obj.data.wxid}")
print(f"第一个好友: {obj.data.friends[0]}")
print(f"第一个群聊: {obj.data.chatrooms[0]}")
# 转换回字典 # 转换回字典
dict_data = obj.to_dict() dict_data = obj.to_dict()
print(f"转换回字典: {dict_data}") print(f"转换回字典: {dict_data}")