From bf7bd28424b17a470c3171425312db49fffdb410 Mon Sep 17 00:00:00 2001 From: hanshino Date: Fri, 19 Jan 2024 15:41:02 +0000 Subject: [PATCH 1/4] Refactor docker-compose.yml file --- docker-compose.yml | 69 +++------------------------------------------- 1 file changed, 4 insertions(+), 65 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 27db53cb..b9187441 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,52 +1,6 @@ version: "3.5" services: - nginx: - image: nginx - env_file: ./.env - volumes: - - ./docker/config:/etc/nginx/conf.d/templates - ports: - - "5000:80" - networks: - - bot_network - depends_on: - - bot - - frontend - command: /bin/bash -c "envsubst '$$APP_DOMAIN' < /etc/nginx/conf.d/templates/redive.dev.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" - - frontend: - build: - context: ./frontend - dockerfile: Dockerfile.dev - environment: - "CHOKIDAR_USEPOLLING": "true" - expose: - - 3000 - networks: - - bot_network - volumes: - - ./frontend:/app - - bot: - build: - context: ./app - dockerfile: Dockerfile.dev - env_file: ./.env - restart: always - volumes: - - ./app:/application - expose: - - 5000 - depends_on: - - mysql - - redis - networks: - - bot_network - environment: - - "NODE_ENV=development" - mysql: - env_file: ./.env image: mysql volumes: - ./migration:/docker-entrypoint-initdb.d @@ -56,8 +10,8 @@ services: volume: nocopy: true restart: always - expose: - - "${DB_PORT}" + ports: + - 3306:3306 networks: - bot_network environment: @@ -85,23 +39,8 @@ services: restart: always networks: - bot_network - expose: - - "${REDIS_PORT}" - - crontab: - build: - context: ./job - dockerfile: Dockerfile.dev - networks: - - bot_network - depends_on: - - mysql - - redis - env_file: ./.env - environment: - - "NODE_ENV=development" - volumes: - - ./job:/script + ports: + - 6379:6379 phpmyadmin: depends_on: From 4ce4947cb762358a10bc02a5fa84a52b604004c4 Mon Sep 17 00:00:00 2001 From: hanshino Date: Fri, 19 Jan 2024 15:47:04 +0000 Subject: [PATCH 2/4] Update Redis host configuration and add dotenv package --- app/bottender.config.js | 2 +- app/package.json | 1 + app/server.js | 7 +++++++ app/yarn.lock | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/bottender.config.js b/app/bottender.config.js index 66f7da1e..57159843 100644 --- a/app/bottender.config.js +++ b/app/bottender.config.js @@ -12,7 +12,7 @@ module.exports = { }, redis: { port: process.env.REDIS_PORT, - host: "redis", + host: process.env.REDIS_HOST, password: process.env.REDIS_PASSWORD, db: 0, }, diff --git a/app/package.json b/app/package.json index 0ef5b1cf..71cc7daa 100644 --- a/app/package.json +++ b/app/package.json @@ -45,6 +45,7 @@ "devDependencies": { "@types/express": "^4.17.21", "cors": "^2.8.5", + "dotenv": "^16.3.1", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.2", diff --git a/app/server.js b/app/server.js index 5cc8a5e6..0b7fd285 100644 --- a/app/server.js +++ b/app/server.js @@ -1,3 +1,10 @@ +const path = require("path"); +if (process.env.NODE_ENV !== "production") { + require("dotenv").config({ + path: path.resolve(__dirname, "../.env"), + }); +} + const express = require("express"); const rateLimit = require("express-rate-limit"); const { bottender } = require("bottender"); diff --git a/app/yarn.lock b/app/yarn.lock index 19fef9df..2f66e1aa 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -2693,6 +2693,11 @@ dotenv@^10.0.0: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== +dotenv@^16.3.1: + version "16.3.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" + integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== + duplexer3@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" From 88b2127ad8a84ac47f79b175e864c51037149eb1 Mon Sep 17 00:00:00 2001 From: hanshino Date: Fri, 19 Jan 2024 18:59:25 +0000 Subject: [PATCH 3/4] Add NumberController for Sic Bo game --- app/locales/zh_tw.json | 5 +- app/src/app.js | 3 + .../application/NumberController.js | 141 +++++++++++++ app/src/templates/application/Number.js | 198 ++++++++++++++++++ 4 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 app/src/controller/application/NumberController.js create mode 100644 app/src/templates/application/Number.js diff --git a/app/locales/zh_tw.json b/app/locales/zh_tw.json index 210bae4d..52660d95 100644 --- a/app/locales/zh_tw.json +++ b/app/locales/zh_tw.json @@ -171,7 +171,10 @@ "add_start_analyze_success": "成功分析開始時間...", "add_end_now": "未指定結束時間,設定為現在之後一小時...", "add_end_analyze_success": "成功分析結束時間...", - "admin_now": "正在舉辦的遊戲:\n{{ id }}\n{{ name }}" + "admin_now": "正在舉辦的遊戲:\n{{ id }}\n{{ name }}", + "sic_bo_rolled": "骰出了 {{ dice1 }}、{{ dice2 }}、{{ dice3 }},總和為 {{ sum }}", + "sic_bo_win": "你選擇的是 {{ option }},獲得 {{ chips }} * {{ payout }} = {{ total }} 顆女神石", + "sic_bo_lose": "你選擇的是 {{ option }},失去 {{ chips }} 顆女神石" }, "trade": { "no_mention": "請標記要交易的對象", diff --git a/app/src/app.js b/app/src/app.js index fb110a36..aabb443c 100644 --- a/app/src/app.js +++ b/app/src/app.js @@ -34,6 +34,7 @@ const LotteryController = require("./controller/application/LotteryController"); const BullshitController = require("./controller/application/BullshitController"); const SubscribeController = require("./controller/application/SubscribeController"); const ScratchCardController = require("./controller/application/ScratchCardController"); +const NumberController = require("./controller/application/NumberController"); const { transfer } = require("./middleware/dcWebhook"); const redis = require("./util/redis"); const traffic = require("./util/traffic"); @@ -97,6 +98,7 @@ async function HandlePostback(context, { next }) { () => action === "exchangeScratchCard", withProps(ScratchCardController.exchange, { payload }) ), + route(() => action === "sicBoGuess", withProps(NumberController.postbackDecide, { payload })), route("*", next), ]); } catch (e) { @@ -134,6 +136,7 @@ async function OrderBased(context, { next }) { ...BullshitController.router, ...SubscribeController.router, ...ScratchCardController.router, + ...NumberController.router, text(/^[/#.](使用說明|help)$/, welcome), text(/^[/#.]抽(\*(?\d+))?(\s*(?[\s\S]+))?$/, gacha.play), text(/^[/#.]消耗抽(\*(?\d+))?(\s*(?[\s\S]+))?$/, (context, props) => diff --git a/app/src/controller/application/NumberController.js b/app/src/controller/application/NumberController.js new file mode 100644 index 00000000..8ea8952c --- /dev/null +++ b/app/src/controller/application/NumberController.js @@ -0,0 +1,141 @@ +const { text } = require("bottender/router"); +const { sample, get } = require("lodash"); +const NumberTemplate = require("../../templates/application/Number"); +const i18n = require("../../util/i18n"); + +exports.router = [ + text(/^[.#/](猜大小) (?\d{1,7})$/, privateSicBoHolding), + text(/^[.#/](猜) (?