#!/bin/bash
source $HOME/.gamerc

[ "$1" == "" ] && exec echo "Usage: $0 <Environment (TEST => 0, LIVE => 1)>"

env=$1
check_filename="/tmp/exchange_cointype2_check.csv"
output_filename="/tmp/exchange_cointype2_monitor.log"

sudo rm -rf ${check_filename}

psql -U postgres ${ACCOUNT_DB_NAME} -c "COPY (SELECT id, reward FROM bonus_activity_exchange WHERE reward <> '') TO '${check_filename}' CSV"

COUNT=$(cat ${check_filename} | egrep ',6 2 |;6 2 ' | wc -l)

if [ "${COUNT}" -ne 0 ]; then
    rm -rf ${output_filename}
    echo "id,reward" >> ${output_filename}
    cat ${check_filename} | egrep ',6 2 |;6 2 ' >> ${output_filename}

    if [ "${env}" == "0" ]; then
        ENV_TAG="(測試)"
    elif [ "${env}" == "1" ]; then
        ENV_TAG="(正式)"
    fi
    send_messages ERROR exchange_cointype2 "${ENV_TAG} Bonus Activity Exchange 設定到給予付費鑽"
fi
