Mattie112 / FactoriGOChatBot

A Discord chatbot for Factorio written in Golang
GNU General Public License v3.0
10 stars 5 forks source link

discord notification of players' JOIN/LEAVE not working #33

Closed changchiyou closed 3 hours ago

changchiyou commented 3 hours ago
docker-compose.yml ``` services: factorio: container_name: Factorio image: factoriotools/factorio:stable environment: CONSOLE_LOG_LOCATION: "/factorio/console.log" ports: - "34197:34197/udp" - "27015:27015/tcp" volumes: - /opt/factorio:/factorio restart: always labels: - "com.centurylinklabs.watchtower.scope=${COMPOSE_PROJECT_NAME}" healthcheck: test: ["CMD-SHELL", "grep -q 'Starting RCON interface at IP ADDR' /factorio/factorio-current.log || exit 1"] interval: 60s timeout: 10s retries: 3 start_period: 2s factorigochatbot: container_name: FactoriGOChatBot image: mattie112/factorigo-chat-bot:latest environment: LOG_LEVEL: debug DISCORD_TOKEN: "${FACTORIOGOCHATBOT_DISCORD_TOKEN}" DISCORD_CHANNEL_ID: "${FACTORIOGOCHATBOT_DISCORD_CHANNEL_ID}" RCON_IP: "factorio" RCON_PORT: "${RCON_PORT-27015}" RCON_PASSWORD: "${RCONPW}" FACTORIO_LOG: "/opt-factorio/console.log" ACHIEVEMENT_MODE: "true" volumes: - /opt/factorio:/opt-factorio restart: always depends_on: factorio: condition: service_healthy watchtower: container_name: Watchtower image: containrrr/watchtower volumes: - /var/run/docker.sock:/var/run/docker.sock - /root/.docker/config.json:/config.json command: --interval 30 environment: WATCHTOWER_NO_STARTUP_MESSAGE: "true" WATCHTOWER_REMOVE_VOLUMES: "true" WATCHTOWER_ROLLING_RESTART: "true" WATCHTOWER_CLEANUP: "true" WATCHTOWER_SCOPE: "${COMPOSE_PROJECT_NAME}" TZ: "Asia/Taipei" WATCHTOWER_NOTIFICATION_REPORT: "true" WATCHTOWER_NOTIFICATION_URL: > discord://${WATCHTOWER_DISCORD_WEBHOOK_TOKEN}@${WATCHTOWER_DISCORD_WEBHOOK_ID} WATCHTOWER_NOTIFICATION_TEMPLATE: | {{- if .Report -}} {{- with .Report -}} {{- if ( or .Updated .Failed ) -}} **Watchtower Report Summary** - **Scanned:** {{len .Scanned}} - **Updated:** {{len .Updated}} - **Failed:** {{len .Failed}} {{- if .Updated}} **Updated Containers:** {{- range .Updated}} - **{{.Name}}** ({{.ImageName}}) - Current ID: `{{.CurrentImageID.ShortID}}` - Updated to: `{{.LatestImageID.ShortID}}` {{- end -}} {{- end}} {{- if .Skipped}} **Skipped Containers:** {{- range .Skipped}} - **{{.Name}}** ({{.ImageName}}) - Status: `{{.State}}` - Error: `{{.Error}}` {{- end -}} {{- end}} {{- if .Failed}} **Failed Containers:** {{- range .Failed}} - **{{.Name}}** ({{.ImageName}}) - Status: `{{.State}}` - Error: `{{.Error}}` {{- end -}} {{- end}} {{- end -}} {{- end -}} {{- else -}} **General Notifications:** {{range .Entries -}} {{.Message}}{{"\n"}} {{- end -}} {{- end -}} restart: always ```
time="2024-11-02T08:46:21.588748102Z" level="info" msg="Starting FactoriGO Chat Bot f5e3089 - 20241101.165503"
time="2024-11-02T08:46:22.116627971Z" level="info" msg="Bot registered by Discord and is now listening for messagesToDiscord"
time="2024-11-02T08:46:22.116721401Z" level="debug" msg="Updated status to Watching the world burn"
time="2024-11-02T08:46:24.117975879Z" level="debug" msg="Setting up message handler"
time="2024-11-02T08:46:24.118207918Z" level="debug" msg="Updated status to Watching the world burn"
time="2024-11-02T08:57:22.514084261Z" level="debug" msg="Read line from Factorio log" line="2024-11-02 08:57:22 [JOIN] happydogismine joined the game"
time="2024-11-02T09:02:58.113596545Z" level="debug" msg="Read line from Factorio log" line="2024-11-02 09:02:58 [CHAT] happydogismine: testtest"
time="2024-11-02T09:04:33.847036812Z" level="debug" msg="Read line from Factorio log" line="2024-11-02 09:04:33 [CHAT] happydogismine: testtest"
time="2024-11-02T09:04:40.647283337Z" level="debug" msg="Read line from Factorio log" line="2024-11-02 09:04:40 [LEAVE] happydogismine left the game"
time="2024-11-02T11:39:44.796432834Z" level="debug" msg="Read line from Factorio log" line="2024-11-02 11:39:44 [JOIN] happydogismine joined the game"
time="2024-11-02T11:40:25.813678901Z" level="debug" msg="Read line from Factorio log" line="2024-11-02 11:40:25 [LEAVE] happydogismine left the game"

image

parseAndFormatMessage parese & format CHAT correctly (without GPS, I havn't test it yet), but failed with JOIN/LEAVE without any error logs.

changchiyou commented 3 hours ago

NVM, I found that there is no default value setting at loadConfig:

https://github.com/Mattie112/FactoriGOChatBot/blob/f5e3089521933bc04701ff54a92b03ea6298ecff/main.go#L88-L112

Which means I have to set sendJoinLeave if I want to enable the feature, it's not frendly enought for docker user - since we have to assign ALL variables into enviorments section.