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

# 如果 gamerc 存在, 則載入它
[ -f ~/.gamerc ] && source ~/.gamerc

# 如果是非 Ctrl 架構請自行設定遊戲名稱跟國家名稱
[ -z "${GAME_TYPE}" ] && GAME_TYPE="非Ctrl架構, 自行設定"
[ -z "${COUNTRY_CODE}" ] && COUNTRY_CODE="非Ctrl架構, 自行設定"

# 如果有需要自訂或是修改顯示的遊戲與國家名稱, 請自行修正
[ "${GAME_TYPE}" == "AK" ] && GAME_TYPE_DISPLAY="M7" || GAME_TYPE_DISPLAY=${GAME_TYPE}
[ ! -z "${COUNTRY_CODE_DISPLAY}" ] && COUNTRY_CODE_DISPLAY=${COUNTRY_CODE_DISPLAY} || COUNTRY_CODE_DISPLAY=${COUNTRY_CODE}

TITLE=$1
CONTENT=$2

# Chatbot Announce
#GOOGLE_CHAT_WEBHOOK_URL="https://chat.googleapis.com/v1/spaces/AAAA7hXAOCM/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=YupvEeDhNq2aF9ldCAf8TeJw8kmafVAXpj3xJWIzRGw%3D"

DATETIME=$(date +"%Y-%m-%d %T %Z")
MESSAGE=$(printf "[${TITLE}]\n${DATETIME}\n${GAME_TYPE_DISPLAY}-${COUNTRY_CODE_DISPLAY} => ${CONTENT}")
curl -sS -X POST -H 'Content-Type: application/json' $GOOGLE_CHAT_WEBHOOK_URL -d "{\"text\": \"${MESSAGE}\"}"
