import { NextFunction , Request , Response } from "express" ; import * as Errors from "../../errors" ; import { fail } from "../../validate" ; import { Main } from "../../../../Main" ; import { Bridge } from "../../../../bridging" ; import { LogService } from "matrix-bot-sdk" ; import { MCEvents } from "../../../../minecraft" ; param { Request } req param { Response } res returns { Promise < void > } export async function postChat ( req , res ) { const main = req [ 'main' ] ; const bridge = req [ 'bridge' ] ; const id = req [ 'id' ] ; const body = req . body ; const message = body [ 'message' ] ; const playerRaw = body . player ; const player = await main . players . getPlayer ( playerRaw . name , playerRaw . uuid ) ; const mcMessage = { message , player } ; await main . sendToMatrix ( bridge , mcMessage ) ; res . status ( 200 ) ; res . end ( ) ; LogService . info ( 'WebInterface' , `[Request ${ id }]: Finished` ) ; } param { Request } req param { Response } res param { NextFunction } next export function checkChatIntegrity ( req , res , next ) { const reqID = req [ 'id' ] ; const body = req . body ; LogService . info ( 'WebInterface' , `[Request ${ reqID }]: Checking Chat Body Integrity` ) ; const message = body [ 'message' ] ; if ( message == undefined ) { fail ( res , Errors . noMessageError ) ; return ; } else if ( ! ( typeof message == 'string' ) ) { fail ( res , Errors . messageTypeError ) ; return ; } LogService . debug ( 'WebInterface' , `[Request ${ reqID }]: Message "${ message }"` ) ; /**
     * If the integrity passed this is what the body should look like:
     * {
     *   "message": "The body of the message",
     *   "player" {
     *     "name": "player name",
     *     "uuid": "player uuid"
     *   }
     * }
     */ next ( ) ; }