diff --git a/src/commands/messages/alliaces/createEmbedv2.ts b/src/commands/messages/alliaces/createDisplayComponent.ts similarity index 99% rename from src/commands/messages/alliaces/createEmbedv2.ts rename to src/commands/messages/alliaces/createDisplayComponent.ts index 6d0b80a..a72916a 100644 --- a/src/commands/messages/alliaces/createEmbedv2.ts +++ b/src/commands/messages/alliaces/createDisplayComponent.ts @@ -227,7 +227,6 @@ const updateEditor = async (msg: any, data: any) => { const payload: any = { ...data }; delete payload.display; payload.components = components; - // Si no se pasa flags explĂ­citos, usamos 32768 como en tu entorno if (payload.flags === undefined) payload.flags = 32768; await msg.edit(payload); }; diff --git a/src/commands/messages/alliaces/embedDelete.ts b/src/commands/messages/alliaces/deleteDisplayComponent.ts similarity index 100% rename from src/commands/messages/alliaces/embedDelete.ts rename to src/commands/messages/alliaces/deleteDisplayComponent.ts diff --git a/src/commands/messages/alliaces/embedList.ts b/src/commands/messages/alliaces/displayComponentList.ts similarity index 100% rename from src/commands/messages/alliaces/embedList.ts rename to src/commands/messages/alliaces/displayComponentList.ts diff --git a/src/commands/messages/alliaces/editEmbedv2.ts b/src/commands/messages/alliaces/editDisplayComponent.ts similarity index 100% rename from src/commands/messages/alliaces/editEmbedv2.ts rename to src/commands/messages/alliaces/editDisplayComponent.ts diff --git a/src/commands/messages/help.ts b/src/commands/messages/help.ts index d29d604..b80b5a8 100644 --- a/src/commands/messages/help.ts +++ b/src/commands/messages/help.ts @@ -1,6 +1,6 @@ // @ts-ignore import { CommandMessage } from "../../../core/types/commands"; -import { commands as registry } from "../../core/loader"; +import { commands as registry } from "../../core/loaders/loader"; export const command: CommandMessage = { name: 'ayuda', diff --git a/src/commands/messages/net/commandsAdmin.ts b/src/commands/messages/net/commandsAdmin.ts index 2b766b4..aa38ec8 100644 --- a/src/commands/messages/net/commandsAdmin.ts +++ b/src/commands/messages/net/commandsAdmin.ts @@ -34,7 +34,7 @@ function buildAdminPanel() { { type: 9, components: [ - { type: 10, content: "<:astar:1336533817296683059> Registrar los comandos '/' dentro del servidor de pruebas" } + { type: 10, content: "<:astar:1336533817296683059> Registrar los comandos **/** dentro del servidor de pruebas" } ], accessory: { type: 2, @@ -47,7 +47,7 @@ function buildAdminPanel() { { type: 9, components: [ - { type: 10, content: "<:astar:1336533817296683059> Registrar los comandos '/' de manera GLOBAL (todos los servidores)" } + { type: 10, content: "<:astar:1336533817296683059> Registrar los comandos **/** de manera GLOBAL (todos los servidores)" } ], accessory: { type: 2, @@ -60,7 +60,7 @@ function buildAdminPanel() { { type: 9, components: [ - { type: 10, content: "<:Sup_urg:1420535068056748042> Eliminar los comandos '/' dentro del servidor de pruebas" } + { type: 10, content: "<:Sup_urg:1420535068056748042> Eliminar los comandos **/** dentro del servidor de pruebas" } ], accessory: { type: 2, @@ -73,7 +73,7 @@ function buildAdminPanel() { { type: 9, components: [ - { type: 10, content: "<:Sup_urg:1420535068056748042> Eliminar los comandos '/' de manera GLOBAL (todos los servidores)" } + { type: 10, content: "<:Sup_urg:1420535068056748042> Eliminar los comandos **/** de manera GLOBAL (todos los servidores)" } ], accessory: { type: 2, diff --git a/src/core/api/discordAPI.ts b/src/core/api/discordAPI.ts index bf2561a..17bc3ec 100644 --- a/src/core/api/discordAPI.ts +++ b/src/core/api/discordAPI.ts @@ -1,7 +1,7 @@ import { REST } from "discord.js"; // @ts-ignore import { Routes } from "discord-api-types/v10"; -import { commands } from "../loader"; +import { commands } from "../loaders/loader"; // Reutilizamos una instancia REST singleton const rest = new REST({ version: '10' }).setToken(process.env.TOKEN ?? ""); diff --git a/src/core/client.ts b/src/core/client.ts index 9a62cf7..d47b361 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -1,5 +1,5 @@ import { Client, GatewayIntentBits, Options, Partials } from 'discord.js'; -import { prisma, ensurePrismaConnection } from './prisma'; +import { prisma, ensurePrismaConnection } from './database/prisma'; // Verificar si process.loadEnvFile existe (Node.js 20.6+) if (typeof process.loadEnvFile === 'function') { diff --git a/src/core/prisma.ts b/src/core/database/prisma.ts similarity index 100% rename from src/core/prisma.ts rename to src/core/database/prisma.ts diff --git a/src/core/redis.ts b/src/core/database/redis.ts similarity index 86% rename from src/core/redis.ts rename to src/core/database/redis.ts index eaee4e9..4f3b2db 100644 --- a/src/core/redis.ts +++ b/src/core/database/redis.ts @@ -1,11 +1,5 @@ import { createClient } from "redis"; -/** -* export const redis = createClient({ -* url: process.env.REDIS_URL, -* }) -**/ - export const redis = createClient({ username: 'default', password: process.env.REDIS_PASS, diff --git a/src/core/components.ts b/src/core/lib/components.ts similarity index 96% rename from src/core/components.ts rename to src/core/lib/components.ts index edf10fe..f59e8ef 100644 --- a/src/core/components.ts +++ b/src/core/lib/components.ts @@ -1,7 +1,7 @@ import * as fs from "node:fs"; import * as path from "node:path"; import { Collection } from "discord.js"; -import type { Button, Modal, SelectMenu, ContextMenu } from "./types/components"; +import type { Button, Modal, SelectMenu, ContextMenu } from "../types/components"; export const buttons: Collection = new Collection(); export const modals: Collection = new Collection(); diff --git a/src/core/lib/vars.ts b/src/core/lib/vars.ts index e4ee720..f443080 100644 --- a/src/core/lib/vars.ts +++ b/src/core/lib/vars.ts @@ -1,4 +1,6 @@ import { Guild, Invite, User, GuildMember } from "discord.js"; +// Prisma client to compute ranks +import { prisma } from "../database/prisma"; /** * Registro central de variables -> resolutores @@ -33,6 +35,27 @@ const getInviteObject = (invite?: Invite) => invite?.guild ? { icon: invite.guild.icon ? `https://cdn.discordapp.com/icons/${invite.guild.id}/${invite.guild.icon}.webp?size=256` : '' } : null; +// Helper: calcula el rank dentro del servidor para un campo (weeklyPoints / monthlyPoints) +async function computeRankInGuild(guildId: string, userId: string, field: 'weeklyPoints' | 'monthlyPoints', knownPoints?: number): Promise { + try { + let points = knownPoints; + if (typeof points !== 'number') { + const self = await prisma.partnershipStats.findUnique({ + where: { userId_guildId: { userId, guildId } } + }); + if (!self) return 0; // No tiene registro -> no rank + // @ts-ignore - modelo generado por Prisma + points = (self as any)[field] as number; + } + const higher = await prisma.partnershipStats.count({ + where: { guildId, [field]: { gt: points as number } } as any + }); + return higher + 1; // rank 1 para el mayor puntaje + } catch { + return 0; + } +} + export const VARIABLES: Record = { // USER INFO 'user.name': ({ user }) => getUsername(user), @@ -47,6 +70,21 @@ export const VARIABLES: Record = { 'user.pointsAll': ({ stats }) => stats?.totalPoints?.toString?.() ?? '0', 'user.pointsWeekly': ({ stats }) => stats?.weeklyPoints?.toString?.() ?? '0', 'user.pointsMonthly': ({ stats }) => stats?.monthlyPoints?.toString?.() ?? '0', + // USER RANKS (dentro del servidor actual) + 'user.rankWeekly': async ({ user, guild, stats }) => { + const userId = getUserId(user); + const guildId = guild?.id; + if (!userId || !guildId) return '0'; + const rank = await computeRankInGuild(guildId, userId, 'weeklyPoints', stats?.weeklyPoints); + return String(rank || 0); + }, + 'user.rankMonthly': async ({ user, guild, stats }) => { + const userId = getUserId(user); + const guildId = guild?.id; + if (!userId || !guildId) return '0'; + const rank = await computeRankInGuild(guildId, userId, 'monthlyPoints', stats?.monthlyPoints); + return String(rank || 0); + }, // GUILD INFO 'guild.name': ({ guild }) => guild?.name ?? '', diff --git a/src/core/loader.ts b/src/core/loaders/loader.ts similarity index 100% rename from src/core/loader.ts rename to src/core/loaders/loader.ts diff --git a/src/core/loaderEvents.ts b/src/core/loaders/loaderEvents.ts similarity index 96% rename from src/core/loaderEvents.ts rename to src/core/loaders/loaderEvents.ts index cc03550..cf038aa 100644 --- a/src/core/loaderEvents.ts +++ b/src/core/loaders/loaderEvents.ts @@ -1,4 +1,4 @@ -import { bot } from "../main"; +import { bot } from "../../main"; import path from "node:path"; import * as fs from "node:fs"; diff --git a/src/core/memoryMonitor.ts b/src/core/memory/memoryMonitor.ts similarity index 100% rename from src/core/memoryMonitor.ts rename to src/core/memory/memoryMonitor.ts diff --git a/src/core/memoryOptimizer.ts b/src/core/memory/memoryOptimizer.ts similarity index 100% rename from src/core/memoryOptimizer.ts rename to src/core/memory/memoryOptimizer.ts diff --git a/src/events/extras/alliace.ts b/src/events/extras/alliace.ts index 54d3762..4deaedc 100644 --- a/src/events/extras/alliace.ts +++ b/src/events/extras/alliace.ts @@ -2,7 +2,7 @@ import { Message } from "discord.js"; // Reemplaza instancia local -> usa singleton -import { prisma } from "../../core/prisma"; +import { prisma } from "../../core/database/prisma"; import { replaceVars } from "../../core/lib/vars"; diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 85dc4cf..b1617d8 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -1,9 +1,9 @@ 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"; +import { redis } from "../core/database/redis"; +import { commands } from "../core/loaders/loader"; +import { buttons, modals, selectmenus } from "../core/lib/components"; bot.on(Events.InteractionCreate, async (interaction: BaseInteraction) => { try { diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 678c106..1447496 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -1,7 +1,7 @@ import {bot} from "../main"; import {Events} from "discord.js"; -import {redis} from "../core/redis"; -import {commands} from "../core/loader"; +import {redis} from "../core/database/redis"; +import {commands} from "../core/loaders/loader"; import {alliance} from "./extras/alliace"; diff --git a/src/main.ts b/src/main.ts index 2bd6442..a023e6d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,11 +1,11 @@ import Amayo from "./core/client"; -import { loadCommands } from "./core/loader"; -import { loadEvents } from "./core/loaderEvents"; -import { redis, redisConnect } from "./core/redis"; +import { loadCommands } from "./core/loaders/loader"; +import { loadEvents } from "./core/loaders/loaderEvents"; +import { redis, redisConnect } from "./core/database/redis"; import { registeringCommands } from "./core/api/discordAPI"; -import {loadComponents} from "./core/components"; -import { startMemoryMonitor } from "./core/memoryMonitor"; -import {memoryOptimizer} from "./core/memoryOptimizer"; +import {loadComponents} from "./core/lib/components"; +import { startMemoryMonitor } from "./core/memory/memoryMonitor"; +import {memoryOptimizer} from "./core/memory/memoryOptimizer"; // Activar monitor de memoria si se define la variable const __memInt = parseInt(process.env.MEMORY_LOG_INTERVAL_SECONDS || '0', 10);