refactor: reorganize project structure and improve user command handling

This commit is contained in:
grngxd 2025-07-31 19:25:31 +01:00
parent 5cfcb3ba0c
commit 49d6b51de6
7 changed files with 64 additions and 26 deletions

7
cmd/index.ts Normal file
View file

@ -0,0 +1,7 @@
import register from "./register";
import user from "./user";
export default [
user,
register
]

18
cmd/register.ts Normal file
View file

@ -0,0 +1,18 @@
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
import { db } from "../db/db";
export const data = new SlashCommandBuilder()
.setName("register")
.setDescription("create your stereo account");
export const execute = async (interaction: ChatInputCommandInteraction) => {
const existingUser = await db.get<{ id: string }>`SELECT id FROM users WHERE id = ${interaction.user.id}`;
if (existingUser) {
await interaction.reply({ content: "You already have a stereo account.", ephemeral: true });
return;
}
await interaction.reply({ content: "Your stereo account has been created!", ephemeral: true });
}
export default [data, execute] as const;

View file

@ -1,16 +1,26 @@
// commands/overview.ts
import { ChatInputCommandInteraction, EmbedBuilder, MessageFlags, SlashCommandBuilder } from "discord.js";
import { db } from "../db";
import { formatSize } from "../lib";
import { StereoFile } from "../types";
import { db } from "../db/db";
import { formatSize } from "../lib/files";
import { StereoFile } from "../types/files";
export const data = new SlashCommandBuilder()
.setName("user")
.addUserOption(option => option.setName("user").setDescription("user to look up").setRequired(false))
.setDescription("get information about a user (or yourself) on stereo");
.setName("user")
.addUserOption(option => option.setName("user").setDescription("user to look up").setRequired(false))
.setDescription("get information about a user (or yourself) on stereo");
export const execute = async (interaction: ChatInputCommandInteraction) => {
const user = interaction.options.getUser("user") || interaction.user;
if (user.id === interaction.client.user?.id) {
await interaction.reply({ content: "hey! stop that!!!!", flags: MessageFlags.Ephemeral });
return;
}
if (user.bot) {
await interaction.reply({ content: "bots can't have stereo accounts...", flags: MessageFlags.Ephemeral });
return;
}
if (!user) {
await interaction.reply({ content: "couldn't find user", flags: MessageFlags.Ephemeral });
return;
@ -18,6 +28,11 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
const id = await db.get<{ id: string }>`SELECT id FROM users WHERE id = ${user.id}`;
if (!id) {
if (user.id === interaction.user.id) {
await interaction.reply({ content: "you don't have a stereo account yet, use the `/register` command to make one", flags: MessageFlags.Ephemeral });
return;
}
await interaction.reply({ content: "this user doesn't have a stereo account", flags: MessageFlags.Ephemeral });
return;
}