This commit is contained in:
Milo
2025-12-10 10:16:06 +01:00
parent 17b62b50c0
commit 7c48f16cad
9 changed files with 42 additions and 53 deletions

View File

@@ -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));
}

View File

@@ -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`);
}
});

View File

@@ -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);
}
}
}

View File

@@ -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}.`);
}
});
}

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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];

View File

@@ -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 });
}
});

View File

@@ -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" });