File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,26 @@ class Client {
105105 if ( hc . cmd == "info" && hc . type == "whisper" && typeof hc . from == "string" ) {
106106 hc . nick = hc . from ;
107107 hc . msg = hc . text . substring ( hc . from . length + 12 ) ;
108+ hc . cmd = hc . type ;
109+ delete hc . type ;
110+ }
111+ if ( hc . cmd == "info" && / ^ ( [ a - z A - Z 0 - 9 _ ] { 1 , 24 } ) i n v i t e d y o u t o / . test ( hc . text ) ) {
112+ let inv = hc . text . match ( / ^ ( [ a - z A - Z 0 - 9 _ ] { 1 , 24 } ) i n v i t e d y o u t o / ) ;
113+ return this . onmessage (
114+ event . data ,
115+ {
116+ cmd : 'invite' ,
117+ nick : inv [ 1 ] ,
118+ to : hc . text . substring ( inv [ 1 ] . length + 17 )
119+ }
120+ )
121+ }
122+ if ( hc . cmd == "updateMessage" ) {
123+ let updateBy = this . users . find ( ( user ) => {
124+ return user . userid == hc . userid ;
125+ } )
126+ hc . nick = updateBy . nick ;
127+ hc . trip = updateBy . trip ;
108128 }
109129 this . onmessage ( event . data , hc ) ;
110130 }
@@ -177,6 +197,14 @@ class Client {
177197 return user . nick == nick ;
178198 } )
179199 }
200+ invite ( nick , to ) {
201+ let pack = {
202+ cmd : 'invite' ,
203+ nick : nick
204+ }
205+ if ( to ) pack . to = to ;
206+ this . _send ( pack ) ;
207+ }
180208 whisper ( to , text ) {
181209 this . _send ( {
182210 cmd : 'whisper' ,
Original file line number Diff line number Diff line change @@ -3,12 +3,11 @@ let client = new Client("wss://hack.chat/chat-ws");
33let join_channel = "your-channel" ;
44
55client . onjoin = ( ) => {
6- client . join ( { //发送加入数据包
6+ client . join ( {
77 channel : join_channel ,
88 nick : 'my_bot' ,
99 password : '123456'
1010 } )
11- //也可以读取 client.joined 判断有没有加入频道
1211}
1312
1413client . onmessage = ( raw , json ) => {
@@ -26,4 +25,10 @@ client.onjoined = () => {
2625}
2726
2827client . ping = 10000 ;
28+ client . onchangechannel = ( channel ) => {
29+ client . close ( "被踢出或者移动到了" + channel ) ;
30+ }
2931
32+ client . onclose = ( reason ) => {
33+ console . log ( `连接断开` , reason )
34+ }
You can’t perform that action at this time.
0 commit comments