This commit is contained in:
parent
31cc9e056a
commit
d794b30bb5
10 changed files with 204 additions and 176 deletions
|
@ -73,6 +73,8 @@ export default class Claim extends ButtonEvent {
|
|||
const card = GetCardsHelper.GetCardByCardNumber(cardNumber);
|
||||
|
||||
if (!card) {
|
||||
AppLogger.LogError("Button/Claim", `Unable to find card, ${cardNumber}`);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { EffectDetails } from "../../constants/EffectDetails";
|
|||
import EffectHelper from "../../helpers/EffectHelper";
|
||||
import EmbedColours from "../../constants/EmbedColours";
|
||||
import TimeLengthInput from "../../helpers/TimeLengthInput";
|
||||
import AppLogger from "../../client/appLogger";
|
||||
|
||||
export default async function Use(interaction: ButtonInteraction) {
|
||||
const subaction = interaction.customId.split(" ")[2];
|
||||
|
@ -23,6 +24,8 @@ export async function UseConfirm(interaction: ButtonInteraction) {
|
|||
const effectDetail = EffectDetails.get(id);
|
||||
|
||||
if (!effectDetail) {
|
||||
AppLogger.LogError("Button/Effects/Use", `Effect not found, ${id}`);
|
||||
|
||||
await interaction.reply("Effect not found in system!");
|
||||
return;
|
||||
}
|
||||
|
@ -33,46 +36,46 @@ export async function UseConfirm(interaction: ButtonInteraction) {
|
|||
|
||||
const result = await EffectHelper.UseEffect(interaction.user.id, id, whenExpires);
|
||||
|
||||
if (result) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Effect Used")
|
||||
.setDescription("You now have an active effect!")
|
||||
.setColor(EmbedColours.Green)
|
||||
.addFields([
|
||||
{
|
||||
name: "Effect",
|
||||
value: effectDetail.friendlyName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Expires",
|
||||
value: `<t:${Math.round(whenExpires.getTime() / 1000)}:f>`,
|
||||
inline: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setLabel("Confirm")
|
||||
.setCustomId(`effects use confirm ${effectDetail.id}`)
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(true),
|
||||
new ButtonBuilder()
|
||||
.setLabel("Cancel")
|
||||
.setCustomId(`effects use cancel ${effectDetail.id}`)
|
||||
.setStyle(ButtonStyle.Danger)
|
||||
.setDisabled(true),
|
||||
]);
|
||||
|
||||
await interaction.update({
|
||||
embeds: [ embed ],
|
||||
components: [ row ],
|
||||
});
|
||||
if (!result) {
|
||||
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown");
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown");
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Effect Used")
|
||||
.setDescription("You now have an active effect!")
|
||||
.setColor(EmbedColours.Green)
|
||||
.addFields([
|
||||
{
|
||||
name: "Effect",
|
||||
value: effectDetail.friendlyName,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Expires",
|
||||
value: `<t:${Math.round(whenExpires.getTime() / 1000)}:f>`,
|
||||
inline: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setLabel("Confirm")
|
||||
.setCustomId(`effects use confirm ${effectDetail.id}`)
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(true),
|
||||
new ButtonBuilder()
|
||||
.setLabel("Cancel")
|
||||
.setCustomId(`effects use cancel ${effectDetail.id}`)
|
||||
.setStyle(ButtonStyle.Danger)
|
||||
.setDisabled(true),
|
||||
]);
|
||||
|
||||
await interaction.update({
|
||||
embeds: [ embed ],
|
||||
components: [ row ],
|
||||
});
|
||||
}
|
||||
|
||||
export async function UseCancel(interaction: ButtonInteraction) {
|
||||
|
@ -81,6 +84,8 @@ export async function UseCancel(interaction: ButtonInteraction) {
|
|||
const effectDetail = EffectDetails.get(id);
|
||||
|
||||
if (!effectDetail) {
|
||||
AppLogger.LogError("Button/Effects/Cancel", `Effect not found, ${id}`);
|
||||
|
||||
await interaction.reply("Effect not found in system!");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder} from "discord.js";
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||
import UserEffect from "../database/entities/app/UserEffect";
|
||||
import EmbedColours from "../constants/EmbedColours";
|
||||
import {EffectDetails} from "../constants/EffectDetails";
|
||||
import { EffectDetails } from "../constants/EffectDetails";
|
||||
|
||||
export default class EffectHelper {
|
||||
public static async AddEffectToUserInventory(userId: string, name: string, quantity: number = 1) {
|
||||
|
@ -23,11 +23,9 @@ export default class EffectHelper {
|
|||
|
||||
const effect = await UserEffect.FetchOneByUserIdAndName(userId, name);
|
||||
|
||||
if (!effect) return false;
|
||||
effect!.UseEffect(whenExpires);
|
||||
|
||||
effect.UseEffect(whenExpires);
|
||||
|
||||
await effect.Save(UserEffect, effect);
|
||||
await effect!.Save(UserEffect, effect!);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue