Compare commits

..

11 commits

Author SHA1 Message Date
58c77dba21 v0.1.1
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-05 21:07:41 +01:00
5ec79ee67c Add ability to force a card
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-05 20:45:33 +01:00
476b9ad5f9 Give failsafe to api sending for drop
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-05 20:05:29 +01:00
97dc81df9a Add drop rarity force logic to reroll
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-05 19:42:07 +01:00
20461dde6d Remove .db file
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-05 19:38:33 +01:00
ada907e2a4 Make force rarity configurable
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-05 19:34:25 +01:00
1a4d4b4e23 Merge branch 'hotfix/0.1.1' into develop
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-05 19:14:40 +01:00
bd7b5e7b1a Temporary force legendary
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-05 19:14:12 +01:00
6629ac30aa hotfix/0.1.1 (#23)
All checks were successful
continuous-integration/drone/push Build is passing
- Fix gifs not animating

Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/23
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2023-09-04 13:02:02 +01:00
737c804d7e 0.1.1
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-04 13:00:51 +01:00
b848629f8d Fix gifs not working
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-04 12:59:09 +01:00
9 changed files with 123 additions and 33 deletions

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=0.1.0 DEV BOT_VER=0.1.1 DEV
BOT_AUTHOR=Vylpes BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816 BOT_OWNERID=147392775707426816
BOT_CLIENTID=682942374040961060 BOT_CLIENTID=682942374040961060
@ -15,6 +15,9 @@ BOT_CLIENTID=682942374040961060
ABOUT_FUNDING= ABOUT_FUNDING=
ABOUT_REPO= ABOUT_REPO=
DROP_RARITY=-1
DROP_CARD=-1
DB_HOST=127.0.0.1 DB_HOST=127.0.0.1
DB_PORT=3301 DB_PORT=3301
DB_NAME=carddrop DB_NAME=carddrop

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=0.1.0 BOT_VER=0.1.1
BOT_AUTHOR=Vylpes BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816 BOT_OWNERID=147392775707426816
BOT_CLIENTID=1093810443589529631 BOT_CLIENTID=1093810443589529631
@ -15,6 +15,9 @@ BOT_CLIENTID=1093810443589529631
ABOUT_FUNDING= ABOUT_FUNDING=
ABOUT_REPO= ABOUT_REPO=
DROP_RARITY=-1
DROP_CARD=-1
DB_HOST=127.0.0.1 DB_HOST=127.0.0.1
DB_PORT=3321 DB_PORT=3321
DB_NAME=carddrop DB_NAME=carddrop

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=0.1.0 BETA BOT_VER=0.1.1 BETA
BOT_AUTHOR=Vylpes BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816 BOT_OWNERID=147392775707426816
BOT_CLIENTID=1147976642942214235 BOT_CLIENTID=1147976642942214235
@ -15,6 +15,9 @@ BOT_CLIENTID=1147976642942214235
ABOUT_FUNDING= ABOUT_FUNDING=
ABOUT_REPO= ABOUT_REPO=
DROP_RARITY=-1
DROP_CARD=-1
DB_HOST=127.0.0.1 DB_HOST=127.0.0.1
DB_PORT=3311 DB_PORT=3311
DB_NAME=carddrop DB_NAME=carddrop

View file

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

View file

@ -65,7 +65,7 @@ export default class CardSetupFunction {
const cardId = filePart[0]; const cardId = filePart[0];
const cardName = filePart[0]; const cardName = filePart[0];
const card = new Card(cardId, cardName, CardRarity.Bronze, path.join(path.join(process.cwd(), 'cards', series.Path, 'BRONZE', file)), series); const card = new Card(cardId, cardName, CardRarity.Bronze, path.join(path.join(process.cwd(), 'cards', series.Path, 'BRONZE', file)), file, series);
cardsToSave.push(card); cardsToSave.push(card);
} }
@ -76,7 +76,7 @@ export default class CardSetupFunction {
const cardId = filePart[0]; const cardId = filePart[0];
const cardName = filePart[0]; const cardName = filePart[0];
const card = new Card(cardId, cardName, CardRarity.Gold, path.join(path.join(process.cwd(), 'cards', series.Path, 'GOLD', file)), series); const card = new Card(cardId, cardName, CardRarity.Gold, path.join(path.join(process.cwd(), 'cards', series.Path, 'GOLD', file)), file, series);
cardsToSave.push(card); cardsToSave.push(card);
} }
@ -87,7 +87,7 @@ export default class CardSetupFunction {
const cardId = filePart[0]; const cardId = filePart[0];
const cardName = filePart[0]; const cardName = filePart[0];
const card = new Card(cardId, cardName, CardRarity.Legendary, path.join(path.join(process.cwd(), 'cards', series.Path, 'LEGENDARY', file)), series); const card = new Card(cardId, cardName, CardRarity.Legendary, path.join(path.join(process.cwd(), 'cards', series.Path, 'LEGENDARY', file)), file, series);
cardsToSave.push(card); cardsToSave.push(card);
} }
@ -98,7 +98,7 @@ export default class CardSetupFunction {
const cardId = filePart[0]; const cardId = filePart[0];
const cardName = filePart[0]; const cardName = filePart[0];
const card = new Card(cardId, cardName, CardRarity.Silver, path.join(path.join(process.cwd(), 'cards', series.Path, 'SILVER', file)), series); const card = new Card(cardId, cardName, CardRarity.Silver, path.join(path.join(process.cwd(), 'cards', series.Path, 'SILVER', file)), file, series);
cardsToSave.push(card); cardsToSave.push(card);
} }

View file

@ -1,27 +1,41 @@
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, EmbedBuilder } from "discord.js"; import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, DiscordAPIError, EmbedBuilder } from "discord.js";
import { ButtonEvent } from "../type/buttonEvent"; import { ButtonEvent } from "../type/buttonEvent";
import CardDropHelper from "../helpers/CardDropHelper"; import CardDropHelper from "../helpers/CardDropHelper";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity"; import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
import { v4 } from "uuid"; import { v4 } from "uuid";
import { CoreClient } from "../client/client"; import { CoreClient } from "../client/client";
import Card from "../database/entities/card/Card";
export default class Reroll extends ButtonEvent { export default class Reroll extends ButtonEvent {
public override async execute(interaction: ButtonInteraction) { public override async execute(interaction: ButtonInteraction) {
if (!interaction.guild || !interaction.guildId) return; if (!interaction.guild || !interaction.guildId) return;
const randomCard = await CardDropHelper.GetRandomCard(); let randomCard = await CardDropHelper.GetRandomCard();
if (process.env.DROP_RARITY && Number(process.env.DROP_RARITY) > 0) {
randomCard = await CardDropHelper.GetRandomCardByRarity(Number(process.env.DROP_RARITY));
} else if (process.env.DROP_CARD && process.env.DROP_CARD != '-1') {
let card = await Card.FetchOneByCardNumber(process.env.DROP_CARD, [ "Series" ]);
if (!card) {
await interaction.reply("Card not found");
return;
}
randomCard = card;
}
const image = readFileSync(randomCard.Path); const image = readFileSync(randomCard.Path);
const attachment = new AttachmentBuilder(image, { name: `${randomCard.Id}.png` }); const attachment = new AttachmentBuilder(image, { name: randomCard.FileName });
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(randomCard.Name) .setTitle(randomCard.Name)
.setDescription(randomCard.Series.Name) .setDescription(randomCard.Series.Name)
.setFooter({ text: CardRarityToString(randomCard.Rarity) }) .setFooter({ text: CardRarityToString(randomCard.Rarity) })
.setColor(CardRarityToColour(randomCard.Rarity)) .setColor(CardRarityToColour(randomCard.Rarity))
.setImage(`attachment://${randomCard.Id}.png`); .setImage(`attachment://${randomCard.FileName}`);
const row = new ActionRowBuilder<ButtonBuilder>(); const row = new ActionRowBuilder<ButtonBuilder>();
@ -37,11 +51,22 @@ export default class Reroll extends ButtonEvent {
.setLabel("Reroll") .setLabel("Reroll")
.setStyle(ButtonStyle.Secondary)); .setStyle(ButtonStyle.Secondary));
await interaction.reply({ try {
await interaction.editReply({
embeds: [ embed ], embeds: [ embed ],
files: [ attachment ], files: [ attachment ],
components: [ row ], components: [ row ],
}); });
} catch (e) {
console.error(e);
if (e instanceof DiscordAPIError) {
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
} else {
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`);
}
}
CoreClient.ClaimId = claimId; CoreClient.ClaimId = claimId;
} }

View file

@ -1,10 +1,11 @@
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js"; import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, DiscordAPIError, EmbedBuilder, SlashCommandBuilder } from "discord.js";
import { Command } from "../type/command"; import { Command } from "../type/command";
import CardDropHelper from "../helpers/CardDropHelper"; import CardDropHelper from "../helpers/CardDropHelper";
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity"; import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
import { CoreClient } from "../client/client"; import { CoreClient } from "../client/client";
import { v4 } from "uuid"; import { v4 } from "uuid";
import Card from "../database/entities/card/Card";
export default class Drop extends Command { export default class Drop extends Command {
constructor() { constructor() {
@ -16,18 +17,33 @@ export default class Drop extends Command {
} }
public override async execute(interaction: CommandInteraction) { public override async execute(interaction: CommandInteraction) {
const randomCard = await CardDropHelper.GetRandomCard(); let randomCard = await CardDropHelper.GetRandomCard();
if (process.env.DROP_RARITY && Number(process.env.DROP_RARITY) > 0) {
randomCard = await CardDropHelper.GetRandomCardByRarity(Number(process.env.DROP_RARITY));
} else if (process.env.DROP_CARD && process.env.DROP_CARD != '-1') {
let card = await Card.FetchOneByCardNumber(process.env.DROP_CARD, [ "Series" ]);
if (!card) {
await interaction.reply("Card not found");
return;
}
randomCard = card;
}
const image = readFileSync(randomCard.Path); const image = readFileSync(randomCard.Path);
const attachment = new AttachmentBuilder(image, { name: `${randomCard.Id}.png` }); await interaction.deferReply();
const attachment = new AttachmentBuilder(image, { name: randomCard.FileName });
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(randomCard.Name) .setTitle(randomCard.Name)
.setDescription(randomCard.Series.Name) .setDescription(randomCard.Series.Name)
.setFooter({ text: CardRarityToString(randomCard.Rarity) }) .setFooter({ text: CardRarityToString(randomCard.Rarity) })
.setColor(CardRarityToColour(randomCard.Rarity)) .setColor(CardRarityToColour(randomCard.Rarity))
.setImage(`attachment://${randomCard.Id}.png`); .setImage(`attachment://${randomCard.FileName}`);
const row = new ActionRowBuilder<ButtonBuilder>(); const row = new ActionRowBuilder<ButtonBuilder>();
@ -43,11 +59,23 @@ export default class Drop extends Command {
.setLabel("Reroll") .setLabel("Reroll")
.setStyle(ButtonStyle.Secondary)); .setStyle(ButtonStyle.Secondary));
await interaction.reply({ try {
await interaction.editReply({
embeds: [ embed ], embeds: [ embed ],
files: [ attachment ], files: [ attachment ],
components: [ row ], components: [ row ],
}); });
} catch (e) {
console.error(e);
if (e instanceof DiscordAPIError) {
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`);
} else {
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`);
}
}
CoreClient.ClaimId = claimId; CoreClient.ClaimId = claimId;
} }

View file

@ -2,21 +2,23 @@ import { Column, Entity, ManyToOne } from "typeorm";
import CardBaseEntity from "../../../contracts/CardBaseEntity"; import CardBaseEntity from "../../../contracts/CardBaseEntity";
import { CardRarity } from "../../../constants/CardRarity"; import { CardRarity } from "../../../constants/CardRarity";
import Series from "./Series"; import Series from "./Series";
import CardDataSource from "../../dataSources/cardDataSource";
@Entity() @Entity()
export default class Card extends CardBaseEntity { export default class Card extends CardBaseEntity {
constructor(cardNumber: string, name: string, rarity: CardRarity, path: string, series: Series) { constructor(cardNumber: string, name: string, rarity: CardRarity, path: string, fileName: string, series: Series) {
super(); super();
this.CardNumber = cardNumber; this.CardNumber = cardNumber;
this.Name = name; this.Name = name;
this.Rarity = rarity; this.Rarity = rarity;
this.Path = path; this.Path = path;
this.FileName = fileName;
this.Series = series; this.Series = series;
} }
@Column() @Column()
CardNumber: string CardNumber: string;
@Column() @Column()
Name: string; Name: string;
@ -25,8 +27,27 @@ export default class Card extends CardBaseEntity {
Rarity: CardRarity; Rarity: CardRarity;
@Column() @Column()
Path: string Path: string;
@Column()
FileName: string;
@ManyToOne(() => Series, x => x.Cards) @ManyToOne(() => Series, x => x.Cards)
Series: Series; Series: Series;
public static async FetchOneByCardNumber(cardNumber: string, relations?: string[]): Promise<Card | null> {
const repository = CardDataSource.getRepository(Card);
const single = await repository.findOne({ where: { CardNumber: cardNumber }, relations: relations || [] });
return single;
}
public static async FetchAllByRarity(rarity: CardRarity, relations?: string[]): Promise<Card[]> {
const repository = CardDataSource.getRepository(Card);
const all = await repository.find({ where: { Rarity: rarity }, relations: relations || [] });
return all;
}
} }

View file

@ -1,12 +1,9 @@
import { CardRarity } from "../constants/CardRarity"; import { CardRarity } from "../constants/CardRarity";
import CardDataSource from "../database/dataSources/cardDataSource";
import Card from "../database/entities/card/Card"; import Card from "../database/entities/card/Card";
import Series from "../database/entities/card/Series"; import Series from "../database/entities/card/Series";
export default class CardDropHelper { export default class CardDropHelper {
public static async GetRandomCard(): Promise<Card> { public static async GetRandomCard(): Promise<Card> {
const seriesRepository = CardDataSource.getRepository(Series);
const allSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]); const allSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]);
const allSeriesWithCards = allSeries.filter(x => x.Cards.length > 0); const allSeriesWithCards = allSeries.filter(x => x.Cards.length > 0);
@ -27,7 +24,7 @@ export default class CardDropHelper {
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold; else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
else cardRarity = CardRarity.Legendary; else cardRarity = CardRarity.Legendary;
const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity); const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity && x.Path && x.FileName);
const randomCardIndex = Math.floor(Math.random() * allCards.length); const randomCardIndex = Math.floor(Math.random() * allCards.length);
@ -35,4 +32,14 @@ export default class CardDropHelper {
return randomCard; return randomCard;
} }
public static async GetRandomCardByRarity(rarity: CardRarity): Promise<Card> {
const allCards = await Card.FetchAllByRarity(rarity, [ "Series" ]);
const randomCardIndex = Math.floor(Math.random() * allCards.length);
const card = allCards[randomCardIndex];
return card;
}
} }