-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Description
没在您代码里没有找到判断是否有人@我的功能,所以我在wechat_adapter.py添加了 GetMyName方法,用来在消息的content里获取匹配自己的名称:
app/wechat_adapter.py:
def GetMyName(self):
# 获取我的昵称 用于判断@是否是本人,虽然有可能会有重名的问题 但是概率很小 而且可以在微信名称后面加随机数来减小
if not self._instance:
raise AttributeError("微信实例未初始化")
return self._instance.core.nickname然后在app/api/routes.py 添加了/wechat/me 接口:
@api_bp.route('/wechat/me', methods=['GET'])
@require_api_key
def get_my_name():
# 获取我的昵称
wx_instance = wechat_manager.get_instance()
if not wx_instance:
return {
'response': {
'code': 2001,
'message': '微信未初始化',
'data': None
},
'status_code': 400
}
try:
me = wx_instance.GetMyName()
return jsonify({
'code': 0,
'message': '获取成功',
'data': me
})
except Exception as e:
logger.error(f"获取昵称异常: {str(e)}")
return jsonify({
'code': 2001,
'message': f'获取昵称失败: {str(e)}',
'data': None
}), 500Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels