Split up moon counter from the database #489

Open
Vylpes wants to merge 19 commits from feature/300-moon-set into develop
3 changed files with 27 additions and 8 deletions
Showing only changes of commit 2695219b20 - Show all commits

View file

@ -11,17 +11,16 @@ export default async function ListMoons(interaction: CommandInteraction) {
const moons = await Moon.FetchPaginatedMoonsByUserId(user.id, pageLength, page);
if (!moons || moons[0].length == 0) {
await interaction.reply(`${user.username} does not have any moons or page is invalid.`);
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 description = moons[0].flatMap(x => `**${x.MoonNumber} -** ${x.Description.slice(0, 15)}`);
let description = ["*none*"];
if (moons[0].length > 0) {
description = moons[0].flatMap(x => `**${x.MoonNumber} -** ${x.Description.slice(0, 15)}`);
}
const embed = new EmbedBuilder()
.setTitle(`${user.username}'s Moons`)
@ -40,7 +39,7 @@ export default async function ListMoons(interaction: CommandInteraction) {
.setCustomId(`moons list ${user.id} ${page + 1}`)
.setLabel("Next")
.setStyle(ButtonStyle.Primary)
.setDisabled(page + 1 == totalPages));
.setDisabled(page + 1 == totalPages || moons[0].length == 0));
await interaction.reply({
embeds: [ embed ],

View file

@ -1,6 +1,7 @@
import { CommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
import { CommandInteraction, EmbedBuilder, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
import { Command } from "../../type/command";
import UserSetting from "../../database/entities/UserSetting";
import EmbedColours from "../../constants/EmbedColours";
export default class MoonSet extends Command {
constructor() {
@ -24,5 +25,21 @@ export default class MoonSet extends Command {
public override async execute(interaction: CommandInteraction) {
const user = interaction.options.get("user", true).user!;
const count = interaction.options.get("count", true).value! as number;
let moonSetting = await UserSetting.FetchOneByKey(user.id, "moons");
if (moonSetting) {
moonSetting.UpdateValue(`${count}`);
} else {
moonSetting = new UserSetting(user.id, "moons", `${count}`);
}
await moonSetting.Save(UserSetting, moonSetting);
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setDescription(`Moon count for ${user.username} set to ${count}`);
await interaction.reply({ embeds: [ embed ]});
}
}

View file

@ -31,6 +31,7 @@ import ListLobby from "./commands/501231711271780357/Lobby/list";
// Command Imports: Potato Talk
import Moons from "./commands/304276391837302787/moons";
import MoonSet from "./commands/304276391837302787/moonset";
// Event Imports
import GuildMemberAdd from "./events/MemberEvents/GuildMemberAdd";
@ -76,6 +77,7 @@ export default class Registry {
// Exclusive Commands: Potato Talk
CoreClient.RegisterCommand("moons", new Moons(), "304276391837302787");
CoreClient.RegisterCommand("moonset", new MoonSet(), "304276391837302787");
// Add Exclusive Commands to Test Server
CoreClient.RegisterCommand("lobby", new Lobby(), "442730357897429002");
@ -84,6 +86,7 @@ export default class Registry {
CoreClient.RegisterCommand("listlobby", new ListLobby(), "442730357897429002");
CoreClient.RegisterCommand("entry", new Entry(), "442730357897429002");
CoreClient.RegisterCommand("moons", new Moons(), "442730357897429002");
CoreClient.RegisterCommand("moonset", new MoonSet(), "442730357897429002");
}
public static RegisterEvents() {