Add ability to add a moon to your count #477
7 changed files with 55 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
||||||
import {ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, EmbedBuilder} from "discord.js";
|
import {ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, EmbedBuilder} from "discord.js";
|
||||||
import Moon from "../../database/entities/Moon";
|
import Moon from "../../database/entities/304276391837302787/Moon";
|
||||||
import EmbedColours from "../../constants/EmbedColours";
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
|
|
||||||
export default async function List(interaction: ButtonInteraction) {
|
export default async function List(interaction: ButtonInteraction) {
|
||||||
|
@ -25,7 +25,7 @@ export default async function List(interaction: ButtonInteraction) {
|
||||||
|
|
||||||
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)}`);
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(`${member?.user.username}'s Moons`)
|
.setTitle(`${member?.user.username}'s Moons`)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { Command } from "../../type/command";
|
import { Command } from "../../type/command";
|
||||||
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
import ListMoons from "./moons/list";
|
import ListMoons from "./moons/list";
|
||||||
|
import AddMoon from "./moons/add";
|
||||||
|
|
||||||
export default class Moons extends Command {
|
export default class Moons extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -20,7 +21,16 @@ export default class Moons extends Command {
|
||||||
.addNumberOption(option =>
|
.addNumberOption(option =>
|
||||||
option
|
option
|
||||||
.setName("page")
|
.setName("page")
|
||||||
.setDescription("The page to start with")));
|
.setDescription("The page to start with")))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('add')
|
||||||
|
.setDescription('Add a moon to your count!')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName("description")
|
||||||
|
.setDescription("What deserved a moon?")
|
||||||
|
.setRequired(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(interaction: CommandInteraction) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
@ -30,6 +40,9 @@ export default class Moons extends Command {
|
||||||
case "list":
|
case "list":
|
||||||
await ListMoons(interaction);
|
await ListMoons(interaction);
|
||||||
break;
|
break;
|
||||||
|
case "add":
|
||||||
|
await AddMoon(interaction);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
src/commands/304276391837302787/moons/add.ts
Normal file
26
src/commands/304276391837302787/moons/add.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import {CommandInteraction, EmbedBuilder} from "discord.js";
|
||||||
|
import Moon from "../../../database/entities/304276391837302787/Moon";
|
||||||
|
import EmbedColours from "../../../constants/EmbedColours";
|
||||||
|
|
||||||
|
export default async function AddMoon(interaction: CommandInteraction) {
|
||||||
|
const description = interaction.options.get("description", true).value?.toString();
|
||||||
|
|
||||||
|
if (!description || description.length > 255) {
|
||||||
|
await interaction.reply("Name must be less than 255 characters!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const moonCount = await Moon.FetchMoonCountByUserId(interaction.user.id);
|
||||||
|
|
||||||
|
const moon = new Moon(moonCount + 1, description, interaction.user.id);
|
||||||
|
|
||||||
|
await moon.Save(Moon, moon);
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle(`${interaction.user.globalName} Got A Moon!`)
|
||||||
|
.setColor(EmbedColours.Moon)
|
||||||
|
.setDescription(`**${moon.MoonNumber} -** ${moon.Description}`)
|
||||||
|
.setThumbnail("https://cdn.discordapp.com/emojis/374131312182689793.webp?size=96&quality=lossless");
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [ embed ] });
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import {ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder} from "discord.js";
|
import {ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder} from "discord.js";
|
||||||
import Moon from "../../../database/entities/Moon";
|
import Moon from "../../../database/entities/304276391837302787/Moon";
|
||||||
import EmbedColours from "../../../constants/EmbedColours";
|
import EmbedColours from "../../../constants/EmbedColours";
|
||||||
|
|
||||||
export default async function ListMoons(interaction: CommandInteraction) {
|
export default async function ListMoons(interaction: CommandInteraction) {
|
||||||
|
@ -17,7 +17,7 @@ export default async function ListMoons(interaction: CommandInteraction) {
|
||||||
|
|
||||||
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)}`);
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(`${user.username}'s Moons`)
|
.setTitle(`${user.username}'s Moons`)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export default class EmbedColours {
|
export default class EmbedColours {
|
||||||
public static readonly Ok = 0x3050ba;
|
public static readonly Ok = 0x3050ba;
|
||||||
|
public static readonly Moon = 0x50C878;
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import { Column, Entity, IsNull } from "typeorm";
|
import { Column, Entity, IsNull } from "typeorm";
|
||||||
import BaseEntity from "../../contracts/BaseEntity";
|
import BaseEntity from "../../../contracts/BaseEntity";
|
||||||
import AppDataSource from "../dataSources/appDataSource";
|
import AppDataSource from "../../dataSources/appDataSource";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export default class Moon extends BaseEntity {
|
export default class Moon extends BaseEntity {
|
||||||
|
@ -46,4 +46,12 @@ export default class Moon extends BaseEntity {
|
||||||
|
|
||||||
return moons;
|
return moons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async FetchMoonCountByUserId(userId: string): Promise<number> {
|
||||||
|
const repository = AppDataSource.getRepository(Moon);
|
||||||
|
|
||||||
|
const count = await repository.count({ where: { UserId: userId } });
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4346,11 +4346,6 @@ typescript@^5.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
|
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
|
||||||
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==
|
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==
|
||||||
|
|
||||||
undici-types@~6.13.0:
|
|
||||||
version "6.13.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.13.0.tgz#e3e79220ab8c81ed1496b5812471afd7cf075ea5"
|
|
||||||
integrity sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==
|
|
||||||
|
|
||||||
undici-types@~6.19.2:
|
undici-types@~6.19.2:
|
||||||
version "6.19.8"
|
version "6.19.8"
|
||||||
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
|
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
|
||||||
|
|
Loading…
Reference in a new issue