Compare commits

..

1 commit

Author SHA1 Message Date
9a37b8d2c9 Update dependency @types/uuid to v9.0.3
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-09 11:04:20 +00:00
17 changed files with 43 additions and 118 deletions

View file

@ -7,7 +7,7 @@
# any secret values.
BOT_TOKEN=
BOT_VER=0.1.4 DEV
BOT_VER=0.1.1 DEV
BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816
BOT_CLIENTID=682942374040961060
@ -26,4 +26,4 @@ DB_AUTH_PASS=dev
DB_SYNC=true
DB_LOGGING=true
DB_CARD_FILE=:memory:
DB_CARD_FILE=:memory:

View file

@ -7,7 +7,7 @@ steps:
- name: deploy
image: appleboy/drone-ssh
settings:
host: 192.168.68.120
host: 192.168.68.121
username: vylpes
password:
from_secret: ssh_password
@ -28,7 +28,7 @@ steps:
- name: stage
image: appleboy/drone-ssh
settings:
host: 192.168.68.120
host: 192.168.68.121
username: vylpes
password:
from_secret: ssh_password

View file

@ -7,7 +7,7 @@
# any secret values.
BOT_TOKEN=
BOT_VER=0.1.4
BOT_VER=0.1.1
BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816
BOT_CLIENTID=1093810443589529631
@ -26,4 +26,4 @@ DB_AUTH_PASS=prod
DB_SYNC=false
DB_LOGGING=false
DB_CARD_FILE=:memory:
DB_CARD_FILE=:memory:

View file

@ -7,7 +7,7 @@
# any secret values.
BOT_TOKEN=
BOT_VER=0.1.4 BETA
BOT_VER=0.1.1 BETA
BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816
BOT_CLIENTID=1147976642942214235
@ -26,4 +26,4 @@ DB_AUTH_PASS=stage
DB_SYNC=false
DB_LOGGING=false
DB_CARD_FILE=:memory:
DB_CARD_FILE=:memory:

View file

@ -1,8 +0,0 @@
CREATE TABLE `claim` (
`Id` varchar(255) NOT NULL,
`WhenCreated` datetime NOT NULL,
`WhenUpdated` datetime NOT NULL,
`ClaimId` varchar(255) NOT NULL,
`InventoryId` varchar(255) NOT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

View file

@ -1,14 +0,0 @@
INSERT INTO claim (
Id,
WhenCreated,
WhenUpdated,
ClaimId,
InventoryId
)
SELECT
UUID(),
NOW(),
NOW(),
ClaimId,
Id
FROM inventory;

View file

@ -1,2 +0,0 @@
ALTER TABLE inventory
DROP ClaimId;

View file

@ -1,6 +1,6 @@
{
"name": "card-drop",
"version": "0.1.5",
"version": "0.1.1",
"main": "./dist/bot.js",
"typings": "./dist",
"scripts": {

View file

@ -2,7 +2,6 @@ import { ButtonInteraction } from "discord.js";
import { ButtonEvent } from "../type/buttonEvent";
import Inventory from "../database/entities/app/Inventory";
import { CoreClient } from "../client/client";
import { default as eClaim } from "../database/entities/app/Claim";
export default class Claim extends ButtonEvent {
public override async execute(interaction: ButtonInteraction) {
@ -10,36 +9,30 @@ export default class Claim extends ButtonEvent {
const cardNumber = interaction.customId.split(' ')[1];
const claimId = interaction.customId.split(' ')[2];
const droppedBy = interaction.customId.split(' ')[3];
const userId = interaction.user.id;
const claimed = await eClaim.FetchOneByClaimId(claimId);
const claimed = await Inventory.FetchOneByClaimId(claimId);
if (claimed) {
await interaction.reply('This card has already been claimed');
return;
}
if (claimId == CoreClient.ClaimId && userId != droppedBy) {
await interaction.reply('The latest dropped card can only be claimed by the user who dropped it');
if (claimId != CoreClient.ClaimId) {
await interaction.reply('This card has expired');
return;
}
let inventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber);
if (!inventory) {
inventory = new Inventory(userId, cardNumber, 1);
inventory = new Inventory(userId, cardNumber, 1, claimId);
} else {
inventory.SetQuantity(inventory.Quantity + 1);
}
await inventory.Save(Inventory, inventory);
const claim = new eClaim(claimId);
claim.SetInventory(inventory);
await claim.Save(eClaim, claim);
await interaction.reply('Card claimed');
}
}

View file

@ -28,8 +28,6 @@ export default class Reroll extends ButtonEvent {
const image = readFileSync(randomCard.Path);
await interaction.deferReply();
const attachment = new AttachmentBuilder(image, { name: randomCard.FileName });
const embed = new EmbedBuilder()
@ -45,7 +43,7 @@ export default class Reroll extends ButtonEvent {
row.addComponents(
new ButtonBuilder()
.setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`)
.setCustomId(`claim ${randomCard.CardNumber} ${claimId}`)
.setLabel("Claim")
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()

View file

@ -9,6 +9,7 @@ import { Events } from "./events";
import { Util } from "./util";
import CardSetupFunction from "../Functions/CardSetupFunction";
import CardDataSource from "../database/dataSources/cardDataSource";
import CardDropHelper from "../helpers/CardDropHelper";
import IButtonEventItem from "../contracts/IButtonEventItem";
import { ButtonEvent } from "../type/buttonEvent";
import AppDataSource from "../database/dataSources/appDataSource";

View file

@ -51,7 +51,7 @@ export default class Drop extends Command {
row.addComponents(
new ButtonBuilder()
.setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`)
.setCustomId(`claim ${randomCard.CardNumber} ${claimId}`)
.setLabel("Claim")
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
@ -76,6 +76,7 @@ export default class Drop extends Command {
}
}
CoreClient.ClaimId = claimId;
}
}

View file

@ -1,31 +0,0 @@
import { Column, Entity, ManyToOne } from "typeorm";
import AppBaseEntity from "../../../contracts/AppBaseEntity";
import Inventory from "./Inventory";
import AppDataSource from "../../dataSources/appDataSource";
@Entity()
export default class Claim extends AppBaseEntity {
constructor(claimId: string) {
super();
this.ClaimId = claimId;
}
@Column()
ClaimId: string;
@ManyToOne(() => Inventory, x => x.Claims)
Inventory: Inventory;
public SetInventory(inventory: Inventory) {
this.Inventory = inventory;
}
public static async FetchOneByClaimId(claimId: string): Promise<Claim | null> {
const repository = AppDataSource.getRepository(Claim);
const single = await repository.findOne({ where: { ClaimId: claimId }});
return single;
}
}

View file

@ -1,16 +1,16 @@
import { Column, Entity, OneToMany } from "typeorm";
import { Column, Entity } from "typeorm";
import AppBaseEntity from "../../../contracts/AppBaseEntity";
import AppDataSource from "../../dataSources/appDataSource";
import Claim from "./Claim";
@Entity()
export default class Inventory extends AppBaseEntity {
constructor(userId: string, cardNumber: string, quantity: number) {
constructor(userId: string, cardNumber: string, quantity: number, claimId: string) {
super();
this.UserId = userId;
this.CardNumber = cardNumber;
this.Quantity = quantity;
this.ClaimId = claimId;
}
@Column()
@ -22,17 +22,13 @@ export default class Inventory extends AppBaseEntity {
@Column()
Quantity: number;
@OneToMany(() => Claim, x => x.Inventory)
Claims: Claim[];
@Column()
ClaimId: string;
public SetQuantity(quantity: number) {
this.Quantity = quantity;
}
public AddClaim(claim: Claim) {
this.Claims.push(claim);
}
public static async FetchOneByCardNumberAndUserId(userId: string, cardNumber: string): Promise<Inventory | null> {
const repository = AppDataSource.getRepository(Inventory);
@ -40,4 +36,12 @@ export default class Inventory extends AppBaseEntity {
return single;
}
public static async FetchOneByClaimId(claimId: string): Promise<Inventory | null> {
const repository = AppDataSource.getRepository(Inventory);
const single = await repository.findOne({ where: { ClaimId: claimId }});
return single;
}
}

View file

@ -1,17 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import MigrationHelper from "../../../../helpers/MigrationHelper"
export class CreateClaim1694609771821 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
MigrationHelper.Up('1694609771821-CreateClaim', '0.1.5', [
'01-CreateClaim',
'02-MoveToClaim',
'03-AlterInventory',
], queryRunner);
}
public async down(queryRunner: QueryRunner): Promise<void> {
}
}

View file

@ -4,6 +4,13 @@ import Series from "../database/entities/card/Series";
export default class CardDropHelper {
public static async GetRandomCard(): Promise<Card> {
const allSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]);
const allSeriesWithCards = allSeries.filter(x => x.Cards.length > 0);
const randomSeriesIndex = Math.floor(Math.random() * allSeriesWithCards.length);
const randomSeries = allSeriesWithCards[randomSeriesIndex];
const randomRarity = Math.random() * 100;
let cardRarity: CardRarity;
@ -17,13 +24,6 @@ export default class CardDropHelper {
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
else cardRarity = CardRarity.Legendary;
const allSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]);
const allSeriesWithCards = allSeries.filter(x => x.Cards.length > 0 && x.Cards.find(x => x.Rarity == cardRarity));
const randomSeriesIndex = Math.floor(Math.random() * allSeriesWithCards.length);
const randomSeries = allSeriesWithCards[randomSeriesIndex];
const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity && x.Path && x.FileName);
const randomCardIndex = Math.floor(Math.random() * allCards.length);

View file

@ -910,14 +910,14 @@
integrity sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==
"@types/uuid@^9.0.0":
version "9.0.4"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.4.tgz#e884a59338da907bda8d2ed03e01c5c49d036f1c"
integrity sha512-zAuJWQflfx6dYJM62vna+Sn5aeSWhh3OB+wfUEACNcqUSc0AGc5JKl+ycL1vrH7frGTXhJchYjE1Hak8L819dA==
version "9.0.3"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.3.tgz#6cdd939b4316b4f81625de9f06028d848c4a1533"
integrity sha512-taHQQH/3ZyI3zP8M/puluDEIEvtQHVYcC6y3N8ijFtAd28+Ey/G4sg1u2gB01S8MwybLOKAp9/yCMu/uR5l3Ug==
"@types/ws@^8.5.5":
version "8.5.6"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.6.tgz#e9ad51f0ab79b9110c50916c9fcbddc36d373065"
integrity sha512-8B5EO9jLVCy+B58PLHvLDuOD8DRVMgQzq8d55SjLCOn9kqGyqOvy27exVaTio1q1nX5zLu8/6N0n2ThSxOM6tg==
version "8.5.5"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.5.tgz#af587964aa06682702ee6dcbc7be41a80e4b28eb"
integrity sha512-lwhs8hktwxSjf9UaZ9tG5M03PGogvFaH8gUgLNbN9HKIg0dvv6q+gkSuJ8HN4/VbyxkuLzCjlN7GquQ0gUJfIg==
dependencies:
"@types/node" "*"