all repos — stealth-developers @ 3266a1185e40b7607c7d2f6db8992c23b487273c

feat: bug report - numerical ids
willow hai@wlo.moe
Sat, 24 May 2025 21:11:30 +0100
commit

3266a1185e40b7607c7d2f6db8992c23b487273c

parent

db675c1b582931dd7f05060ca75abb92b47c82b8

2 files changed, 29 insertions(+), 6 deletions(-)

jump to
M src/database/schemas.tssrc/database/schemas.ts

@@ -16,7 +16,13 @@ user_id: z.string(),

guild_id: z.string(), }); +const CounterSchema = new Schema({ + _id: String, + sequence_value: { type: Number, default: 0 }, +}); + export const bugSchema = z.object({ + bug_id: z.number(), user_id: z.string(), status: z.enum(["open", "closed"]).default("open"), game: z.enum(["wft", "gw", "ab"]),

@@ -62,6 +68,7 @@ );

const BugSchema = new Schema( { + bug_id: { type: Number, required: true, unique: true }, user_id: { type: String, required: true, ref: "User" }, status: { type: String, enum: ["open", "closed"], default: "open" }, title: { type: String, required: true },

@@ -87,7 +94,18 @@ // compound indexes for better perf

UserSchema.index({ user_id: 1, guild_id: 1 }, { unique: true }); // models -export const GuildModel = model<Guild>("Guild", GuildSchema); -export const UserModel = model<User>("User", UserSchema); -export const BugModel = model<Bug>("Bug", BugSchema); -export const MediaModel = model<Media>("Media", MediaSchema); +export const GuildModel = model<GuildType>("Guild", GuildSchema); +export const UserModel = model<UserType>("User", UserSchema); +export const BugModel = model<BugType>("Bug", BugSchema); +export const MediaModel = model<MediaType>("Media", MediaSchema); +export const CounterModel = model("Counter", CounterSchema); + +// funcs +export async function getNextBugId(): Promise<number> { + const counter = await CounterModel.findByIdAndUpdate( + "bug_id", + { $inc: { sequence_value: 1 } }, + { new: true, upsert: true }, + ); + return counter.sequence_value; +}
M src/interactions/commands/bug.tssrc/interactions/commands/bug.ts

@@ -1,5 +1,7 @@

import { ActionRowBuilder, + ButtonBuilder, + ButtonStyle, ChannelType, type ChatInputCommandInteraction, type Client,

@@ -10,7 +12,7 @@ SlashCommandBuilder,

TextInputBuilder, TextInputStyle, } from "discord.js"; -import { BugModel, GuildModel } from "../../database/schemas.ts"; +import { BugModel, GuildModel, getNextBugId } from "../../database/schemas.ts"; import { createUserIfNotExists } from "../../utils/exists.ts"; import { Logger } from "../../utils/logging.ts";

@@ -106,7 +108,10 @@

try { await createUserIfNotExists(interaction.user.id, interaction.guild.id); + const bugId = await getNextBugId(); + const bug = new BugModel({ + bug_id: bugId, user_id: interaction.user.id, game, title,

@@ -146,7 +151,7 @@ .setThumbnail(gameInfo.iconURL)

.setTitle(title) .setColor(0xff6b6b) .setDescription(description) - .setFooter({ text: gameInfo.name }) + .setFooter({ text: `${gameInfo.name} • bug #${bugId}` }) .setTimestamp(); const message = await channel.send({ embeds: [embed] });