Compare commits
No commits in common. "d874cb7a12b16e2ad693f097f2b9bacab5c2eafd" and "f8b013a091f4f5df2aa699c774cd637cbb81d979" have entirely different histories.
d874cb7a12
...
f8b013a091
5 changed files with 30 additions and 105 deletions
|
@ -1,7 +1,6 @@
|
||||||
import {ButtonInteraction,EmbedBuilder} from "discord.js";
|
import {ButtonInteraction} from "discord.js";
|
||||||
import {ButtonEvent} from "../type/buttonEvent";
|
import {ButtonEvent} from "../type/buttonEvent";
|
||||||
import EffectHelper from "../helpers/EffectHelper";
|
import EffectHelper from "../helpers/EffectHelper";
|
||||||
import { EffectDetails } from "../constants/EffectDetails";
|
|
||||||
|
|
||||||
export default class Effects extends ButtonEvent {
|
export default class Effects extends ButtonEvent {
|
||||||
public override async execute(interaction: ButtonInteraction) {
|
public override async execute(interaction: ButtonInteraction) {
|
||||||
|
@ -11,9 +10,6 @@ export default class Effects extends ButtonEvent {
|
||||||
case "list":
|
case "list":
|
||||||
await this.List(interaction);
|
await this.List(interaction);
|
||||||
break;
|
break;
|
||||||
case "use":
|
|
||||||
await this.Use(interaction);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,53 +30,4 @@ export default class Effects extends ButtonEvent {
|
||||||
components: [ result.row ],
|
components: [ result.row ],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Use(interaction: ButtonInteraction) {
|
|
||||||
const subaction = interaction.customId.split(" ")[2];
|
|
||||||
|
|
||||||
switch (subaction) {
|
|
||||||
case "confirm":
|
|
||||||
await this.UseConfirm(interaction);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async UseConfirm(interaction: ButtonInteraction) {
|
|
||||||
const id = interaction.customId.split(" ")[3];
|
|
||||||
|
|
||||||
const effectDetail = EffectDetails.get(id);
|
|
||||||
|
|
||||||
if (!effectDetail) {
|
|
||||||
await interaction.reply("Unable to find effect!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const now = new Date();
|
|
||||||
const whenExpires = new Date(now.getMilliseconds() + effectDetail.duration);
|
|
||||||
|
|
||||||
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!")
|
|
||||||
.addFields([
|
|
||||||
{
|
|
||||||
name: "Effect",
|
|
||||||
value: effectDetail.friendlyName,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Expires",
|
|
||||||
value: `<t:${whenExpires.getMilliseconds()}:f>`,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
await interaction.update({ embeds: [ embed ] });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ import {CommandInteraction, EmbedBuilder, SlashCommandBuilder} from "discord.js"
|
||||||
import {Command} from "../type/command";
|
import {Command} from "../type/command";
|
||||||
import EffectHelper from "../helpers/EffectHelper";
|
import EffectHelper from "../helpers/EffectHelper";
|
||||||
import {EffectDetails} from "../constants/EffectDetails";
|
import {EffectDetails} from "../constants/EffectDetails";
|
||||||
import UserEffect from "../database/entities/app/UserEffect";
|
|
||||||
|
|
||||||
export default class Effects extends Command {
|
export default class Effects extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -68,16 +67,15 @@ export default class Effects extends Command {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const canUseEffect = await EffectHelper.CanUseEffect(interaction.user.id, id)
|
const now = new Date();
|
||||||
|
const whenExpires = new Date(now.getMilliseconds() + effectDetail.duration);
|
||||||
|
|
||||||
if (!canUseEffect) {
|
const result = await EffectHelper.UseEffect(interaction.user.id, id, whenExpires);
|
||||||
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (result) {
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("Effect Confirmation")
|
.setTitle("Effect Used")
|
||||||
.setDescription("Would you like to use this effect?")
|
.setDescription("You now have an active effect!")
|
||||||
.addFields([
|
.addFields([
|
||||||
{
|
{
|
||||||
name: "Effect",
|
name: "Effect",
|
||||||
|
@ -85,12 +83,16 @@ export default class Effects extends Command {
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Length",
|
name: "Expires",
|
||||||
value: "",
|
value: `<t:${whenExpires.getMilliseconds()}:f>`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await interaction.reply({ embeds: [ embed ] });
|
await interaction.reply({ embeds: [ embed ] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,15 @@ 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, cooldown: number) {
|
constructor(id: string, friendlyName: string, duration: number, cost: 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", 10 * 60 * 1000, 100, 3 * 60 * 60 * 1000) ],
|
[ "unclaimed", new EffectDetail("unclaimed", "Unclaimed Chance Up", 24 * 60 * 60 * 1000, 100) ],
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
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) {
|
||||||
|
@ -17,22 +16,6 @@ export default class EffectHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async UseEffect(userId: string, name: string, whenExpires: Date): Promise<boolean> {
|
public static async UseEffect(userId: string, name: string, whenExpires: Date): Promise<boolean> {
|
||||||
const canUseEffect = await this.CanUseEffect(userId, name);
|
|
||||||
|
|
||||||
if (!canUseEffect) return false;
|
|
||||||
|
|
||||||
const effect = await UserEffect.FetchOneByUserIdAndName(userId, name);
|
|
||||||
|
|
||||||
if (!effect) return false;
|
|
||||||
|
|
||||||
effect.UseEffect(whenExpires);
|
|
||||||
|
|
||||||
await effect.Save(UserEffect, effect);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async CanUseEffect(userId: string, name: string): Promise<boolean> {
|
|
||||||
const effect = await UserEffect.FetchOneByUserIdAndName(userId, name);
|
const effect = await UserEffect.FetchOneByUserIdAndName(userId, name);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
|
@ -40,15 +23,13 @@ export default class EffectHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const effectDetail = EffectDetails.get(effect.Id);
|
if (effect.WhenExpires && now < effect.WhenExpires) {
|
||||||
|
|
||||||
if (!effectDetail) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effect.WhenExpires && now < new Date(effect.WhenExpires.getMilliseconds() + effectDetail.cooldown)) {
|
effect.UseEffect(whenExpires);
|
||||||
return false;
|
|
||||||
}
|
await effect.Save(UserEffect, effect);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,4 @@ export default class TimeLengthInput {
|
||||||
|
|
||||||
return desNumber;
|
return desNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConvertFromMilliseconds(ms: number): TimeLengthInput {
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue