SnapdragonLee / ChatGPT-weBot

Chat with ChatGPT (gpt-3.5 or newer),WeChat hook interface based
655 stars 117 forks source link

群访问加用户名 #64

Closed dvdco closed 9 months ago

dvdco commented 1 year ago

我正在尝试修改源码,如果在群里的话,每个用户给出的信息会以“他的昵称:”开头,原版似乎没有这种处理,直接视为输入。 我现在只可以做到以“微信号:”开头。如果要实现上述功能请问我该怎么做?

SnapdragonLee commented 1 year ago

昵称没有办法,注入的ddl有bug,这也是为什么群聊回复不能@的原因

nulshell commented 1 year ago

之前我参考过hook client里面的例子改过源码,是可以获得群里的昵称的,加下面的就行:

-http-

def send(uri, data): base_data={ 'id':getid(), 'type':'null', 'roomid':'null', 'wxid':'null', 'content':'null', 'nickname':'null', 'ext':'null', } base_data.update(data) url=f'http://{server_host}/{uri}' res=requests.post(url,json={'para':base_data},timeout=5) return res.json()

def get_member_nick(roomid, wxid):

获取指定群的成员的昵称 或 微信好友的昵称

uri='api/getmembernick'
data={
    'type':CHATROOM_MEMBER_NICK,
    'wxid':wxid,
    'roomid':roomid or 'null'
}
respJson=send(uri,data)
return json.loads(respJson['content'])['nick']

如果是room,就获取一下昵称 nickname=get_member_nick(room_id, wx_id),然后获得答案后可以用 ws.send(send_at_msg(wx_id, room_id, content=reply.strip(), nickname=nickname)) @昵称 发给相应的人的。

SnapdragonLee commented 1 year ago

貌似这个有bug,因为我之前有的id可以获得昵称 有的就不行很怪

SnapdragonLee commented 9 months ago

这个问题暂时关闭,新版SDK的msg中直接支持微信号开头的输入,也支持在群聊里@别人