Fantitom commited on
Commit
b41ec66
·
1 Parent(s): 1fbf5f0

IPv4 First

Browse files
Files changed (1) hide show
  1. index.js +23 -17
index.js CHANGED
@@ -1,4 +1,10 @@
1
  require('dotenv').config();
 
 
 
 
 
 
2
  const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, ActionRowBuilder, ButtonBuilder, ButtonStyle, REST, Routes, SlashCommandBuilder } = require('discord.js');
3
  const { createClient } = require('@supabase/supabase-js');
4
 
@@ -16,7 +22,7 @@ const commands = [
16
  .addUserOption(opt => opt.setName('rival').setDescription('El jugador contra el que jugaste').setRequired(true))
17
  .addIntegerOption(opt => opt.setName('mis_puntos').setDescription('Cantidad de partidas que ganaste TÚ').setRequired(true))
18
  .addIntegerOption(opt => opt.setName('sus_puntos').setDescription('Cantidad de partidas que ganó TU RIVAL').setRequired(true)),
19
-
20
  new SlashCommandBuilder()
21
  .setName('perfil')
22
  .setDescription('Mira tu perfil de Rivals o el de otro jugador.')
@@ -58,7 +64,7 @@ function getTrend(current, last) {
58
  // --- EVENTOS DEL BOT ---
59
  client.once('ClientReady', async () => {
60
  console.log(`✅ Bot conectado como ${client.user.tag}`);
61
-
62
  // Registrar los comandos en Discord al encender
63
  const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
64
  try {
@@ -123,7 +129,7 @@ client.on('interactionCreate', async interaction => {
123
  // --- COMANDO: /perfil ---
124
  if (commandName === 'perfil') {
125
  await interaction.deferReply(); // Le avisa a Discord que estamos procesando (Supabase puede tardar unos ms)
126
-
127
  const targetUser = interaction.options.getUser('jugador') || interaction.user;
128
  const targetMember = await interaction.guild.members.fetch(targetUser.id);
129
 
@@ -160,8 +166,8 @@ client.on('interactionCreate', async interaction => {
160
  const embed = new EmbedBuilder()
161
  .setTitle(`🏆 Top 10 - Temporada ${season}`)
162
  .setColor(0x00FF00)
163
- .setDescription(rows && rows.length > 0
164
- ? rows.map((r, i) => `**${i+1}.** ${r.user_name} - ${r.elo} pts ${getTrend(i+1, r.last_rank)}`).join('\n')
165
  : "Aún no hay partidas.");
166
  await interaction.editReply({ embeds: [embed] });
167
  }
@@ -201,7 +207,7 @@ async function procesarResultado(winnerMember, loserMember, guildId, season) {
201
  lData = lData || { elo: 1000, wins: 0, losses: 0, matches_played: 0, last_rank: null };
202
 
203
  const { data: allRankings } = await supabase.from('ranking').select('user_id').eq('guild_id', guildId).eq('season', season).order('elo', { ascending: false });
204
-
205
  const wOldRank = allRankings ? allRankings.findIndex(r => r.user_id === winnerMember.id) + 1 || null : null;
206
  const lOldRank = allRankings ? allRankings.findIndex(r => r.user_id === loserMember.id) + 1 || null : null;
207
 
@@ -220,16 +226,16 @@ const http = require('http');
220
 
221
  // Servidor de mantenimiento para Hugging Face
222
  http.createServer((req, res) => {
223
- res.writeHead(200);
224
- res.end('Bot Online');
225
  }).listen(7860, '0.0.0.0', () => {
226
- console.log('✅ Servidor de mantenimiento listo.');
227
-
228
- // Esperamos 5 segundos antes de loguear para que el DNS de la nube despierte
229
- setTimeout(() => {
230
- console.log('🚀 Intentando conectar a Discord...');
231
- client.login(process.env.DISCORD_TOKEN).catch(err => {
232
- console.error('❌ Error al loguear en Discord:', err);
233
- });
234
- }, 5000);
235
  });
 
1
  require('dotenv').config();
2
+
3
+ // --- PARCHE PARA HUGGING FACE (Forzar IPv4) ---
4
+ const dns = require('node:dns');
5
+ dns.setDefaultResultOrder('ipv4first');
6
+ // ----------------------------------------------
7
+
8
  const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, ActionRowBuilder, ButtonBuilder, ButtonStyle, REST, Routes, SlashCommandBuilder } = require('discord.js');
9
  const { createClient } = require('@supabase/supabase-js');
10
 
 
22
  .addUserOption(opt => opt.setName('rival').setDescription('El jugador contra el que jugaste').setRequired(true))
23
  .addIntegerOption(opt => opt.setName('mis_puntos').setDescription('Cantidad de partidas que ganaste TÚ').setRequired(true))
24
  .addIntegerOption(opt => opt.setName('sus_puntos').setDescription('Cantidad de partidas que ganó TU RIVAL').setRequired(true)),
25
+
26
  new SlashCommandBuilder()
27
  .setName('perfil')
28
  .setDescription('Mira tu perfil de Rivals o el de otro jugador.')
 
64
  // --- EVENTOS DEL BOT ---
65
  client.once('ClientReady', async () => {
66
  console.log(`✅ Bot conectado como ${client.user.tag}`);
67
+
68
  // Registrar los comandos en Discord al encender
69
  const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
70
  try {
 
129
  // --- COMANDO: /perfil ---
130
  if (commandName === 'perfil') {
131
  await interaction.deferReply(); // Le avisa a Discord que estamos procesando (Supabase puede tardar unos ms)
132
+
133
  const targetUser = interaction.options.getUser('jugador') || interaction.user;
134
  const targetMember = await interaction.guild.members.fetch(targetUser.id);
135
 
 
166
  const embed = new EmbedBuilder()
167
  .setTitle(`🏆 Top 10 - Temporada ${season}`)
168
  .setColor(0x00FF00)
169
+ .setDescription(rows && rows.length > 0
170
+ ? rows.map((r, i) => `**${i + 1}.** ${r.user_name} - ${r.elo} pts ${getTrend(i + 1, r.last_rank)}`).join('\n')
171
  : "Aún no hay partidas.");
172
  await interaction.editReply({ embeds: [embed] });
173
  }
 
207
  lData = lData || { elo: 1000, wins: 0, losses: 0, matches_played: 0, last_rank: null };
208
 
209
  const { data: allRankings } = await supabase.from('ranking').select('user_id').eq('guild_id', guildId).eq('season', season).order('elo', { ascending: false });
210
+
211
  const wOldRank = allRankings ? allRankings.findIndex(r => r.user_id === winnerMember.id) + 1 || null : null;
212
  const lOldRank = allRankings ? allRankings.findIndex(r => r.user_id === loserMember.id) + 1 || null : null;
213
 
 
226
 
227
  // Servidor de mantenimiento para Hugging Face
228
  http.createServer((req, res) => {
229
+ res.writeHead(200);
230
+ res.end('Bot Online');
231
  }).listen(7860, '0.0.0.0', () => {
232
+ console.log('✅ Servidor de mantenimiento listo.');
233
+
234
+ // Esperamos 10 segundos antes de loguear para que el DNS despierte
235
+ setTimeout(() => {
236
+ console.log('🚀 Intentando conectar a Discord...');
237
+ client.login(process.env.DISCORD_TOKEN).catch(err => {
238
+ console.error('❌ Error al loguear en Discord:', err);
239
+ });
240
+ }, 10000);
241
  });