Skip to content

Commit 511c3fe

Browse files
committed
version v1.20.1
1 parent c835815 commit 511c3fe

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

basic/task.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import websocket
99

1010
from shared.shared import *
11-
from services.ChatGPTAPI import ChatbotError
11+
from services.chat.ChatGPTAPI import ChatbotError
1212
from .send import send_txt_msg, send_pic_msg
1313

1414
global_dict = dict()
@@ -73,7 +73,7 @@ def play(self):
7373

7474
print("reply: " + self.reply)
7575
if self.is_citation:
76-
self.reply = (self.bot.prev_question[-1] if self.type == "rg" else (
76+
self.reply = (self.bot.prev_question[-1][0] if self.type == "rg" else (
7777
"用150字内总结全部对话" if self.type == "z" else self.prompt)) + "\n- - - - - - - - - -\n" + self.reply.strip()
7878
self.ws.send(send_txt_msg(self.room_id if self.is_room else self.wx_id, self.reply.strip()))
7979

client/handle.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from basic.task import *
44
from multithread.threads import *
5-
from services.ChatGPTAPI import Chatbot
5+
from services.model import Selfinfo
6+
from services.chat.ChatGPTAPI import Chatbot
67

7-
global ws
8+
ws: websocket.WebSocketApp
9+
my_info: Selfinfo
810

911

1012
def handle_response(ws_t, j: json):
@@ -68,7 +70,7 @@ def handle_response(ws_t, j: json):
6870
GET_CHATROOM_INFO: print,
6971
GET_CHATROOM_MEMBER: hanle_memberlist,
7072
CHECK_LOGIN: print,
71-
CHECK_SELF_INFO: print,
73+
CHECK_SELF_INFO: handle_self_info,
7274
CHECK_DB_INFO: print,
7375
CHECK_PERSON_INFO: print,
7476
EXEC_SQL: print,
@@ -114,7 +116,10 @@ def handle_wxuser_list(j):
114116
def handle_recv_txt_msg(j):
115117
print(j)
116118

117-
wx_id = j['fromUser']
119+
if j['fromUser'] == my_info.wx_id:
120+
wx_id = j['toUser']
121+
else:
122+
wx_id = j['fromUser']
118123
room_id = ''
119124
content: str = j['content'].strip()
120125

@@ -123,18 +128,16 @@ def handle_recv_txt_msg(j):
123128
chatbot: Chatbot
124129

125130
if len(wx_id) < 9 or wx_id[-9] != '@':
126-
if len(j['toUser']) == 20:
127-
is_room = True
128-
room_id = j['toUser']
129-
else:
130-
is_room = False
131-
131+
is_room = False
132132
else:
133133
is_room = True
134134
room_id = wx_id
135135
pos = content.find(':\n', 0)
136-
wx_id = content[:pos]
137-
content = content[pos + 2:].lstrip()
136+
if pos != -1:
137+
wx_id = content[:pos]
138+
content = content[pos + 2:].lstrip()
139+
else:
140+
wx_id = my_info.wx_id
138141

139142
chatbot = global_dict.get((wx_id, room_id))
140143

@@ -238,3 +241,12 @@ def handle_recv_pic_msg(j):
238241

239242
def handle_recv_xml_txt(j):
240243
print(j)
244+
245+
246+
def handle_self_info(j):
247+
print(j)
248+
data = j["data"]
249+
250+
global my_info
251+
my_info = Selfinfo(data["wxid"], data["name"], data["account"], data["currentDataPath"], data["dataSavePath"],
252+
data["dbKey"])

client/wxclient.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
from basic.get import *
34
from basic.task import *
45
from multithread.threads import *
56
from .handle import handle_response
@@ -9,7 +10,7 @@
910

1011

1112
def on_open(ws):
12-
# ws.send(send_pic_msg(wx_id='filehelper', room_id='', content=''))
13+
ws.send(get_self_info())
1314
# ws.send(send_wxuser_list())
1415
# ws.send(get_chatroom_memberlist())
1516

@@ -45,7 +46,7 @@ def on_error(ws, error):
4546

4647
def on_close(ws, close_status_code, close_msg):
4748
for key, value in global_dict.items():
48-
print('clear conversation:' + key)
49+
print('clear conversation:' + str(key))
4950
del value
5051

5152
print(f'WebSocket closed with status code: 0')
File renamed without changes.

services/model.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Selfinfo:
2+
def __init__(self, wxid, name, account_id, data_path, save_path, db_key):
3+
self.wx_id = wxid
4+
self.wx_idname = name
5+
self.wx_idaccount_id = account_id
6+
self.wx_iddata_path = data_path
7+
self.wx_idsave_path = save_path
8+
self.wx_iddb_key = db_key

0 commit comments

Comments
 (0)