From e41cedeacb87463256fbc20187e6d6fe0ddb51f7 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 13 Jun 2024 20:52:11 +0100 Subject: [PATCH 1/4] Fix the database saving the user's currency being removed before other checks are done --- src/buttonEvents/Claim.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/buttonEvents/Claim.ts b/src/buttonEvents/Claim.ts index 4f7f5ae..a1d2d44 100644 --- a/src/buttonEvents/Claim.ts +++ b/src/buttonEvents/Claim.ts @@ -31,8 +31,6 @@ export default class Claim extends ButtonEvent { return; } - await user.Save(User, user); - const claimed = await eClaim.FetchOneByClaimId(claimId); if (claimed) { @@ -45,6 +43,8 @@ export default class Claim extends ButtonEvent { return; } + await user.Save(User, user); + let inventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber); if (!inventory) { From e8ffe26bc3e6ac7c7aa43373dde9b638f9ec239e Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 13 Jun 2024 21:05:22 +0100 Subject: [PATCH 2/4] Add middleware so that the bot saves a user to the database on discovery of them --- src/client/events.ts | 3 +++ .../middleware/NewUserDiscovery.ts | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/client/interactionCreate/middleware/NewUserDiscovery.ts diff --git a/src/client/events.ts b/src/client/events.ts index 0b82cee..f02fb9c 100644 --- a/src/client/events.ts +++ b/src/client/events.ts @@ -2,11 +2,14 @@ import { Interaction } from "discord.js"; import ChatInputCommand from "./interactionCreate/ChatInputCommand"; import Button from "./interactionCreate/Button"; import AppLogger from "./appLogger"; +import NewUserDiscovery from "./interactionCreate/middleware/NewUserDiscovery"; export class Events { public async onInteractionCreate(interaction: Interaction) { if (!interaction.guildId) return; + await NewUserDiscovery(interaction); + if (interaction.isChatInputCommand()) { AppLogger.LogVerbose("Client", `ChatInputCommand: ${interaction.commandName}`); ChatInputCommand.onChatInput(interaction); diff --git a/src/client/interactionCreate/middleware/NewUserDiscovery.ts b/src/client/interactionCreate/middleware/NewUserDiscovery.ts new file mode 100644 index 0000000..dcbe75a --- /dev/null +++ b/src/client/interactionCreate/middleware/NewUserDiscovery.ts @@ -0,0 +1,15 @@ +import { Interaction } from "discord.js"; +import User from "../../../database/entities/app/User"; +import CardConstants from "../../../constants/CardConstants"; +import AppLogger from "../../appLogger"; + +export default async function NewUserDiscovery(interaction: Interaction) { + const existingUser = await User.FetchOneById(User, interaction.user.id); + + if (existingUser) return; + + const newUser = new User(interaction.user.id, CardConstants.StartingCurrency); + await newUser.Save(User, newUser); + + AppLogger.LogInfo("NewUserDiscovery", `Discovered new user ${interaction.user.id}`); +} \ No newline at end of file From 324065e29be40dde568ea015635610d6a1b6ec8d Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 13 Jun 2024 21:10:06 +0100 Subject: [PATCH 3/4] 0.6.4 --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index bd411ca..d660884 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.6.3 +BOT_VER=0.6.4 BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=682942374040961060 From f4d01992b85d328f3c6b59fb0b7271a6627bc847 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 13 Jun 2024 21:10:15 +0100 Subject: [PATCH 4/4] v0.6.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 12287fd..2568f8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "card-drop", - "version": "0.6.3", + "version": "0.6.4", "main": "./dist/bot.js", "typings": "./dist", "scripts": {