Make moon count come from user setting table
All checks were successful
Test / build (push) Successful in 6s
All checks were successful
Test / build (push) Successful in 6s
This commit is contained in:
parent
9d6c2d1bb2
commit
476ff7cfc4
3 changed files with 21 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
import {ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, EmbedBuilder} from "discord.js";
|
import {ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, EmbedBuilder} from "discord.js";
|
||||||
import Moon from "../../database/entities/304276391837302787/Moon";
|
import Moon from "../../database/entities/304276391837302787/Moon";
|
||||||
import EmbedColours from "../../constants/EmbedColours";
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
|
import UserSetting from "../../database/entities/UserSetting";
|
||||||
|
|
||||||
export default async function List(interaction: ButtonInteraction) {
|
export default async function List(interaction: ButtonInteraction) {
|
||||||
if (!interaction.guild) return;
|
if (!interaction.guild) return;
|
||||||
|
@ -23,6 +24,9 @@ export default async function List(interaction: ButtonInteraction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const moonSetting = await UserSetting.FetchOneByKey(userId, "moons");
|
||||||
|
const totalMoons = moonSetting && Number(moonSetting.Value) ? Number(moonSetting.Value) : 0;
|
||||||
|
|
||||||
const totalPages = Math.ceil(moons[1] / pageLength);
|
const totalPages = Math.ceil(moons[1] / pageLength);
|
||||||
|
|
||||||
const description = moons[0].flatMap(x => `**${x.MoonNumber} -** ${x.Description.slice(0, 15)}`);
|
const description = moons[0].flatMap(x => `**${x.MoonNumber} -** ${x.Description.slice(0, 15)}`);
|
||||||
|
@ -31,7 +35,7 @@ export default async function List(interaction: ButtonInteraction) {
|
||||||
.setTitle(`${member?.user.username}'s Moons`)
|
.setTitle(`${member?.user.username}'s Moons`)
|
||||||
.setColor(EmbedColours.Ok)
|
.setColor(EmbedColours.Ok)
|
||||||
.setDescription(description.join("\n"))
|
.setDescription(description.join("\n"))
|
||||||
.setFooter({ text: `Page ${page + 1} of ${totalPages} · ${moons[1]} moons` });
|
.setFooter({ text: `Page ${pageNumber + 1} of ${totalPages} · ${totalMoons} moons` });
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {CommandInteraction, EmbedBuilder} from "discord.js";
|
import {CommandInteraction, EmbedBuilder} from "discord.js";
|
||||||
import Moon from "../../../database/entities/304276391837302787/Moon";
|
import Moon from "../../../database/entities/304276391837302787/Moon";
|
||||||
import EmbedColours from "../../../constants/EmbedColours";
|
import EmbedColours from "../../../constants/EmbedColours";
|
||||||
|
import UserSetting from "../../../database/entities/UserSetting";
|
||||||
|
|
||||||
export default async function AddMoon(interaction: CommandInteraction) {
|
export default async function AddMoon(interaction: CommandInteraction) {
|
||||||
const description = interaction.options.get("description", true).value?.toString();
|
const description = interaction.options.get("description", true).value?.toString();
|
||||||
|
@ -10,7 +11,16 @@ export default async function AddMoon(interaction: CommandInteraction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const moonCount = await Moon.FetchMoonCountByUserId(interaction.user.id);
|
let moonSetting = await UserSetting.FetchOneByKey(interaction.user.id, "moons");
|
||||||
|
const moonCount = moonSetting && Number(moonSetting.Value) ? Number(moonSetting.Value) : 0;
|
||||||
|
|
||||||
|
if (moonSetting) {
|
||||||
|
moonSetting.UpdateValue(`${moonCount + 1}`);
|
||||||
|
} else {
|
||||||
|
moonSetting = new UserSetting(interaction.user.id, "moons", `${moonCount + 1}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await moonSetting.Save(UserSetting, moonSetting);
|
||||||
|
|
||||||
const moon = new Moon(moonCount + 1, description, interaction.user.id);
|
const moon = new Moon(moonCount + 1, description, interaction.user.id);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder} from "discord.js";
|
import {ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder} from "discord.js";
|
||||||
import Moon from "../../../database/entities/304276391837302787/Moon";
|
import Moon from "../../../database/entities/304276391837302787/Moon";
|
||||||
import EmbedColours from "../../../constants/EmbedColours";
|
import EmbedColours from "../../../constants/EmbedColours";
|
||||||
|
import UserSetting from "../../../database/entities/UserSetting";
|
||||||
|
|
||||||
export default async function ListMoons(interaction: CommandInteraction) {
|
export default async function ListMoons(interaction: CommandInteraction) {
|
||||||
const user = interaction.options.get("user")?.user ?? interaction.user;
|
const user = interaction.options.get("user")?.user ?? interaction.user;
|
||||||
|
@ -15,6 +16,9 @@ export default async function ListMoons(interaction: CommandInteraction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const moonSetting = await UserSetting.FetchOneByKey(interaction.user.id, "moons");
|
||||||
|
const totalMoons = moonSetting && Number(moonSetting.Value) ? Number(moonSetting.Value) : 0;
|
||||||
|
|
||||||
const totalPages = Math.ceil(moons[1] / pageLength);
|
const totalPages = Math.ceil(moons[1] / pageLength);
|
||||||
|
|
||||||
const description = moons[0].flatMap(x => `**${x.MoonNumber} -** ${x.Description.slice(0, 15)}`);
|
const description = moons[0].flatMap(x => `**${x.MoonNumber} -** ${x.Description.slice(0, 15)}`);
|
||||||
|
@ -23,7 +27,7 @@ export default async function ListMoons(interaction: CommandInteraction) {
|
||||||
.setTitle(`${user.username}'s Moons`)
|
.setTitle(`${user.username}'s Moons`)
|
||||||
.setColor(EmbedColours.Ok)
|
.setColor(EmbedColours.Ok)
|
||||||
.setDescription(description.join("\n"))
|
.setDescription(description.join("\n"))
|
||||||
.setFooter({ text: `Page ${page + 1} of ${totalPages} · ${moons[1]} moons` });
|
.setFooter({ text: `Page ${page + 1} of ${totalPages} · ${totalMoons} moons` });
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
|
|
Loading…
Reference in a new issue