Add check for cooldown

This commit is contained in:
Ethan Lane 2024-12-16 19:17:23 +00:00
parent f8b013a091
commit 57c3d603a9
3 changed files with 13 additions and 4 deletions

View file

@ -93,6 +93,6 @@ export default class Effects extends Command {
return; return;
} }
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory"); await interaction.reply("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown");
} }
} }

View file

@ -3,15 +3,17 @@ class EffectDetail {
public readonly friendlyName: string; public readonly friendlyName: string;
public readonly duration: number; public readonly duration: number;
public readonly cost: number; public readonly cost: number;
public readonly cooldown: number;
constructor(id: string, friendlyName: string, duration: number, cost: number) { constructor(id: string, friendlyName: string, duration: number, cost: number, cooldown: number) {
this.id = id; this.id = id;
this.friendlyName = friendlyName; this.friendlyName = friendlyName;
this.duration = duration; this.duration = duration;
this.cost = cost; this.cost = cost;
this.cooldown = cooldown;
} }
}; };
export const EffectDetails = new Map<string, EffectDetail>([ export const EffectDetails = new Map<string, EffectDetail>([
[ "unclaimed", new EffectDetail("unclaimed", "Unclaimed Chance Up", 24 * 60 * 60 * 1000, 100) ], [ "unclaimed", new EffectDetail("unclaimed", "Unclaimed Chance Up", 10 * 60 * 1000, 100, 3 * 60 * 60 * 1000) ],
]); ]);

View file

@ -1,6 +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 UserEffect from "../database/entities/app/UserEffect";
import EmbedColours from "../constants/EmbedColours"; import EmbedColours from "../constants/EmbedColours";
import {EffectDetails} from "../constants/EffectDetails";
export default class EffectHelper { export default class EffectHelper {
public static async AddEffectToUserInventory(userId: string, name: string, quantity: number = 1) { public static async AddEffectToUserInventory(userId: string, name: string, quantity: number = 1) {
@ -23,7 +24,13 @@ export default class EffectHelper {
return false; return false;
} }
if (effect.WhenExpires && now < effect.WhenExpires) { const effectDetail = EffectDetails.get(effect.Id);
if (!effectDetail) {
return false;
}
if (effect.WhenExpires && now < new Date(effect.WhenExpires.getMilliseconds() + effectDetail.cooldown)) {
return false; return false;
} }