import type { Request , Response } from "express" ; import type { Main } from "../../../../Main" ; import type { Bridge } from "../../../../bridging" ; import type { MxEvents } from "../../../../minecraft" ; import { LogService } from "matrix-bot-sdk" ; param { Request } req param { Response } res export function getChat ( req , res ) { const main = req [ 'main' ] ; const bridge = req [ 'bridge' ] ; const id = req [ 'id' ] ; let messages = [ ] ; main . getNewMxMessages ( bridge ) . forEach ( function ( rawEvent ) { switch ( rawEvent [ 'type' ] ) { case "message.emote" : { let event = rawEvent as MxEvents . EmoteMessageEvent ; messages . push ( ` * <${ event [ 'sender' ] [ 'displayName' ] }> ${ event [ 'body' ] }` ) ; break ; } case "message.text" : { let event = rawEvent as MxEvents . TextMessageEvent ; messages . push ( `<${ event [ 'sender' ] [ 'displayName' ] }> ${ event [ 'body' ] }` ) ; break ; } case "message.announce" : { let event = rawEvent as MxEvents . AnnounceMessageEvent ; messages . push ( `[Server] ${ event [ 'body' ] }` ) ; break ; } } } ) ; const chat = { chat : messages } ; res . status ( 200 ) ; res . send ( chat ) ; res . end ( ) ; LogService . info ( 'WebInterface' , `[Request ${ id }]: Finished.` ) ; }