refactor: reorganize imports and update file paths for consistency

This commit is contained in:
2025-09-27 16:00:12 -05:00
parent 39b105789f
commit db44e148d3
20 changed files with 59 additions and 28 deletions

View File

@@ -227,7 +227,6 @@ const updateEditor = async (msg: any, data: any) => {
const payload: any = { ...data }; const payload: any = { ...data };
delete payload.display; delete payload.display;
payload.components = components; payload.components = components;
// Si no se pasa flags explícitos, usamos 32768 como en tu entorno
if (payload.flags === undefined) payload.flags = 32768; if (payload.flags === undefined) payload.flags = 32768;
await msg.edit(payload); await msg.edit(payload);
}; };

View File

@@ -1,6 +1,6 @@
// @ts-ignore // @ts-ignore
import { CommandMessage } from "../../../core/types/commands"; 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 = { export const command: CommandMessage = {
name: 'ayuda', name: 'ayuda',

View File

@@ -34,7 +34,7 @@ function buildAdminPanel() {
{ {
type: 9, type: 9,
components: [ 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: { accessory: {
type: 2, type: 2,
@@ -47,7 +47,7 @@ function buildAdminPanel() {
{ {
type: 9, type: 9,
components: [ 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: { accessory: {
type: 2, type: 2,
@@ -60,7 +60,7 @@ function buildAdminPanel() {
{ {
type: 9, type: 9,
components: [ 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: { accessory: {
type: 2, type: 2,
@@ -73,7 +73,7 @@ function buildAdminPanel() {
{ {
type: 9, type: 9,
components: [ 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: { accessory: {
type: 2, type: 2,

View File

@@ -1,7 +1,7 @@
import { REST } from "discord.js"; import { REST } from "discord.js";
// @ts-ignore // @ts-ignore
import { Routes } from "discord-api-types/v10"; import { Routes } from "discord-api-types/v10";
import { commands } from "../loader"; import { commands } from "../loaders/loader";
// Reutilizamos una instancia REST singleton // Reutilizamos una instancia REST singleton
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN ?? ""); const rest = new REST({ version: '10' }).setToken(process.env.TOKEN ?? "");

View File

@@ -1,5 +1,5 @@
import { Client, GatewayIntentBits, Options, Partials } from 'discord.js'; 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+) // Verificar si process.loadEnvFile existe (Node.js 20.6+)
if (typeof process.loadEnvFile === 'function') { if (typeof process.loadEnvFile === 'function') {

View File

@@ -1,11 +1,5 @@
import { createClient } from "redis"; import { createClient } from "redis";
/**
* export const redis = createClient({
* url: process.env.REDIS_URL,
* })
**/
export const redis = createClient({ export const redis = createClient({
username: 'default', username: 'default',
password: process.env.REDIS_PASS, password: process.env.REDIS_PASS,

View File

@@ -1,7 +1,7 @@
import * as fs from "node:fs"; import * as fs from "node:fs";
import * as path from "node:path"; import * as path from "node:path";
import { Collection } from "discord.js"; 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<string, Button> = new Collection<string, Button>(); export const buttons: Collection<string, Button> = new Collection<string, Button>();
export const modals: Collection<string, Modal> = new Collection<string, Modal>(); export const modals: Collection<string, Modal> = new Collection<string, Modal>();

View File

@@ -1,4 +1,6 @@
import { Guild, Invite, User, GuildMember } from "discord.js"; import { Guild, Invite, User, GuildMember } from "discord.js";
// Prisma client to compute ranks
import { prisma } from "../database/prisma";
/** /**
* Registro central de variables -> resolutores * 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` : '' icon: invite.guild.icon ? `https://cdn.discordapp.com/icons/${invite.guild.id}/${invite.guild.icon}.webp?size=256` : ''
} : null; } : 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<number> {
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<string, VarResolver> = { export const VARIABLES: Record<string, VarResolver> = {
// USER INFO // USER INFO
'user.name': ({ user }) => getUsername(user), 'user.name': ({ user }) => getUsername(user),
@@ -47,6 +70,21 @@ export const VARIABLES: Record<string, VarResolver> = {
'user.pointsAll': ({ stats }) => stats?.totalPoints?.toString?.() ?? '0', 'user.pointsAll': ({ stats }) => stats?.totalPoints?.toString?.() ?? '0',
'user.pointsWeekly': ({ stats }) => stats?.weeklyPoints?.toString?.() ?? '0', 'user.pointsWeekly': ({ stats }) => stats?.weeklyPoints?.toString?.() ?? '0',
'user.pointsMonthly': ({ stats }) => stats?.monthlyPoints?.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 INFO
'guild.name': ({ guild }) => guild?.name ?? '', 'guild.name': ({ guild }) => guild?.name ?? '',

View File

@@ -1,4 +1,4 @@
import { bot } from "../main"; import { bot } from "../../main";
import path from "node:path"; import path from "node:path";
import * as fs from "node:fs"; import * as fs from "node:fs";

View File

@@ -2,7 +2,7 @@ import {
Message Message
} from "discord.js"; } from "discord.js";
// Reemplaza instancia local -> usa singleton // Reemplaza instancia local -> usa singleton
import { prisma } from "../../core/prisma"; import { prisma } from "../../core/database/prisma";
import { replaceVars } from "../../core/lib/vars"; import { replaceVars } from "../../core/lib/vars";

View File

@@ -1,9 +1,9 @@
import { bot } from "../main"; import { bot } from "../main";
import type { BaseInteraction } from "discord.js"; import type { BaseInteraction } from "discord.js";
import { Events } from "discord.js"; import { Events } from "discord.js";
import { redis } from "../core/redis"; import { redis } from "../core/database/redis";
import { commands } from "../core/loader"; import { commands } from "../core/loaders/loader";
import { buttons, modals, selectmenus } from "../core/components"; import { buttons, modals, selectmenus } from "../core/lib/components";
bot.on(Events.InteractionCreate, async (interaction: BaseInteraction) => { bot.on(Events.InteractionCreate, async (interaction: BaseInteraction) => {
try { try {

View File

@@ -1,7 +1,7 @@
import {bot} from "../main"; import {bot} from "../main";
import {Events} from "discord.js"; import {Events} from "discord.js";
import {redis} from "../core/redis"; import {redis} from "../core/database/redis";
import {commands} from "../core/loader"; import {commands} from "../core/loaders/loader";
import {alliance} from "./extras/alliace"; import {alliance} from "./extras/alliace";

View File

@@ -1,11 +1,11 @@
import Amayo from "./core/client"; import Amayo from "./core/client";
import { loadCommands } from "./core/loader"; import { loadCommands } from "./core/loaders/loader";
import { loadEvents } from "./core/loaderEvents"; import { loadEvents } from "./core/loaders/loaderEvents";
import { redis, redisConnect } from "./core/redis"; import { redis, redisConnect } from "./core/database/redis";
import { registeringCommands } from "./core/api/discordAPI"; import { registeringCommands } from "./core/api/discordAPI";
import {loadComponents} from "./core/components"; import {loadComponents} from "./core/lib/components";
import { startMemoryMonitor } from "./core/memoryMonitor"; import { startMemoryMonitor } from "./core/memory/memoryMonitor";
import {memoryOptimizer} from "./core/memoryOptimizer"; import {memoryOptimizer} from "./core/memory/memoryOptimizer";
// Activar monitor de memoria si se define la variable // Activar monitor de memoria si se define la variable
const __memInt = parseInt(process.env.MEMORY_LOG_INTERVAL_SECONDS || '0', 10); const __memInt = parseInt(process.env.MEMORY_LOG_INTERVAL_SECONDS || '0', 10);