Compare commits
No commits in common. "0e1bc43ac444a0f261d362514638b1f9576e0b36" and "9fce79579baee90688064c0375c83f2ccf41519f" have entirely different histories.
0e1bc43ac4
...
9fce79579b
3 changed files with 14 additions and 52 deletions
|
@ -14,17 +14,5 @@ export default class Effects extends Command {
|
|||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
|
||||
switch (subcommand) {
|
||||
case "list":
|
||||
await this.List(interaction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async List(interaction: CommandInteraction) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,17 +58,18 @@ export default class UserEffect extends AppBaseEntity {
|
|||
return single;
|
||||
}
|
||||
|
||||
public static async FetchAllByUserIdPaginated(userId: string, page: number = 0, itemsPerPage: number = 10): Promise<[UserEffect[], number]> {
|
||||
public static async FetchAllByUserIdPaginated(userId: string, page: number = 0): Promise<UserEffect[]> {
|
||||
const itemsPerPage = 10;
|
||||
|
||||
const repository = AppDataSource.getRepository(UserEffect);
|
||||
|
||||
const query = await repository.createQueryBuilder("effect")
|
||||
.where("effect.UserId = :userId", { userId })
|
||||
.where("effect.Unused > 0")
|
||||
.orderBy("effect.Name", "ASC")
|
||||
.skip(page * itemsPerPage)
|
||||
.take(itemsPerPage)
|
||||
.getManyAndCount();
|
||||
const all = await repository.find({
|
||||
where: { UserId: userId },
|
||||
order: { Name: "ASC" },
|
||||
skip: page * itemsPerPage,
|
||||
take: itemsPerPage,
|
||||
});
|
||||
|
||||
return query;
|
||||
return all;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder} from "discord.js";
|
||||
import {EmbedBuilder} from "discord.js";
|
||||
import UserEffect from "../database/entities/app/UserEffect";
|
||||
import EmbedColours from "../constants/EmbedColours";
|
||||
|
||||
|
@ -49,18 +49,8 @@ export default class EffectHelper {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static async GenerateEffectEmbed(userId: string, page: number): Promise<{
|
||||
embed: EmbedBuilder,
|
||||
row: ActionRowBuilder<ButtonBuilder>,
|
||||
}> {
|
||||
const itemsPerPage = 10;
|
||||
|
||||
const query = await UserEffect.FetchAllByUserIdPaginated(userId, page - 1, itemsPerPage);
|
||||
|
||||
const effects = query[0];
|
||||
const count = query[1];
|
||||
|
||||
const isLastPage = Math.ceil(count / itemsPerPage) - 1 == page;
|
||||
public static async GenerateEffectEmbed(userId: string, page: number): Promise<EmbedBuilder> {
|
||||
const effects = await UserEffect.FetchAllByUserIdPaginated(userId, page - 1);
|
||||
|
||||
let description = "*none*";
|
||||
|
||||
|
@ -73,23 +63,6 @@ export default class EffectHelper {
|
|||
.setDescription(description)
|
||||
.setColor(EmbedColours.Ok);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`effects list ${page - 1}`)
|
||||
.setLabel("Previous")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(page == 0),
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`effects list ${page + 1}`)
|
||||
.setLabel("Next")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(isLastPage),
|
||||
);
|
||||
|
||||
return {
|
||||
embed,
|
||||
row,
|
||||
};
|
||||
return embed;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue