@@ -126,12 +126,27 @@ class Client {
126126 hc . nick = updateBy . nick ;
127127 hc . trip = updateBy . trip ;
128128 }
129+ if ( this . cmdstart !== false ) {
130+ let originText = hc . text ;
131+ if ( hc . cmd == "whisper" ) originText = hc . msg ; //前面有扩展;
132+ if ( originText . startsWith ( this . cmdstart ) ) {
133+ let originCmd = originText . substring ( this . cmdstart . length ) . split ( " " ) ;
134+ let runcmd = originCmd . shift ( ) ;
135+ this . _COMMAND (
136+ runcmd ,
137+ originCmd ,
138+ this . selNick ( hc . nick ) ,
139+ hc . cmd == "whisper" ?( text , e = false ) => { this . whisper ( hc . nick , `${ e ?"\x00\n" :"" } ${ text } ` ) } :( text , e ) => { this . chat ( `${ e ?"" :`@{hc.nick} ` } ${ text } ` ) } ,
140+ hc . cmd == "whisper"
141+ )
142+ }
143+ }
129144 this . onmessage ( event . data , hc ) ;
130145 }
131146 [ "onclose" , "onchangechannel" , "joinfailed" , "oncaptcha" , "onjoin" , "onjoined" , "onmessage" ] . forEach ( func => {
132147 this [ func ] = ( ) => { }
133148 } ) ;
134- [ "channel" , "nick" , "joined" , "ping" , "pingtime" , "check" ] . forEach ( ve => {
149+ [ "channel" , "nick" , "joined" , "ping" , "pingtime" , "check" , "cmdstart" , "command" ] . forEach ( ve => {
135150 this [ ve ] = false
136151 } ) ;
137152 this . customId = 0 ;
@@ -212,6 +227,42 @@ class Client {
212227 text : text
213228 } )
214229 }
230+ reply ( obj ) { //来源十字街,有改动
231+ let replyText = '' ;
232+ let originalText = args . text ;
233+ let overlongText = false ;
234+ if ( originalText . length > 152 ) {
235+ replyText = originalText . slice ( 0 , 152 ) ;
236+ overlongText = true ;
237+ }
238+ if ( args . trip ) {
239+ replyText = '>' + args . trip + ' ' + args . nick + ':\n' ;
240+ } else {
241+ replyText = '>' + args . nick + ':\n' ;
242+ }
243+ originalText = originalText . split ( '\n' ) ;
244+ if ( originalText . length >= 8 ) {
245+ originalText = originalText . slice ( 0 , 8 ) ;
246+ overlongText = true ;
247+ }
248+ for ( let replyLine of originalText ) {
249+ if ( ! replyLine . startsWith ( '>>' ) ) replyText += '>' + replyLine + '\n' ;
250+ }
251+ if ( overlongText ) replyText += '>……\n' ;
252+ replyText += '\n' ;
253+ var nick = args . nick
254+ replyText += '@' + nick + ' ' ;
255+ return replyText ;
256+ }
257+ _COMMAND ( cmd , args , info , back , whisper ) {
258+ if ( this . command [ cmd ] ) {
259+ try {
260+ back ( this . command [ cmd ] . run ( args , info , back , whisper ) ) ;
261+ } catch ( e ) {
262+ back ( `命令执行出错:${ e . message } ` ) ;
263+ }
264+ } else back ( "命令未找到" ) ;
265+ }
215266}
216267
217268module . exports = Client
0 commit comments