import { MatrixInterface , MxMessage } from "../MatrixInterface" ; import { MxEvents } from "../../minecraft" ; import { Player } from "../../minecraft/internal/Player" ; export class MsgProcessor { constructor ( private readonly matrix ) { } param { string } room param { any } event returns { Promise < string > } public async buildEmoteMsg ( room , event ) { const content = event [ 'content' ] ; const sender = event [ 'sender' ] ; const body = content [ 'body' ] ; const roomMember = await this . matrix . getRoomMember ( room , sender ) ; const name = roomMember [ 'displayname' ] || sender ; return { sender : sender , room , body : ` * <${ name }> ${ body }` , event : < MxEvents . EmoteMessageEvent > { sender : { mxid : sender , displayName : name } , type : "message.emote" , body : body , } as MxEvents . Event } ; } param room param event returns { Promise < string > } public async buildTextMsg ( room , event ) { const content = event [ 'content' ] ; const sender = event [ 'sender' ] ; const body = content [ 'body' ] ; const roomMember = await this . matrix . getRoomMember ( room , sender ) ; const name = roomMember [ 'displayname' ] || sender ; return { sender : sender , room , body : `<${ name }> ${ body }` , event : < MxEvents . TextMessageEvent > { sender : { mxid : sender , displayName : name } , type : "message.text" , body : body , } as MxEvents . Event } ; } public async buildKickMsg ( room , event ) { const content = event [ 'content' ] ; const reason = content [ 'reason' ] ; const prevContent = event [ 'prev_content' ] || { } ; const sender = event [ 'sender' ] ; const victim = event [ 'state_key' ] ; const senderRoomMember = await this . matrix . getRoomMember ( room , sender ) ; const victimUUID = this . matrix . getPlayerUUID ( victim ) ; const senderName = senderRoomMember [ 'displayname' ] || sender ; const victimName = prevContent [ 'displayname' ] || victimUUID ; return { sender : sender , room , event : < MxEvents . KickPlayerEvent > { sender : { mxid : sender , displayName : senderName } , type : "player.kick" , player : new Player ( victimName , victimUUID ) , reason : reason } as MxEvents . Event } ; } public async buildBanMsg ( room , event ) { const content = event [ 'content' ] ; const reason = content [ 'reason' ] ; const prevContent = event [ 'prev_content' ] || { } ; const sender = event [ 'sender' ] ; const victim = event [ 'state_key' ] ; const senderRoomMember = await this . matrix . getRoomMember ( room , sender ) ; const victimUUID = this . matrix . getPlayerUUID ( victim ) ; const senderName = senderRoomMember [ 'displayname' ] || sender ; const victimName = prevContent [ 'displayname' ] || victimUUID ; return { sender : sender , room , event : < MxEvents . BanPlayerEvent > { sender : { mxid : sender , displayName : senderName } , type : "player.ban" , player : new Player ( victimName , victimUUID ) , reason : reason } as MxEvents . Event } ; } public async buildUnbanMsg ( room , event ) { const prevContent = event [ 'prev_content' ] ; const sender = event [ 'sender' ] ; const victim = event [ 'state_key' ] ; const senderRoomMember = await this . matrix . getRoomMember ( room , sender ) ; const victimUUID = this . matrix . getPlayerUUID ( victim ) ; const senderName = senderRoomMember [ 'displayname' ] || sender ; const victimName = prevContent [ 'displayname' ] || victimUUID ; return { sender : sender , room , event : < MxEvents . UnbanPlayerEvent > { sender : { mxid : sender , displayName : senderName } , type : "player.unban" , player : new Player ( victimName , victimUUID ) } as MxEvents . Event } ; } }