import * as moment from 'moment' ; import momentDurationFormatSetup from 'moment-duration-format' ; import { PayloadBundle , PayloadBundleSource , PayloadBundleType } from '@wireapp/core/src/main/conversation/' ; import type { QuotableMessage } from '@wireapp/core/src/main/conversation/message/OtrMessage' ; import { MessageHandler } from '@wireapp/bot-api' ; import type { TextContent } from '@wireapp/core/src/main/conversation/content' ; momentDurationFormatSetup ( moment as any ) ; export class UptimeHandler extends MessageHandler { static getUptime ( ) { const seconds = Math . floor ( process . uptime ( ) ) ; return ( moment . duration ( seconds , 'seconds' ) as any ) . format ( { precision : 0 , template : 'y [years], w [weeks], d [days], h [hours], m [minutes], s [seconds]' , } ) ; } async handleEvent ( payload ) { if ( payload . source === PayloadBundleSource . NOTIFICATION_STREAM ) { return ; } switch ( payload . type ) { case PayloadBundleType . TEXT : { const content = payload . content as TextContent ; if ( content . text . trim ( ) === '/uptime' ) { const upTime = UptimeHandler . getUptime ( ) ; await this . sendReply ( payload . conversation , payload as QuotableMessage , `Running since: ${ upTime }` ) ; } break ; } } } }