Compare commits

...

2 commits

Author SHA1 Message Date
476ff7cfc4 Make moon count come from user setting table
All checks were successful
Test / build (push) Successful in 6s
2024-09-27 18:15:23 +01:00
9d6c2d1bb2 Fix SQL 2024-09-27 18:01:00 +01:00
6 changed files with 25 additions and 7 deletions

View file

@ -4,8 +4,5 @@ CREATE TABLE `user_setting` (
`WhenUpdated` datetime NOT NULL, `WhenUpdated` datetime NOT NULL,
`UserId` varchar(255) NOT NULL, `UserId` varchar(255) NOT NULL,
`Key` varchar(255) NOT NULL, `Key` varchar(255) NOT NULL,
`Value` varchar(255) NOT NULL, `Value` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
ALTER TABLE `user_setting`
ADD PRIMARY KEY (`Id`);

View file

@ -0,0 +1,2 @@
ALTER TABLE user_setting
ADD PRIMARY KEY (Id);

View file

@ -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(

View file

@ -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);

View file

@ -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(

View file

@ -6,6 +6,7 @@ export class CreateUserSetting1727286976268 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
MigrationHelper.Up('1727286976268-CreateUserSetting', '3.3.0', [ MigrationHelper.Up('1727286976268-CreateUserSetting', '3.3.0', [
"01-UserSetting", "01-UserSetting",
"02-UserSettingKey",
], queryRunner); ], queryRunner);
} }