@@ -15,10 +15,6 @@ def __init__(self , ip : str = "0.0.0.0" , port : int = 23456):
1515 self .ip = ip
1616 self .port = port
1717 self .api = Api ()
18- #StartHook
19- print (self .StartMsgHook (port = port ))
20- print (self .StartImageHook (save_path = "" ))
21- print (self .StartVoiceHook (save_path = "" ))
2218
2319 self .url = "http://{}:{}/" .format (ip , port )
2420
@@ -30,13 +26,25 @@ def deco(func: Callable) -> Callable:
3026 return deco
3127
3228 def run (self , main_thread : bool = True ):
33- def receive_callback (data ):
34- return self .post (data )
35-
29+ #StartHook
30+ self .StartMsgHook (port = self .port )
31+ self .StartImageHook (save_path = "" )
32+ self .StartVoiceHook (save_path = "" )
33+
3634 class ReceiveMsgSocketServer (socketserver .BaseRequestHandler ):
3735 def __init__ (self , * args , ** kwargs ):
3836 super ().__init__ (* args , ** kwargs )
3937
38+ def receive_callback (msg ):
39+ if 1 == msg ["isSendMsg" ]:
40+ Bus .emit ("self_msg" , msg )
41+ elif "chatroom" in msg ["sender" ]:
42+ Bus .emit ("group_msg" , msg )
43+ elif "gh" in msg ["sender" ]:
44+ Bus .emit ("public_msg" , msg )
45+ else :
46+ Bus .emit ("friend_msg" , msg )
47+
4048 def handle (self ):
4149 conn = self .request
4250 while True :
@@ -49,14 +57,7 @@ def handle(self):
4957 conn .sendall ("200 OK" .encode ())
5058 break
5159 msg = json .loads (ptr_data .decode ('utf-8' ))
52-
53- if 1 == msg ["isSendMsg" ]:
54- Bus .emit ("self_msg" , msg )
55- elif "chatroom" in msg ["sender" ]:
56- Bus .emit ("group_msg" , msg )
57- else :
58- Bus .emit ("friend_msg" , msg )
59-
60+ receive_callback (msg )
6061 except OSError :
6162 break
6263 except json .JSONDecodeError :
@@ -79,10 +80,6 @@ def handle(self):
7980 print (e )
8081 return None
8182
82- # on_friend_msg = on("friend_msg")
83- # on_group_msg = on("group_msg")
84- # on_self_msg = on("self_msg")
85-
8683 def __getattr__ (self , item : str ):
8784 return self .api .exec_command (item )
8885
0 commit comments