Compare commits
No commits in common. "0bf9096fe8f25c692df2e8dac7000428dc5557dd" and "647e811c6433d5ac732935adc71e3df7ceee0c03" have entirely different histories.
0bf9096fe8
...
647e811c64
7 changed files with 11 additions and 101 deletions
2
.dev.env
2
.dev.env
|
@ -16,6 +16,8 @@ BOT_ENV=4
|
||||||
ABOUT_FUNDING=
|
ABOUT_FUNDING=
|
||||||
ABOUT_REPO=
|
ABOUT_REPO=
|
||||||
|
|
||||||
|
DROP_RARITY=-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
|
||||||
|
|
|
@ -16,6 +16,8 @@ BOT_ENV=1
|
||||||
ABOUT_FUNDING=
|
ABOUT_FUNDING=
|
||||||
ABOUT_REPO=
|
ABOUT_REPO=
|
||||||
|
|
||||||
|
DROP_RARITY=-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
|
||||||
|
|
|
@ -16,6 +16,8 @@ BOT_ENV=2
|
||||||
ABOUT_FUNDING=
|
ABOUT_FUNDING=
|
||||||
ABOUT_REPO=
|
ABOUT_REPO=
|
||||||
|
|
||||||
|
DROP_RARITY=-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
|
||||||
|
|
|
@ -17,7 +17,11 @@ 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));
|
||||||
|
}
|
||||||
|
|
||||||
const image = readFileSync(randomCard.Path);
|
const image = readFileSync(randomCard.Path);
|
||||||
|
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
import { AttachmentBuilder, CacheType, CommandInteraction, DiscordAPIError, SlashCommandBuilder } from "discord.js";
|
|
||||||
import { Command } from "../../type/command";
|
|
||||||
import { CardRarity, CardRarityParse } from "../../constants/CardRarity";
|
|
||||||
import CardDropHelper from "../../helpers/CardDropHelper";
|
|
||||||
import { readFileSync } from "fs";
|
|
||||||
import Inventory from "../../database/entities/app/Inventory";
|
|
||||||
import { v4 } from "uuid";
|
|
||||||
import { CoreClient } from "../../client/client";
|
|
||||||
|
|
||||||
export default class Droprarity extends Command {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
|
||||||
.setName('droprarity')
|
|
||||||
.setDescription('(TEST) Summon a random card of a specific rarity')
|
|
||||||
.addStringOption(x =>
|
|
||||||
x
|
|
||||||
.setName('rarity')
|
|
||||||
.setDescription('The rarity you want to summon')
|
|
||||||
.setRequired(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(interaction: CommandInteraction<CacheType>) {
|
|
||||||
if (!interaction.isChatInputCommand()) return;
|
|
||||||
|
|
||||||
const rarity = interaction.options.get('rarity');
|
|
||||||
|
|
||||||
if (!rarity || !rarity.value) {
|
|
||||||
await interaction.reply('Rarity is required');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const rarityType = CardRarityParse(rarity.value.toString());
|
|
||||||
|
|
||||||
if (rarityType == CardRarity.Unknown) {
|
|
||||||
await interaction.reply('Invalid rarity');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const card = await CardDropHelper.GetRandomCardByRarity(rarityType);
|
|
||||||
|
|
||||||
if (!card) {
|
|
||||||
await interaction.reply('Card not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const image = readFileSync(card.Path);
|
|
||||||
|
|
||||||
await interaction.deferReply();
|
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: card.FileName });
|
|
||||||
|
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.CardNumber);
|
|
||||||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
|
||||||
|
|
||||||
const embed = CardDropHelper.GenerateDropEmbed(card, quantityClaimed || 0);
|
|
||||||
|
|
||||||
const claimId = v4();
|
|
||||||
|
|
||||||
const row = CardDropHelper.GenerateDropButtons(card, claimId, interaction.user.id);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await interaction.editReply({
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -41,21 +41,4 @@ export function CardRarityToColour(rarity: CardRarity): number {
|
||||||
case CardRarity.Manga:
|
case CardRarity.Manga:
|
||||||
return EmbedColours.MangaCard;
|
return EmbedColours.MangaCard;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function CardRarityParse(rarity: string): CardRarity {
|
|
||||||
switch (rarity.toLowerCase()) {
|
|
||||||
case "bronze":
|
|
||||||
return CardRarity.Bronze;
|
|
||||||
case "silver":
|
|
||||||
return CardRarity.Silver;
|
|
||||||
case "gold":
|
|
||||||
return CardRarity.Gold;
|
|
||||||
case "legendary":
|
|
||||||
return CardRarity.Legendary;
|
|
||||||
case "manga":
|
|
||||||
return CardRarity.Manga;
|
|
||||||
default:
|
|
||||||
return CardRarity.Unknown;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -6,7 +6,6 @@ import Drop from "./commands/drop";
|
||||||
|
|
||||||
// Test Command Imports
|
// Test Command Imports
|
||||||
import Dropnumber from "./commands/stage/dropnumber";
|
import Dropnumber from "./commands/stage/dropnumber";
|
||||||
import Droprarity from "./commands/stage/droprarity";
|
|
||||||
|
|
||||||
// Button Event Imports
|
// Button Event Imports
|
||||||
import Claim from "./buttonEvents/Claim";
|
import Claim from "./buttonEvents/Claim";
|
||||||
|
@ -21,7 +20,6 @@ export default class Registry {
|
||||||
|
|
||||||
// Test Commands
|
// Test Commands
|
||||||
CoreClient.RegisterCommand('dropnumber', new Dropnumber(), Environment.Test);
|
CoreClient.RegisterCommand('dropnumber', new Dropnumber(), Environment.Test);
|
||||||
CoreClient.RegisterCommand('droprarity', new Droprarity(), Environment.Test);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegisterEvents() {
|
public static RegisterEvents() {
|
||||||
|
|
Loading…
Reference in a new issue