Compare commits
No commits in common. "58c77dba2162a76dda81fc346a6fd2ce9a2c8bcd" and "92ef0041ff07919c2835a06d5593bcfbb6770129" have entirely different histories.
58c77dba21
...
92ef0041ff
9 changed files with 33 additions and 123 deletions
5
.dev.env
5
.dev.env
|
@ -7,7 +7,7 @@
|
|||
# any secret values.
|
||||
|
||||
BOT_TOKEN=
|
||||
BOT_VER=0.1.1 DEV
|
||||
BOT_VER=0.1.0 DEV
|
||||
BOT_AUTHOR=Vylpes
|
||||
BOT_OWNERID=147392775707426816
|
||||
BOT_CLIENTID=682942374040961060
|
||||
|
@ -15,9 +15,6 @@ BOT_CLIENTID=682942374040961060
|
|||
ABOUT_FUNDING=
|
||||
ABOUT_REPO=
|
||||
|
||||
DROP_RARITY=-1
|
||||
DROP_CARD=-1
|
||||
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3301
|
||||
DB_NAME=carddrop
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
# any secret values.
|
||||
|
||||
BOT_TOKEN=
|
||||
BOT_VER=0.1.1
|
||||
BOT_VER=0.1.0
|
||||
BOT_AUTHOR=Vylpes
|
||||
BOT_OWNERID=147392775707426816
|
||||
BOT_CLIENTID=1093810443589529631
|
||||
|
@ -15,9 +15,6 @@ BOT_CLIENTID=1093810443589529631
|
|||
ABOUT_FUNDING=
|
||||
ABOUT_REPO=
|
||||
|
||||
DROP_RARITY=-1
|
||||
DROP_CARD=-1
|
||||
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3321
|
||||
DB_NAME=carddrop
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
# any secret values.
|
||||
|
||||
BOT_TOKEN=
|
||||
BOT_VER=0.1.1 BETA
|
||||
BOT_VER=0.1.0 BETA
|
||||
BOT_AUTHOR=Vylpes
|
||||
BOT_OWNERID=147392775707426816
|
||||
BOT_CLIENTID=1147976642942214235
|
||||
|
@ -15,9 +15,6 @@ BOT_CLIENTID=1147976642942214235
|
|||
ABOUT_FUNDING=
|
||||
ABOUT_REPO=
|
||||
|
||||
DROP_RARITY=-1
|
||||
DROP_CARD=-1
|
||||
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3311
|
||||
DB_NAME=carddrop
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "card-drop",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.0",
|
||||
"main": "./dist/bot.js",
|
||||
"typings": "./dist",
|
||||
"scripts": {
|
||||
|
|
|
@ -65,7 +65,7 @@ export default class CardSetupFunction {
|
|||
const cardId = 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)), file, series);
|
||||
const card = new Card(cardId, cardName, CardRarity.Bronze, path.join(path.join(process.cwd(), 'cards', series.Path, 'BRONZE', file)), series);
|
||||
|
||||
cardsToSave.push(card);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ export default class CardSetupFunction {
|
|||
const cardId = 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)), file, series);
|
||||
const card = new Card(cardId, cardName, CardRarity.Gold, path.join(path.join(process.cwd(), 'cards', series.Path, 'GOLD', file)), series);
|
||||
|
||||
cardsToSave.push(card);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ export default class CardSetupFunction {
|
|||
const cardId = 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)), file, series);
|
||||
const card = new Card(cardId, cardName, CardRarity.Legendary, path.join(path.join(process.cwd(), 'cards', series.Path, 'LEGENDARY', file)), series);
|
||||
|
||||
cardsToSave.push(card);
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ export default class CardSetupFunction {
|
|||
const cardId = 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)), file, series);
|
||||
const card = new Card(cardId, cardName, CardRarity.Silver, path.join(path.join(process.cwd(), 'cards', series.Path, 'SILVER', file)), series);
|
||||
|
||||
cardsToSave.push(card);
|
||||
}
|
||||
|
|
|
@ -1,41 +1,27 @@
|
|||
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, DiscordAPIError, EmbedBuilder } from "discord.js";
|
||||
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, EmbedBuilder } from "discord.js";
|
||||
import { ButtonEvent } from "../type/buttonEvent";
|
||||
import CardDropHelper from "../helpers/CardDropHelper";
|
||||
import { readFileSync } from "fs";
|
||||
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
||||
import { v4 } from "uuid";
|
||||
import { CoreClient } from "../client/client";
|
||||
import Card from "../database/entities/card/Card";
|
||||
|
||||
export default class Reroll extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
if (!interaction.guild || !interaction.guildId) return;
|
||||
|
||||
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 randomCard = await CardDropHelper.GetRandomCard();
|
||||
|
||||
const image = readFileSync(randomCard.Path);
|
||||
|
||||
const attachment = new AttachmentBuilder(image, { name: randomCard.FileName });
|
||||
const attachment = new AttachmentBuilder(image, { name: `${randomCard.Id}.png` });
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(randomCard.Name)
|
||||
.setDescription(randomCard.Series.Name)
|
||||
.setFooter({ text: CardRarityToString(randomCard.Rarity) })
|
||||
.setColor(CardRarityToColour(randomCard.Rarity))
|
||||
.setImage(`attachment://${randomCard.FileName}`);
|
||||
.setImage(`attachment://${randomCard.Id}.png`);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
||||
|
||||
|
@ -51,22 +37,11 @@ export default class Reroll extends ButtonEvent {
|
|||
.setLabel("Reroll")
|
||||
.setStyle(ButtonStyle.Secondary));
|
||||
|
||||
try {
|
||||
await interaction.editReply({
|
||||
await interaction.reply({
|
||||
embeds: [ embed ],
|
||||
files: [ attachment ],
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, DiscordAPIError, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||
import { Command } from "../type/command";
|
||||
import CardDropHelper from "../helpers/CardDropHelper";
|
||||
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
||||
import { readFileSync } from "fs";
|
||||
import { CoreClient } from "../client/client";
|
||||
import { v4 } from "uuid";
|
||||
import Card from "../database/entities/card/Card";
|
||||
|
||||
export default class Drop extends Command {
|
||||
constructor() {
|
||||
|
@ -17,33 +16,18 @@ export default class Drop extends Command {
|
|||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction) {
|
||||
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 randomCard = await CardDropHelper.GetRandomCard();
|
||||
|
||||
const image = readFileSync(randomCard.Path);
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
const attachment = new AttachmentBuilder(image, { name: randomCard.FileName });
|
||||
const attachment = new AttachmentBuilder(image, { name: `${randomCard.Id}.png` });
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(randomCard.Name)
|
||||
.setDescription(randomCard.Series.Name)
|
||||
.setFooter({ text: CardRarityToString(randomCard.Rarity) })
|
||||
.setColor(CardRarityToColour(randomCard.Rarity))
|
||||
.setImage(`attachment://${randomCard.FileName}`);
|
||||
.setImage(`attachment://${randomCard.Id}.png`);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
||||
|
||||
|
@ -59,23 +43,11 @@ export default class Drop extends Command {
|
|||
.setLabel("Reroll")
|
||||
.setStyle(ButtonStyle.Secondary));
|
||||
|
||||
try {
|
||||
await interaction.editReply({
|
||||
await interaction.reply({
|
||||
embeds: [ embed ],
|
||||
files: [ attachment ],
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -2,23 +2,21 @@ import { Column, Entity, ManyToOne } from "typeorm";
|
|||
import CardBaseEntity from "../../../contracts/CardBaseEntity";
|
||||
import { CardRarity } from "../../../constants/CardRarity";
|
||||
import Series from "./Series";
|
||||
import CardDataSource from "../../dataSources/cardDataSource";
|
||||
|
||||
@Entity()
|
||||
export default class Card extends CardBaseEntity {
|
||||
constructor(cardNumber: string, name: string, rarity: CardRarity, path: string, fileName: string, series: Series) {
|
||||
constructor(cardNumber: string, name: string, rarity: CardRarity, path: string, series: Series) {
|
||||
super();
|
||||
|
||||
this.CardNumber = cardNumber;
|
||||
this.Name = name;
|
||||
this.Rarity = rarity;
|
||||
this.Path = path;
|
||||
this.FileName = fileName;
|
||||
this.Series = series;
|
||||
}
|
||||
|
||||
@Column()
|
||||
CardNumber: string;
|
||||
CardNumber: string
|
||||
|
||||
@Column()
|
||||
Name: string;
|
||||
|
@ -27,27 +25,8 @@ export default class Card extends CardBaseEntity {
|
|||
Rarity: CardRarity;
|
||||
|
||||
@Column()
|
||||
Path: string;
|
||||
|
||||
@Column()
|
||||
FileName: string;
|
||||
Path: string
|
||||
|
||||
@ManyToOne(() => Series, x => x.Cards)
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
import { CardRarity } from "../constants/CardRarity";
|
||||
import CardDataSource from "../database/dataSources/cardDataSource";
|
||||
import Card from "../database/entities/card/Card";
|
||||
import Series from "../database/entities/card/Series";
|
||||
|
||||
export default class CardDropHelper {
|
||||
public static async GetRandomCard(): Promise<Card> {
|
||||
const seriesRepository = CardDataSource.getRepository(Series);
|
||||
|
||||
const allSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]);
|
||||
const allSeriesWithCards = allSeries.filter(x => x.Cards.length > 0);
|
||||
|
||||
|
@ -24,7 +27,7 @@ export default class CardDropHelper {
|
|||
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
||||
else cardRarity = CardRarity.Legendary;
|
||||
|
||||
const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity && x.Path && x.FileName);
|
||||
const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity);
|
||||
|
||||
const randomCardIndex = Math.floor(Math.random() * allCards.length);
|
||||
|
||||
|
@ -32,14 +35,4 @@ export default class CardDropHelper {
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue