From fca199d9bdb81e273c4dac751b97b324bf441cd2 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 3 May 2024 18:37:08 +0100 Subject: [PATCH 1/3] Make claim button use currency to claim (#216) # Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. #201 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that provde my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://git.vylpes.xyz/External/card-drop/pulls/216 Reviewed-by: VylpesTester Co-authored-by: Ethan Lane Co-committed-by: Ethan Lane --- .env.example | 13 +++++++------ .forgejo/workflows/production.yml | 3 ++- .forgejo/workflows/stage.yml | 3 ++- .gitignore | 3 ++- src/buttonEvents/Claim.ts | 12 ++++++++++++ src/database/entities/app/User.ts | 8 ++++++++ 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 3ff53e9..4fccad3 100644 --- a/.env.example +++ b/.env.example @@ -13,23 +13,24 @@ BOT_OWNERID=147392775707426816 BOT_CLIENTID=682942374040961060 BOT_ENV=4 BOT_ADMINS=147392775707426816,887272961504071690 +BOT_LOGLEVEL=info ABOUT_FUNDING= ABOUT_REPO= -DATA_DIR= +DATA_DIR=./.temp -DB_HOST= -DB_PORT= -DB_NAME= +DB_HOST=127.0.0.1 +DB_PORT=3301 +DB_NAME=carddrop DB_AUTH_USER= DB_AUTH_PASS= DB_SYNC= DB_LOGGING= -DB_DATA_LOCATION=~/.docker +DB_DATA_LOCATION=./.temp/database DB_CARD_FILE=:memory: -EXPRESS_PORT=3303 +EXPRESS_PORT=3302 GDRIVESYNC_AUTO=true \ No newline at end of file diff --git a/.forgejo/workflows/production.yml b/.forgejo/workflows/production.yml index ba028b4..79906d1 100644 --- a/.forgejo/workflows/production.yml +++ b/.forgejo/workflows/production.yml @@ -53,12 +53,13 @@ jobs: DATA_DIR: ${{ secrets.PROD_DATA_DIR }} GDRIVESYNC_AUTO: ${{ vars.PROD_GDRIVESYNC_AUTO }} EXPRESS_PORT: ${{ secrets.PROD_EXPRESS_PORT }} + BOT_LOGLEVEL: ${{ vars.PROD_BOT_LOGLEVEL }} with: host: ${{ secrets.PROD_SSH_HOST }} username: ${{ secrets.PROD_SSH_USER }} key: ${{ secrets.PROD_SSH_KEY }} port: ${{ secrets.PROD_SSH_PORT }} - envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,BOT_ENV,BOT_ADMINS,DATA_DIR,GDRIVESYNC_AUTO,SERVER_PATH,EXPRESS_PORT + envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,BOT_ENV,BOT_ADMINS,DATA_DIR,GDRIVESYNC_AUTO,SERVER_PATH,EXPRESS_PORT,BOT_LOGLEVEL script: | source .sshrc \ && cd /home/vylpes/apps/card-drop/card-drop_prod \ diff --git a/.forgejo/workflows/stage.yml b/.forgejo/workflows/stage.yml index d0d0215..ce9b78f 100644 --- a/.forgejo/workflows/stage.yml +++ b/.forgejo/workflows/stage.yml @@ -53,12 +53,13 @@ jobs: DATA_DIR: ${{ secrets.STAGE_DATA_DIR }} GDRIVESYNC_AUTO: ${{ vars.STAGE_GDRIVESYNC_AUTO }} EXPRESS_PORT: ${{ secrets.STAGE_EXPRESS_PORT }} + BOT_LOGLEVEL: ${{ vars.STAGE_BOT_LOGLEVEL }} with: host: ${{ secrets.STAGE_SSH_HOST }} username: ${{ secrets.STAGE_SSH_USER }} key: ${{ secrets.STAGE_SSH_KEY }} port: ${{ secrets.STAGE_SSH_PORT }} - envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,BOT_ENV,BOT_ADMINS,DATA_DIR,GDRIVESYNC_AUTO,SERVER_PATH,EXPRESS_PORT + envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,BOT_ENV,BOT_ADMINS,DATA_DIR,GDRIVESYNC_AUTO,SERVER_PATH,EXPRESS_PORT,BOT_LOGLEVEL script: | source .sshrc \ && cd /home/vylpes/apps/card-drop/card-drop_stage \ diff --git a/.gitignore b/.gitignore index aecb458..9326cc8 100644 --- a/.gitignore +++ b/.gitignore @@ -108,4 +108,5 @@ config.json ormconfig.json gdrive-credentials.json data/ -*.db \ No newline at end of file +*.db +.temp/ \ No newline at end of file diff --git a/src/buttonEvents/Claim.ts b/src/buttonEvents/Claim.ts index 6c45900..9d29f7b 100644 --- a/src/buttonEvents/Claim.ts +++ b/src/buttonEvents/Claim.ts @@ -7,6 +7,7 @@ import AppLogger from "../client/appLogger"; import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata"; import { readFileSync } from "fs"; import path from "path"; +import User from "../database/entities/app/User"; export default class Claim extends ButtonEvent { public override async execute(interaction: ButtonInteraction) { @@ -41,6 +42,17 @@ export default class Claim extends ButtonEvent { await inventory.Save(Inventory, inventory); + let user = await User.FetchOneById(User, userId) || new User(userId, 300); + + AppLogger.LogSilly("Button/Claim", `${user.Id} has ${user.Currency} currency`); + + if (!user.RemoveCurrency(10)) { + await interaction.reply(`Not enough currency! You need 10 currency, you have ${user.Currency}`); + return; + } + + await user.Save(User, user); + const claim = new eClaim(claimId); claim.SetInventory(inventory); diff --git a/src/database/entities/app/User.ts b/src/database/entities/app/User.ts index c954aea..649c1c1 100644 --- a/src/database/entities/app/User.ts +++ b/src/database/entities/app/User.ts @@ -16,4 +16,12 @@ export default class User extends AppBaseEntity { public UpdateCurrency(currency: number) { this.Currency = currency; } + + public RemoveCurrency(amount: number): boolean { + if (this.Currency < amount) return false; + + this.Currency -= amount; + + return true; + } } \ No newline at end of file From f0870f0d610192693ba5573f23c4d5cccdb0e5fe Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 6 May 2024 16:41:08 +0100 Subject: [PATCH 2/3] Update dependency @types/node to v20.12.8 (#217) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node) ([source](https://github.com/DefinitelyTyped/DefinitelyTyped)) | devDependencies | patch | [`20.12.7` -> `20.12.8`](https://renovatebot.com/diffs/npm/@types%2fnode/20.12.7/20.12.8) | --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Reviewed-on: https://git.vylpes.xyz/External/card-drop/pulls/217 Co-authored-by: Renovate Bot Co-committed-by: Renovate Bot --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e93e59f..066d1d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1900,9 +1900,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "20.12.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", - "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", + "version": "20.12.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.8.tgz", + "integrity": "sha512-NU0rJLJnshZWdE/097cdCBbyW1h4hEg0xpovcoAQYHl8dnEyp/NAOiE45pvc+Bd1Dt+2r94v2eGFpQJ4R7g+2w==", "dependencies": { "undici-types": "~5.26.4" } From f07058d36952957e0966ed4a23de4d3a3b63cba8 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 6 May 2024 16:44:43 +0100 Subject: [PATCH 3/3] Update dependency jest-mock-extended to v3.0.7 (#218) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [jest-mock-extended](https://github.com/marchaos/jest-mock-extended) | dependencies | patch | [`3.0.6` -> `3.0.7`](https://renovatebot.com/diffs/npm/jest-mock-extended/3.0.6/3.0.7) | --- ### Release Notes
marchaos/jest-mock-extended (jest-mock-extended) ### [`v3.0.7`](https://github.com/marchaos/jest-mock-extended/releases/tag/3.0.7) [Compare Source](https://github.com/marchaos/jest-mock-extended/compare/77a64ae8328904bcc614ead4ba8d0d9e8a658136...3.0.7) Bumped ts-essentials
--- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Reviewed-on: https://git.vylpes.xyz/External/card-drop/pulls/218 Co-authored-by: Renovate Bot Co-committed-by: Renovate Bot --- package-lock.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 066d1d0..9d65b45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6816,11 +6816,11 @@ } }, "node_modules/jest-mock-extended": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/jest-mock-extended/-/jest-mock-extended-3.0.6.tgz", - "integrity": "sha512-DJuEoFzio0loqdX8NIwkbE9dgIXNzaj//pefOQxGkoivohpxbSQeNHCAiXkDNA/fmM4EIJDoZnSibP4w3dUJ9g==", + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/jest-mock-extended/-/jest-mock-extended-3.0.7.tgz", + "integrity": "sha512-7lsKdLFcW9B9l5NzZ66S/yTQ9k8rFtnwYdCNuRU/81fqDWicNDVhitTSPnrGmNeNm0xyw0JHexEOShrIKRCIRQ==", "dependencies": { - "ts-essentials": "^9.4.2" + "ts-essentials": "^10.0.0" }, "peerDependencies": { "jest": "^24.0.0 || ^25.0.0 || ^26.0.0 || ^27.0.0 || ^28.0.0 || ^29.0.0", @@ -10847,11 +10847,11 @@ } }, "node_modules/ts-essentials": { - "version": "9.4.2", - "resolved": "https://registry.npmjs.org/ts-essentials/-/ts-essentials-9.4.2.tgz", - "integrity": "sha512-mB/cDhOvD7pg3YCLk2rOtejHjjdSi9in/IBYE13S+8WA5FBSraYf4V/ws55uvs0IvQ/l0wBOlXy5yBNZ9Bl8ZQ==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/ts-essentials/-/ts-essentials-10.0.0.tgz", + "integrity": "sha512-77FHNJEyysF9+1s4G6eejuA1lxw7uMchT3ZPy3CIbh7GIunffpshtM8pTe5G6N5dpOzNevqRHew859ceLWVBfw==", "peerDependencies": { - "typescript": ">=4.1.0" + "typescript": ">=4.5.0" }, "peerDependenciesMeta": { "typescript": {