This commit is contained in:
parent
1be9ba23a3
commit
9fce79579b
4 changed files with 38 additions and 1 deletions
|
@ -7,7 +7,10 @@ export default class Effects extends Command {
|
||||||
|
|
||||||
this.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName("effects")
|
.setName("effects")
|
||||||
.setDescription("Effects");
|
.setDescription("Effects")
|
||||||
|
.addSubcommand(x => x
|
||||||
|
.setName("list")
|
||||||
|
.setDescription("List all effects I have"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(interaction: CommandInteraction) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
|
|
@ -57,4 +57,19 @@ export default class UserEffect extends AppBaseEntity {
|
||||||
|
|
||||||
return single;
|
return single;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async FetchAllByUserIdPaginated(userId: string, page: number = 0): Promise<UserEffect[]> {
|
||||||
|
const itemsPerPage = 10;
|
||||||
|
|
||||||
|
const repository = AppDataSource.getRepository(UserEffect);
|
||||||
|
|
||||||
|
const all = await repository.find({
|
||||||
|
where: { UserId: userId },
|
||||||
|
order: { Name: "ASC" },
|
||||||
|
skip: page * itemsPerPage,
|
||||||
|
take: itemsPerPage,
|
||||||
|
});
|
||||||
|
|
||||||
|
return all;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
import {EmbedBuilder} from "discord.js";
|
||||||
import UserEffect from "../database/entities/app/UserEffect";
|
import UserEffect from "../database/entities/app/UserEffect";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -46,4 +48,21 @@ export default class EffectHelper {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async GenerateEffectEmbed(userId: string, page: number): Promise<EmbedBuilder> {
|
||||||
|
const effects = await UserEffect.FetchAllByUserIdPaginated(userId, page - 1);
|
||||||
|
|
||||||
|
let description = "*none*";
|
||||||
|
|
||||||
|
if (effects.length > 0) {
|
||||||
|
description = effects.map(x => `${x.Name} x${x.Unused}`).join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle("Effects")
|
||||||
|
.setDescription(description)
|
||||||
|
.setColor(EmbedColours.Ok);
|
||||||
|
|
||||||
|
return embed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue