@@ -34,8 +34,7 @@ client.initialize();
3434
3535const messageEvent = ( msg : Message ) => {
3636 // ignore message if it is older than 10 seconds
37- if ( msg . timestamp < Date . now ( ) / 1000 - 10 )
38- return ;
37+ if ( msg . timestamp < Date . now ( ) / 1000 - 10 ) return ;
3938
4039 const prefix = ! msg . body . startsWith ( commandPrefix ) ;
4140 const senderId = msg . from . split ( "@" ) [ 0 ] ;
@@ -49,10 +48,11 @@ const messageEvent = (msg: Message) => {
4948 /*
5049 * Check if the message starts with the command prefix.
5150 */
52- const keyWithPrefix = msg . body . split ( " " ) [ 0 ] ;
53- const key = keyWithPrefix . startsWith ( commandPrefix )
54- ? keyWithPrefix . slice ( commandPrefix . length )
55- : keyWithPrefix ;
51+ const messageBody = msg . body . split ( " " ) [ 0 ] ;
52+ const bodyHasPrefix = messageBody . startsWith ( commandPrefix ) ;
53+ const key = bodyHasPrefix
54+ ? messageBody . slice ( commandPrefix . length )
55+ : messageBody ;
5656 const handler = commands [ key . toLocaleLowerCase ( ) ] ;
5757 if ( ! handler ) return ;
5858
@@ -76,9 +76,7 @@ const messageEvent = (msg: Message) => {
7676 }
7777
7878 if ( debug ) log . info ( "Message" , msg . body . slice ( 0 , 255 ) ) ;
79- msg . body = commandPrefixLess
80- ? msg . body
81- : msg . body . slice ( commandPrefix . length ) . trim ( ) ;
79+ msg . body = ! bodyHasPrefix ? msg . body : msg . body . slice ( commandPrefix . length ) ;
8280
8381 /*
8482 * Execute the command handler.
0 commit comments