Make claiming require currency

This commit is contained in:
Ethan Lane 2024-04-29 18:27:15 +01:00
parent dbbfd74c04
commit 833d29a0e7
4 changed files with 29 additions and 7 deletions

View file

@ -13,23 +13,24 @@ BOT_OWNERID=147392775707426816
BOT_CLIENTID=682942374040961060 BOT_CLIENTID=682942374040961060
BOT_ENV=4 BOT_ENV=4
BOT_ADMINS=147392775707426816,887272961504071690 BOT_ADMINS=147392775707426816,887272961504071690
BOT_LOGLEVEL=info
ABOUT_FUNDING= ABOUT_FUNDING=
ABOUT_REPO= ABOUT_REPO=
DATA_DIR= DATA_DIR=./.temp
DB_HOST= DB_HOST=127.0.0.1
DB_PORT= DB_PORT=3301
DB_NAME= DB_NAME=carddrop
DB_AUTH_USER= DB_AUTH_USER=
DB_AUTH_PASS= DB_AUTH_PASS=
DB_SYNC= DB_SYNC=
DB_LOGGING= DB_LOGGING=
DB_DATA_LOCATION=~/.docker DB_DATA_LOCATION=./.temp/database
DB_CARD_FILE=:memory: DB_CARD_FILE=:memory:
EXPRESS_PORT=3303 EXPRESS_PORT=3302
GDRIVESYNC_AUTO=true GDRIVESYNC_AUTO=true

1
.gitignore vendored
View file

@ -109,3 +109,4 @@ ormconfig.json
gdrive-credentials.json gdrive-credentials.json
data/ data/
*.db *.db
.temp/

View file

@ -7,6 +7,7 @@ import AppLogger from "../client/appLogger";
import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata"; import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
import path from "path"; import path from "path";
import User from "../database/entities/app/User";
export default class Claim extends ButtonEvent { export default class Claim extends ButtonEvent {
public override async execute(interaction: ButtonInteraction) { public override async execute(interaction: ButtonInteraction) {
@ -41,6 +42,17 @@ export default class Claim extends ButtonEvent {
await inventory.Save(Inventory, inventory); 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); const claim = new eClaim(claimId);
claim.SetInventory(inventory); claim.SetInventory(inventory);

View file

@ -16,4 +16,12 @@ export default class User extends AppBaseEntity {
public UpdateCurrency(currency: number) { public UpdateCurrency(currency: number) {
this.Currency = currency; this.Currency = currency;
} }
public RemoveCurrency(amount: number): boolean {
if (this.Currency < amount) return false;
this.Currency -= amount;
return true;
}
} }