From 7c48f16cad5351a7f67acb822bf2897a79689059 Mon Sep 17 00:00:00 2001 From: Milo Date: Wed, 10 Dec 2025 10:16:06 +0100 Subject: [PATCH] hotfix --- src/api/discord.js | 2 +- src/database/index.js | 2 +- src/game/blackjack.js | 4 ++-- src/game/elo.js | 14 +++++------- src/game/points.js | 14 ++++++------ src/server/routes/api.js | 39 ++++++++++++++-------------------- src/server/routes/blackjack.js | 8 +++---- src/server/routes/market.js | 2 +- src/server/routes/poker.js | 10 ++++----- 9 files changed, 42 insertions(+), 53 deletions(-) diff --git a/src/api/discord.js b/src/api/discord.js index 3668588..41eb7c9 100644 --- a/src/api/discord.js +++ b/src/api/discord.js @@ -36,7 +36,7 @@ export async function DiscordRequest(endpoint, options) { } catch (err) { data = res; } - console.error(`[${Date.now().toLocaleString()}] Discord API Error on endpoint ${endpoint}:`, res.status, data); + console.error(`[${Date.now()}] Discord API Error on endpoint ${endpoint}:`, res.status, data); throw new Error(JSON.stringify(data)); } diff --git a/src/database/index.js b/src/database/index.js index 5bc17b2..4eb0829 100644 --- a/src/database/index.js +++ b/src/database/index.js @@ -215,7 +215,7 @@ export const updateManyUsers = flopoDB.transaction(async (users) => { try { await updateUser.run(user); } catch (e) { - console.log(`[${Date.now().toLocaleString()}] user update failed`); + console.log(`[${Date.now()}] user update failed`); } }); diff --git a/src/game/blackjack.js b/src/game/blackjack.js index 6d40a58..501fb7a 100644 --- a/src/game/blackjack.js +++ b/src/game/blackjack.js @@ -317,7 +317,7 @@ export async function settleAll(room) { }); p.bank = coins + hand.bet + res.delta; } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } } } @@ -346,7 +346,7 @@ export async function settleAll(room) { .setTimestamp(new Date()); await msg.edit({ embeds: [updatedEmbed], components: [] }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } } } diff --git a/src/game/elo.js b/src/game/elo.js index df7b955..02ffaaf 100644 --- a/src/game/elo.js +++ b/src/game/elo.js @@ -15,7 +15,7 @@ export async function eloHandler(p1Id, p2Id, p1Score, p2Score, type) { const p1DB = getUser.get(p1Id); const p2DB = getUser.get(p2Id); if (!p1DB || !p2DB) { - console.error(`[${Date.now().toLocaleString()}] Elo Handler: Could not find user data for ${p1Id} or ${p2Id}.`); + console.error(`[${Date.now()}] Elo Handler: Could not find user data for ${p1Id} or ${p2Id}.`); return; } @@ -51,12 +51,8 @@ export async function eloHandler(p1Id, p2Id, p1Score, p2Score, type) { const finalP1Elo = Math.max(0, p1NewElo); const finalP2Elo = Math.max(0, p2NewElo); - console.log( - `[${Date.now().toLocaleString()}] Elo Update (${type}) for ${p1DB.globalName}: ${p1CurrentElo} -> ${finalP1Elo}`, - ); - console.log( - `[${Date.now().toLocaleString()}] Elo Update (${type}) for ${p2DB.globalName}: ${p2CurrentElo} -> ${finalP2Elo}`, - ); + console.log(`[${Date.now()}] Elo Update (${type}) for ${p1DB.globalName}: ${p1CurrentElo} -> ${finalP1Elo}`); + console.log(`[${Date.now()}] Elo Update (${type}) for ${p2DB.globalName}: ${p2CurrentElo} -> ${finalP2Elo}`); try { const generalChannel = await client.channels.fetch(process.env.BOT_CHANNEL_ID); const user1 = await client.users.fetch(p1Id); @@ -74,7 +70,7 @@ export async function eloHandler(p1Id, p2Id, p1Score, p2Score, type) { .setColor("#5865f2"); await generalChannel.send({ embeds: [embed] }); } catch (e) { - console.error(`[${Date.now().toLocaleString()}] Failed to post elo update message`, e); + console.error(`[${Date.now()}] Failed to post elo update message`, e); } // --- 4. Update Database --- @@ -160,7 +156,7 @@ export async function pokerEloHandler(room) { timestamp: Date.now(), }); } else { - console.error(`[${Date.now().toLocaleString()}] Error calculating new Elo for ${player.globalName}.`); + console.error(`[${Date.now()}] Error calculating new Elo for ${player.globalName}.`); } }); } diff --git a/src/game/points.js b/src/game/points.js index f63c148..dbee347 100644 --- a/src/game/points.js +++ b/src/game/points.js @@ -88,7 +88,7 @@ export async function slowmodesHandler(message) { // Check if the slowmode duration has passed if (now > authorSlowmode.endAt) { - console.log(`[${Date.now().toLocaleString()}] Slowmode for ${author.username} has expired.`); + console.log(`[${Date.now()}] Slowmode for ${author.username} has expired.`); delete activeSlowmodes[author.id]; return { deleted: false, expired: true }; } @@ -97,10 +97,10 @@ export async function slowmodesHandler(message) { if (authorSlowmode.lastMessage && now - authorSlowmode.lastMessage < 60 * 1000) { try { await message.delete(); - console.log(`[${Date.now().toLocaleString()}] Deleted a message from slowmoded user: ${author.username}`); + console.log(`[${Date.now()}] Deleted a message from slowmoded user: ${author.username}`); return { deleted: true, expired: false }; } catch (err) { - console.error(`[${Date.now().toLocaleString()}] Failed to delete slowmode message:`, err); + console.error(`[${Date.now()}] Failed to delete slowmode message:`, err); return { deleted: false, expired: false }; } } else { @@ -144,7 +144,7 @@ export function randomSkinPrice() { * This function clears previous stats, awards the winner, and generates a new daily seed. */ export function initTodaysSOTD() { - console.log(`[${Date.now().toLocaleString()}] Initializing new Solitaire of the Day...`); + console.log(`[${Date.now()}] Initializing new Solitaire of the Day...`); // 1. Award previous day's winner const rankings = getAllSOTDStats.all(); @@ -165,7 +165,7 @@ export function initTodaysSOTD() { user_new_amount: newCoinTotal, }); console.log( - `[${Date.now().toLocaleString()}] ${winnerUser.globalName || winnerUser.username} won the previous SOTD and received ${reward} coins.`, + `[${Date.now()}] ${winnerUser.globalName || winnerUser.username} won the previous SOTD and received ${reward} coins.`, ); insertGame.run({ id: `${winnerId}-${Date.now()}`, @@ -206,8 +206,8 @@ export function initTodaysSOTD() { wastePile: JSON.stringify(todaysSOTD.wastePile), seed: newRandomSeed, }); - console.log(`[${Date.now().toLocaleString()}] Today's SOTD is ready with a new seed.`); + console.log(`[${Date.now()}] Today's SOTD is ready with a new seed.`); } catch (e) { - console.error(`[${Date.now().toLocaleString()}] Error saving new SOTD to database:`, e); + console.error(`[${Date.now()}] Error saving new SOTD to database:`, e); } } diff --git a/src/server/routes/api.js b/src/server/routes/api.js index c36592e..697c134 100644 --- a/src/server/routes/api.js +++ b/src/server/routes/api.js @@ -96,14 +96,11 @@ export function apiRoutes(client, io) { user_new_amount: 5000, }); - console.log(`[${Date.now().toLocaleString()}] New registered user: ${discordUser.username} (${discordUser.id})`); + console.log(`[${Date.now()}] New registered user: ${discordUser.username} (${discordUser.id})`); res.status(200).json({ message: `Bienvenue ${discordUser.username} !` }); } catch (e) { - console.log( - `[${Date.now().toLocaleString()}] Failed to register user ${discordUser.username} (${discordUser.id})`, - e, - ); + console.log(`[${Date.now()}] Failed to register user ${discordUser.username} (${discordUser.id})`, e); res.status(500).json({ error: "Erreur lors de la création du nouvel utilisateur." }); } }); @@ -322,9 +319,7 @@ export function apiRoutes(client, io) { user_new_amount: newCoins, }); - console.log( - `[${Date.now().toLocaleString()}] ${commandUserId} change nickname of ${userId}: ${old_nickname} -> ${nickname}`, - ); + console.log(`[${Date.now()}] ${commandUserId} change nickname of ${userId}: ${old_nickname} -> ${nickname}`); try { const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID); @@ -340,7 +335,7 @@ export function apiRoutes(client, io) { await generalChannel.send({ embeds: [embed] }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } res.status(200).json({ @@ -392,7 +387,7 @@ export function apiRoutes(client, io) { await generalChannel.send({ embeds: [embed] }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } for (let i = 1; i < 120; i++) { @@ -400,7 +395,7 @@ export function apiRoutes(client, io) { await sleep(250); } } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); res.status(500).json({ message: "Oups ça n'a pas marché" }); } }); @@ -451,7 +446,7 @@ export function apiRoutes(client, io) { await generalChannel.send({ embeds: [embed] }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } return res.status(200).json({ message: "Slowmode retiré" }); } else { @@ -497,7 +492,7 @@ export function apiRoutes(client, io) { await generalChannel.send({ embeds: [embed] }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } return res.status(200).json({ @@ -540,7 +535,7 @@ export function apiRoutes(client, io) { }, }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); return res.status(403).send({ message: `Impossible de time-out ${user.globalName}` }); } @@ -566,7 +561,7 @@ export function apiRoutes(client, io) { await generalChannel.send({ embeds: [embed] }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } return res.status(200).json({ message: "Time-out retiré" }); } @@ -587,7 +582,7 @@ export function apiRoutes(client, io) { body: { communication_disabled_until: timeoutUntil }, }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); return res.status(403).send({ message: `Impossible de time-out ${user.globalName}` }); } @@ -616,7 +611,7 @@ export function apiRoutes(client, io) { await generalChannel.send({ embeds: [embed] }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } return res.status(200).json({ message: `${user.globalName} est maintenant time-out pour 12h` }); @@ -688,7 +683,7 @@ export function apiRoutes(client, io) { }); msgId = msg.id; } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); return res.status(500).send({ message: "Erreur lors de l'envoi du message" }); } @@ -829,7 +824,7 @@ export function apiRoutes(client, io) { user_new_amount: tempUser.coins + v.amount, }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}] Impossible de rembourser ${v.id} (${v.amount} coins)`); + console.log(`[${Date.now()}] Impossible de rembourser ${v.id} (${v.amount} coins)`); } }); activePredis[predi].options[1].votes.forEach((v) => { @@ -848,7 +843,7 @@ export function apiRoutes(client, io) { user_new_amount: tempUser.coins + v.amount, }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}] Impossible de rembourser ${v.id} (${v.amount} coins)`); + console.log(`[${Date.now()}] Impossible de rembourser ${v.id} (${v.amount} coins)`); } }); activePredis[predi].closed = true; @@ -874,9 +869,7 @@ export function apiRoutes(client, io) { user_new_amount: tempUser.coins + v.amount * (1 + ratio), }); } catch (e) { - console.log( - `[${Date.now().toLocaleString()}] Impossible de créditer ${v.id} (${v.amount} coins pariés, *${1 + ratio})`, - ); + console.log(`[${Date.now()}] Impossible de créditer ${v.id} (${v.amount} coins pariés, *${1 + ratio})`); } }); activePredis[predi].paidTime = new Date(); diff --git a/src/server/routes/blackjack.js b/src/server/routes/blackjack.js index 0bda2ae..10affa3 100644 --- a/src/server/routes/blackjack.js +++ b/src/server/routes/blackjack.js @@ -153,7 +153,7 @@ export function blackjackRoutes(io) { try { const guild = await client.guilds.fetch(process.env.GUILD_ID); - const generalChannel = guild.channels.fetch(process.env.BOT_CHANNEL_ID); + const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID); const embed = new EmbedBuilder() .setDescription(`<@${userId}> joue au Blackjack`) .addFields( @@ -174,7 +174,7 @@ export function blackjackRoutes(io) { const msg = await generalChannel.send({ embeds: [embed] }); room.players[userId].msgId = msg.id; } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } emitUpdate("player-joined", snapshot(room)); @@ -187,7 +187,7 @@ export function blackjackRoutes(io) { try { const guild = await client.guilds.fetch(process.env.GUILD_ID); - const generalChannel = guild.channels.fetch(process.env.BOT_CHANNEL_ID); + const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID); const msg = await generalChannel.messages.fetch(room.players[userId].msgId); const updatedEmbed = new EmbedBuilder() .setDescription(`<@${userId}> a quitté la table de Blackjack.`) @@ -207,7 +207,7 @@ export function blackjackRoutes(io) { .setTimestamp(new Date()); await msg.edit({ embeds: [updatedEmbed], components: [] }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } const p = room.players[userId]; diff --git a/src/server/routes/market.js b/src/server/routes/market.js index 2b6d950..63eadc8 100644 --- a/src/server/routes/market.js +++ b/src/server/routes/market.js @@ -126,7 +126,7 @@ export function marketRoutes(client, io) { res.status(200).send({ message: "Bid placed successfully" }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); res.status(500).send({ error: e }); } }); diff --git a/src/server/routes/poker.js b/src/server/routes/poker.js index 9f1e7ba..70b0a31 100644 --- a/src/server/routes/poker.js +++ b/src/server/routes/poker.js @@ -89,7 +89,7 @@ export function pokerRoutes(client, io) { await emitPokerUpdate({ room: pokerRooms[id], type: "room-created" }); try { - const generalChannel = guild.channels.fetch(process.env.BOT_CHANNEL_ID); + const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID); const embed = new EmbedBuilder() .setTitle("Flopoker 🃏") .setDescription(`<@${creatorId}> a créé une table de poker`) @@ -118,7 +118,7 @@ export function pokerRoutes(client, io) { await generalChannel.send({ embeds: [embed], components: [row] }); } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } res.status(201).json({ roomId: id }); @@ -191,7 +191,7 @@ export function pokerRoutes(client, io) { await checkRoundCompletion(pokerRooms[roomId], io); } } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } await emitPokerUpdate({ type: "player-afk" }); @@ -215,7 +215,7 @@ export function pokerRoutes(client, io) { } } } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } await emitPokerUpdate({ type: "player-left" }); @@ -255,7 +255,7 @@ export function pokerRoutes(client, io) { } } } catch (e) { - console.log(`[${Date.now().toLocaleString()}]`, e); + console.log(`[${Date.now()}]`, e); } await emitPokerUpdate({ type: "player-kicked" });