@@ -51,6 +51,9 @@ const client = new Client({
5151const conversationHistory = new Map ( ) ;
5252const MAX_HISTORY = 20 ;
5353
54+ // Track bot start time for uptime calculation
55+ const startTime = Date . now ( ) ;
56+
5457// Spam patterns
5558const SPAM_PATTERNS = [
5659 / f r e e \s * ( c r y p t o | b i t c o i n | b t c | e t h | n f t ) / i,
@@ -378,6 +381,65 @@ client.on('interactionCreate', async (interaction) => {
378381 ephemeral : true
379382 } ) ;
380383 }
384+ } else if ( commandName === 'status' ) {
385+ // Calculate uptime
386+ const uptime = Date . now ( ) - startTime ;
387+ const seconds = Math . floor ( uptime / 1000 ) ;
388+ const minutes = Math . floor ( seconds / 60 ) ;
389+ const hours = Math . floor ( minutes / 60 ) ;
390+ const days = Math . floor ( hours / 24 ) ;
391+
392+ let uptimeStr = '' ;
393+ if ( days > 0 ) uptimeStr += `${ days } d ` ;
394+ if ( hours % 24 > 0 ) uptimeStr += `${ hours % 24 } h ` ;
395+ if ( minutes % 60 > 0 ) uptimeStr += `${ minutes % 60 } m ` ;
396+ uptimeStr += `${ seconds % 60 } s` ;
397+
398+ // Get memory usage
399+ const memoryUsage = process . memoryUsage ( ) ;
400+ const memoryMB = ( memoryUsage . heapUsed / 1024 / 1024 ) . toFixed ( 2 ) ;
401+
402+ // Get server count
403+ const serverCount = client . guilds . cache . size ;
404+
405+ // Check API health
406+ let apiStatus = '🟢 Operational' ;
407+ try {
408+ const healthCheck = await fetch ( OPENCLAW_URL , {
409+ method : 'POST' ,
410+ headers : {
411+ 'Content-Type' : 'application/json' ,
412+ ...( OPENCLAW_TOKEN && { 'Authorization' : `Bearer ${ OPENCLAW_TOKEN } ` } )
413+ } ,
414+ body : JSON . stringify ( {
415+ model : config . ai ?. model || 'claude-sonnet-4-20250514' ,
416+ max_tokens : 1 ,
417+ messages : [ { role : 'user' , content : 'ping' } ] ,
418+ } ) ,
419+ } ) ;
420+
421+ if ( ! healthCheck . ok ) {
422+ apiStatus = '🟡 Degraded' ;
423+ }
424+ } catch {
425+ apiStatus = '🔴 Unavailable' ;
426+ }
427+
428+ // Create status embed
429+ const embed = new EmbedBuilder ( )
430+ . setColor ( 0x43B581 )
431+ . setTitle ( '📊 Bot Status' )
432+ . addFields (
433+ { name : '⏱️ Uptime' , value : uptimeStr , inline : true } ,
434+ { name : '📡 Servers' , value : serverCount . toString ( ) , inline : true } ,
435+ { name : '🧠 Memory' , value : `${ memoryMB } MB` , inline : true } ,
436+ { name : '🤖 AI Status' , value : apiStatus , inline : false } ,
437+ { name : '🏓 Latency' , value : `${ client . ws . ping } ms` , inline : true }
438+ )
439+ . setFooter ( { text : `${ client . user . tag } ` } )
440+ . setTimestamp ( ) ;
441+
442+ await interaction . reply ( { embeds : [ embed ] } ) ;
381443 }
382444 } catch ( err ) {
383445 console . error ( `Error handling /${ commandName } :` , err . message ) ;
0 commit comments