commands/history.js
/**
         * @brief This function is invoked when the database lookup operation to
         *        find the channel's ongoing game is complete. If a valid game
         *        is found, its history & attributes are returned in the
         *        response.
         *
         * @param error db lookup error
         * @param game valid game from the db
         *
         * @return none
         */
@brief This function is invoked when the database lookup operation to
find the channel's ongoing game is complete. If a valid game
is found, its history & attributes are returned in the
response.

@param error db lookup error
@param game valid game from the db

@return none
@brief This function is invoked when the database lookup operation to find the channel ' s ongoing game is complete . If a valid game is found its history & attributes are returned in the response . @param error db lookup error @param game valid game from the db @return none
function dbLookupCallback(error, game) {
            if (error !== undefined && error !== null) {
                logger.error(error);
                return res.json(
                    slackUtil.createResponse({
                        text: labels.DB_ERROR,
                        response_type: "ephemeral"
                    })
                );
            }
            if (game === undefined || game === null) {
                return res.json(
                    slackUtil.createResponse({
                        text: labels.GAME_NOT_FOUND_ERROR,
                        response_type: "ephemeral"
                    })
                );
            }
            let currentPlayerIndex = 0;
            if (game.players[1].name === game.currentPlayer) {
                currentPlayerIndex = 1;
            }
            let status = util.format(
                labels.CMD_STATUS_TEXT,
                slackUtil.getUserDisplay(game.players[0]),
                slackUtil.getUserDisplay(game.players[1])
            );
            let history = game.history;
            let historyText = "";
            let i = 0;
            let index = 0;
            let symbol = constants.drawState[constants.moveState.X];
            while (i < history.length) {
                historyText = historyText + (i + 1) + ". "
                        + slackUtil.getUserDisplay(game.players[index])
                        + " placed an `" + symbol + "` at location `"
                        + history[i].move + "` at `"
                        + history[i].time.toUTCString() + "`\n";
                index = (index + 1) % 2;
                if (symbol === constants.drawState[constants.moveState.X]) {
                    symbol = constants.drawState[constants.moveState.O];
                } else {
                    symbol = constants.drawState[constants.moveState.X];
                }
                i = i + 1;
            }
            if (history.length === 0) {
                historyText = labels.HISTORY_NOT_FOUND_ERROR;
            }
            res.json(
                slackUtil.createResponse({
                    text: status,
                    response_type: "ephemeral",
                    attachments: [{
                        text: historyText + "\n"
                                + util.format(
                            labels.CMD_STATUS_TURN_TEXT,
                            slackUtil.getUserDisplay(
                                game.players[currentPlayerIndex]
                            )
                        )
                                + "\n" + drawer.draw(game.board),
                        color: "#36a64f",
                        mrkdwn_in: [
                            "text"
                        ]
                    }]
                })
            );
        }
function dbLookupCallback ( error , game ) { if ( error !== undefined && error !== null ) { logger . error ( error ) ; return res . json ( slackUtil . createResponse ( { text : labels . DB_ERROR , response_type : "ephemeral" } ) ) ; } if ( game === undefined || game === null ) { return res . json ( slackUtil . createResponse ( { text : labels . GAME_NOT_FOUND_ERROR , response_type : "ephemeral" } ) ) ; } let currentPlayerIndex = 0 ; if ( game . players [ 1 ] . name === game . currentPlayer ) { currentPlayerIndex = 1 ; } let status = util . format ( labels . CMD_STATUS_TEXT , slackUtil . getUserDisplay ( game . players [ 0 ] ) , slackUtil . getUserDisplay ( game . players [ 1 ] ) ) ; let history = game . history ; let historyText = "" ; let i = 0 ; let index = 0 ; let symbol = constants . drawState [ constants . moveState . X ] ; while ( i < history . length ) { historyText = historyText + ( i + 1 ) + ". " + slackUtil . getUserDisplay ( game . players [ index ] ) + " placed an `" + symbol + "` at location `" + history [ i ] . move + "` at `" + history [ i ] . time . toUTCString ( ) + "`\n" ; index = ( index + 1 ) % 2 ; if ( symbol === constants . drawState [ constants . moveState . X ] ) { symbol = constants . drawState [ constants . moveState . O ] ; } else { symbol = constants . drawState [ constants . moveState . X ] ; } i = i + 1 ; } if ( history . length === 0 ) { historyText = labels . HISTORY_NOT_FOUND_ERROR ; } res . json ( slackUtil . createResponse ( { text : status , response_type : "ephemeral" , attachments : [ { text : historyText + "\n" + util . format ( labels . CMD_STATUS_TURN_TEXT , slackUtil . getUserDisplay ( game . players [ currentPlayerIndex ] ) ) + "\n" + drawer . draw ( game . board ) , color : "#36a64f" , mrkdwn_in : [ "text" ] } ] } ) ) ; }
@brief This function is invoked when the database lookup operation to
        find the channel's ongoing game is complete.
@brief This function is invoked when the database lookup operation to find the channel ' s ongoing game is complete .
// No ongling game found in this channel. // No ongling game found in this channel. // Show status of the current game. // Get historical moves for this game. // Text representing the historical moves.