Version Estable

This commit is contained in:
2025-09-17 13:33:10 -05:00
commit bf6a7e3024
39 changed files with 2537 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { bot } from "../main";
import type { BaseInteraction } from "discord.js";
import { Events } from "discord.js";
import { redis } from "../core/redis";
import { commands } from "../core/loader";
import { buttons, modals, selectmenus } from "../core/components";
bot.on(Events.InteractionCreate, async (interaction: BaseInteraction) => {
try {
// 🔹 Slash commands
if (interaction.isChatInputCommand()) {
const cmd = commands.get(interaction.commandName);
if (!cmd) return;
const cooldown = Math.floor(Number(cmd.cooldown) || 0);
if (cooldown > 0) {
const key = `cooldown:${cmd.name}:${interaction.user.id}`;
const ttl = await redis.ttl(key);
if (ttl > 0) {
return interaction.reply(`⏳ Espera ${ttl}s antes de volver a usar **${cmd.name}**.`);
}
await redis.set(key, "1", { EX: cooldown });
}
await cmd.run(interaction, bot);
}
// 🔹 Botones
if (interaction.isButton()) {
//@ts-ignore
const btn = buttons.get(interaction.customId);
if (btn) await btn.run(interaction, bot);
}
// 🔹 Select menus
if (interaction.isStringSelectMenu()) {
const menu = selectmenus.get(interaction.customId);
if (menu) await menu.run(interaction, bot);
}
// 🔹 Modales
if (interaction.isModalSubmit()) {
const modal = modals.get(interaction.customId);
if (modal) await modal.run(interaction, bot);
}
} catch (error) {
console.error(error);
if (interaction.isRepliable()) {
await interaction.reply({ content: "❌ Hubo un error ejecutando la interacción.", ephemeral: true });
}
}
});

View File

@@ -0,0 +1,40 @@
import {bot} from "../main";
import {Events} from "discord.js";
import {redis} from "../core/redis";
import {commands} from "../core/loader";
bot.on(Events.MessageCreate, async (message) => {
if (message.author.bot) return;
const server = await bot.prisma.guild.findFirst({ where: { id: message.guild!.id } }) || "!";
const PREFIX = server.prefix
if (!message.content.startsWith(PREFIX)) return;
const [cmdName, ...args] = message.content.slice(PREFIX.length).trim().split(/\s+/);
console.log(cmdName);
const command = commands.get(cmdName);
if (!command) return;
const cooldown = Math.floor(Number(command.cooldown) || 0);
if (cooldown > 0) {
const key = `cooldown:${command.name}:${message.author.id}`;
const ttl = await redis.ttl(key);
console.log(`Key: ${key}, TTL: ${ttl}`);
if (ttl > 0) {
return message.reply(`⏳ Espera ${ttl}s antes de volver a usar **${command.name}**.`);
}
// SET con expiración correcta para redis v4+
await redis.set(key, "1", { EX: cooldown });
}
try {
await command.run(message, args, message.client);
} catch (error) {
console.error(error);
await message.reply("❌ Hubo un error ejecutando el comando.");
}
})

6
src/events/ready.ts Normal file
View File

@@ -0,0 +1,6 @@
import {bot} from "../main";
import {Events} from "discord.js";
bot.on(Events.ClientReady, () => {
console.log("Ready!");
})