mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-01-18 16:37:40 +01:00
fix: bot messages in bot channel
Migrated most of the bot messages in the bot channel, commands messages are still in the general channel. Added timestamps to some logs
This commit is contained in:
@@ -36,7 +36,7 @@ export async function DiscordRequest(endpoint, options) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
data = res;
|
data = res;
|
||||||
}
|
}
|
||||||
console.error(`Discord API Error on endpoint ${endpoint}:`, res.status, data);
|
console.error(`[${Date.now().toLocaleString()}] Discord API Error on endpoint ${endpoint}:`, res.status, data);
|
||||||
throw new Error(JSON.stringify(data));
|
throw new Error(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { getAkhys, setupCronJobs } from "../utils/index.js";
|
|||||||
* @param {object} io - The Socket.IO server instance for real-time communication.
|
* @param {object} io - The Socket.IO server instance for real-time communication.
|
||||||
*/
|
*/
|
||||||
export function initializeEvents(client, io) {
|
export function initializeEvents(client, io) {
|
||||||
// --- on 'ready' ---
|
// --- on 'clientReady' ---
|
||||||
// This event fires once the bot has successfully logged in and is ready to operate.
|
// This event fires once the bot has successfully logged in and is ready to operate.
|
||||||
// It's a good place for setup tasks that require the bot to be online.
|
// It's a good place for setup tasks that require the bot to be online.
|
||||||
client.once("clientReady", async () => {
|
client.once("clientReady", async () => {
|
||||||
@@ -29,24 +29,4 @@ export function initializeEvents(client, io) {
|
|||||||
// without needing to import them, preventing potential circular dependencies.
|
// without needing to import them, preventing potential circular dependencies.
|
||||||
await handleMessageCreate(message, client, io);
|
await handleMessageCreate(message, client, io);
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- on 'interactionCreate' (Alternative Method) ---
|
|
||||||
// While we handle interactions via the Express endpoint for scalability and statelessness,
|
|
||||||
// you could also listen for them via the gateway like this.
|
|
||||||
// It's commented out because our current architecture uses the webhook approach.
|
|
||||||
/*
|
|
||||||
client.on('interactionCreate', async (interaction) => {
|
|
||||||
// Logic to handle interactions would go here if not using a webhook endpoint.
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
// You can add more event listeners here as your bot's functionality grows.
|
|
||||||
// For example, listening for new members joining the server:
|
|
||||||
// client.on('guildMemberAdd', (member) => {
|
|
||||||
// console.log(`Welcome to the server, ${member.user.tag}!`);
|
|
||||||
// const welcomeChannel = member.guild.channels.cache.get('YOUR_WELCOME_CHANNEL_ID');
|
|
||||||
// if (welcomeChannel) {
|
|
||||||
// welcomeChannel.send(`Please welcome <@${member.id}> to the server!`);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,7 @@ import {
|
|||||||
MAX_ATTS_PER_MESSAGE,
|
MAX_ATTS_PER_MESSAGE,
|
||||||
stripMentionsOfBot,
|
stripMentionsOfBot,
|
||||||
} from "../../utils/ai.js";
|
} from "../../utils/ai.js";
|
||||||
import {
|
import { calculateBasePrice, calculateMaxPrice, formatTime, getAkhys } from "../../utils/index.js";
|
||||||
calculateBasePrice,
|
|
||||||
calculateMaxPrice,
|
|
||||||
formatTime,
|
|
||||||
getAkhys,
|
|
||||||
getAPOUsers,
|
|
||||||
postAPOBuy,
|
|
||||||
} from "../../utils/index.js";
|
|
||||||
import { channelPointsHandler, initTodaysSOTD, randomSkinPrice, slowmodesHandler } from "../../game/points.js";
|
import { channelPointsHandler, initTodaysSOTD, randomSkinPrice, slowmodesHandler } from "../../game/points.js";
|
||||||
import { activePolls, activeSlowmodes, requestTimestamps, skins } from "../../game/state.js";
|
import { activePolls, activeSlowmodes, requestTimestamps, skins } from "../../game/state.js";
|
||||||
import {
|
import {
|
||||||
@@ -29,7 +22,6 @@ import {
|
|||||||
updateUserAvatar,
|
updateUserAvatar,
|
||||||
} from "../../database/index.js";
|
} from "../../database/index.js";
|
||||||
import { client } from "../client.js";
|
import { client } from "../client.js";
|
||||||
import { autoSolveMoves } from "../../game/solitaire.js";
|
|
||||||
|
|
||||||
// Constants for the AI rate limiter
|
// Constants for the AI rate limiter
|
||||||
const MAX_REQUESTS_PER_INTERVAL = parseInt(process.env.MAX_REQUESTS || "5");
|
const MAX_REQUESTS_PER_INTERVAL = parseInt(process.env.MAX_REQUESTS || "5");
|
||||||
@@ -90,7 +82,6 @@ export async function handleMessageCreate(message, client, io) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Sub-handler for AI Logic ---
|
// --- Sub-handler for AI Logic ---
|
||||||
|
|
||||||
async function handleAiMention(message, client, io) {
|
async function handleAiMention(message, client, io) {
|
||||||
const authorId = message.author.id;
|
const authorId = message.author.id;
|
||||||
let authorDB = getUser.get(authorId);
|
let authorDB = getUser.get(authorId);
|
||||||
@@ -101,7 +92,7 @@ async function handleAiMention(message, client, io) {
|
|||||||
const timestamps = (requestTimestamps.get(authorId) || []).filter((ts) => now - ts < SPAM_INTERVAL);
|
const timestamps = (requestTimestamps.get(authorId) || []).filter((ts) => now - ts < SPAM_INTERVAL);
|
||||||
|
|
||||||
if (timestamps.length >= MAX_REQUESTS_PER_INTERVAL) {
|
if (timestamps.length >= MAX_REQUESTS_PER_INTERVAL) {
|
||||||
console.log(`Rate limit exceeded for ${authorDB.username}`);
|
console.log(`[${now.toLocaleString()}] Rate limit exceeded for ${authorDB.username}`);
|
||||||
if (!authorDB.warned) {
|
if (!authorDB.warned) {
|
||||||
await message.reply(`T'abuses fréro, attends un peu ⏳`).catch(console.error);
|
await message.reply(`T'abuses fréro, attends un peu ⏳`).catch(console.error);
|
||||||
}
|
}
|
||||||
@@ -196,18 +187,11 @@ async function handleAiMention(message, client, io) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Sub-handler for Admin Commands ---
|
// --- Sub-handler for Admin Commands ---
|
||||||
|
|
||||||
async function handleAdminCommands(message) {
|
async function handleAdminCommands(message) {
|
||||||
const prefix = process.env.DEV_SITE === "true" ? "dev" : "flopo";
|
const prefix = process.env.DEV_SITE === "true" ? "dev" : "flopo";
|
||||||
const [command, ...args] = message.content.split(" ");
|
const [command, ...args] = message.content.split(" ");
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "?u":
|
|
||||||
console.log(await getAPOUsers());
|
|
||||||
break;
|
|
||||||
case "?b":
|
|
||||||
console.log(await postAPOBuy("650338922874011648", args[0]));
|
|
||||||
break;
|
|
||||||
case "?v":
|
case "?v":
|
||||||
console.log("Active Polls:", activePolls);
|
console.log("Active Polls:", activePolls);
|
||||||
break;
|
break;
|
||||||
@@ -293,673 +277,5 @@ async function handleAdminCommands(message) {
|
|||||||
});
|
});
|
||||||
console.log("Reworked", dbSkins.length, "skins.");
|
console.log("Reworked", dbSkins.length, "skins.");
|
||||||
break;
|
break;
|
||||||
case `${prefix}:solve-solitaire`:
|
|
||||||
autoSolveMoves({
|
|
||||||
tableauPiles: [
|
|
||||||
[
|
|
||||||
{ suit: "d", rank: "K", faceUp: true },
|
|
||||||
{ suit: "s", rank: "Q", faceUp: true },
|
|
||||||
{ suit: "d", rank: "J", faceUp: true },
|
|
||||||
{ suit: "c", rank: "T", faceUp: true },
|
|
||||||
{ suit: "h", rank: "9", faceUp: true },
|
|
||||||
{ suit: "c", rank: "8", faceUp: true },
|
|
||||||
{ suit: "h", rank: "7", faceUp: true },
|
|
||||||
{ suit: "c", rank: "6", faceUp: true },
|
|
||||||
{ suit: "h", rank: "5", faceUp: true },
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{ suit: "h", rank: "K", faceUp: true },
|
|
||||||
{ suit: "c", rank: "Q", faceUp: true },
|
|
||||||
{ suit: "h", rank: "J", faceUp: true },
|
|
||||||
{ suit: "s", rank: "T", faceUp: true },
|
|
||||||
{ suit: "d", rank: "9", faceUp: true },
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{ suit: "s", rank: "K", faceUp: true },
|
|
||||||
{ suit: "d", rank: "Q", faceUp: true },
|
|
||||||
{ suit: "c", rank: "J", faceUp: true },
|
|
||||||
{ suit: "h", rank: "T", faceUp: true },
|
|
||||||
{ suit: "c", rank: "9", faceUp: true },
|
|
||||||
{ suit: "h", rank: "8", faceUp: true },
|
|
||||||
],
|
|
||||||
[],
|
|
||||||
[],
|
|
||||||
[
|
|
||||||
{ suit: "c", rank: "K", faceUp: true },
|
|
||||||
{ suit: "h", rank: "Q", faceUp: true },
|
|
||||||
{ suit: "s", rank: "J", faceUp: true },
|
|
||||||
{ suit: "d", rank: "T", faceUp: true },
|
|
||||||
{ suit: "s", rank: "9", faceUp: true },
|
|
||||||
{ suit: "d", rank: "8", faceUp: true },
|
|
||||||
{ suit: "c", rank: "7", faceUp: true },
|
|
||||||
{ suit: "h", rank: "6", faceUp: true },
|
|
||||||
{ suit: "c", rank: "5", faceUp: true },
|
|
||||||
{ suit: "h", rank: "4", faceUp: true },
|
|
||||||
],
|
|
||||||
[{ suit: "h", rank: "3", faceUp: true }],
|
|
||||||
],
|
|
||||||
foundationPiles: [
|
|
||||||
[
|
|
||||||
{ suit: "c", rank: "A", faceUp: true },
|
|
||||||
{ suit: "c", rank: "2", faceUp: true },
|
|
||||||
{ suit: "c", rank: "3", faceUp: true },
|
|
||||||
{ suit: "c", rank: "4", faceUp: true },
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{ suit: "h", rank: "A", faceUp: true },
|
|
||||||
{ suit: "h", rank: "2", faceUp: true },
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{ suit: "s", rank: "A", faceUp: true },
|
|
||||||
{ suit: "s", rank: "2", faceUp: true },
|
|
||||||
{ suit: "s", rank: "3", faceUp: true },
|
|
||||||
{ suit: "s", rank: "4", faceUp: true },
|
|
||||||
{ suit: "s", rank: "5", faceUp: true },
|
|
||||||
{ suit: "s", rank: "6", faceUp: true },
|
|
||||||
{ suit: "s", rank: "7", faceUp: true },
|
|
||||||
{ suit: "s", rank: "8", faceUp: true },
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{ suit: "d", rank: "A", faceUp: true },
|
|
||||||
{ suit: "d", rank: "2", faceUp: true },
|
|
||||||
{ suit: "d", rank: "3", faceUp: true },
|
|
||||||
{ suit: "d", rank: "4", faceUp: true },
|
|
||||||
{ suit: "d", rank: "5", faceUp: true },
|
|
||||||
{ suit: "d", rank: "6", faceUp: true },
|
|
||||||
{ suit: "d", rank: "7", faceUp: true },
|
|
||||||
],
|
|
||||||
],
|
|
||||||
stockPile: [],
|
|
||||||
wastePile: [],
|
|
||||||
seed: "mgqnxweyjp8fggj6ol9",
|
|
||||||
isSOTD: false,
|
|
||||||
score: 205,
|
|
||||||
moves: 90,
|
|
||||||
hist: [
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 3,
|
|
||||||
sourceCardIndex: 3,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 4,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "9", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 6,
|
|
||||||
sourceCardIndex: 6,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "A", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 5,
|
|
||||||
sourceCardIndex: 5,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 1,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "5", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 5,
|
|
||||||
sourceCardIndex: 4,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 1,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "4", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 6,
|
|
||||||
sourceCardIndex: 5,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "9", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 6,
|
|
||||||
sourceCardIndex: 4,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 1,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "A", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 6,
|
|
||||||
sourceCardIndex: 3,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 2,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "8", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 6,
|
|
||||||
sourceCardIndex: 2,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "8", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "2", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 1,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "2", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "Q", faceUp: true } },
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "5", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 1,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 3,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "5", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "K", faceUp: true } },
|
|
||||||
{ move: "draw", card: { suit: "c", rank: "J", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 2,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 6,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "J", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 4,
|
|
||||||
sourceCardIndex: 4,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 6,
|
|
||||||
cardsMoved: [
|
|
||||||
{ suit: "h", rank: "T", faceUp: true },
|
|
||||||
{ suit: "c", rank: "9", faceUp: true },
|
|
||||||
],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "4", faceUp: true } },
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "K", faceUp: true } },
|
|
||||||
{ move: "draw", card: { suit: "s", rank: "3", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 4,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 1,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "3", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "c", rank: "K", faceUp: true } },
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "7", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 5,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "7", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 3,
|
|
||||||
sourceCardIndex: 2,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [
|
|
||||||
{ suit: "c", rank: "6", faceUp: true },
|
|
||||||
{ suit: "h", rank: "5", faceUp: true },
|
|
||||||
],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "8", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 5,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 6,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "8", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "c", rank: "Q", faceUp: true } },
|
|
||||||
{ move: "draw", card: { suit: "s", rank: "A", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 6,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 2,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "A", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "J", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 6,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 5,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "J", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 0,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 5,
|
|
||||||
cardsMoved: [
|
|
||||||
{ suit: "c", rank: "T", faceUp: true },
|
|
||||||
{ suit: "h", rank: "9", faceUp: true },
|
|
||||||
{ suit: "c", rank: "8", faceUp: true },
|
|
||||||
{ suit: "h", rank: "7", faceUp: true },
|
|
||||||
{ suit: "c", rank: "6", faceUp: true },
|
|
||||||
{ suit: "h", rank: "5", faceUp: true },
|
|
||||||
],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "c", rank: "4", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 6,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 5,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "4", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "s", rank: "5", faceUp: true } },
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "J", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 4,
|
|
||||||
sourceCardIndex: 3,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 5,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "3", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "c", rank: "2", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 8,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "2", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "c", rank: "7", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 8,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 2,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "7", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 1,
|
|
||||||
sourceCardIndex: 1,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 2,
|
|
||||||
cardsMoved: [
|
|
||||||
{ suit: "h", rank: "6", faceUp: true },
|
|
||||||
{ suit: "c", rank: "5", faceUp: true },
|
|
||||||
{ suit: "h", rank: "4", faceUp: true },
|
|
||||||
{ suit: "s", rank: "3", faceUp: true },
|
|
||||||
],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "5", faceUp: true } },
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "A", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 9,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 3,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "A", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "c", rank: "3", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 9,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "3", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "7", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 9,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 3,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "7", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "6", faceUp: true } },
|
|
||||||
{ move: "draw-reset" },
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "Q", faceUp: true } },
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "K", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 1,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "K", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 5,
|
|
||||||
sourceCardIndex: 3,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [
|
|
||||||
{ suit: "s", rank: "Q", faceUp: true },
|
|
||||||
{ suit: "d", rank: "J", faceUp: true },
|
|
||||||
{ suit: "c", rank: "T", faceUp: true },
|
|
||||||
{ suit: "h", rank: "9", faceUp: true },
|
|
||||||
{ suit: "c", rank: "8", faceUp: true },
|
|
||||||
{ suit: "h", rank: "7", faceUp: true },
|
|
||||||
{ suit: "c", rank: "6", faceUp: true },
|
|
||||||
{ suit: "h", rank: "5", faceUp: true },
|
|
||||||
{ suit: "c", rank: "4", faceUp: true },
|
|
||||||
{ suit: "d", rank: "3", faceUp: true },
|
|
||||||
],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 5,
|
|
||||||
sourceCardIndex: 2,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 2,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "2", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 2,
|
|
||||||
sourceCardIndex: 8,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 2,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "3", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 1,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 2,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "4", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 5,
|
|
||||||
sourceCardIndex: 1,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 3,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "2", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 0,
|
|
||||||
sourceCardIndex: 10,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 3,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "3", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 0,
|
|
||||||
sourceCardIndex: 9,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 0,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "4", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 5,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 6,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "7", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "4", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 1,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 3,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "4", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "K", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 1,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 1,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "K", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "c", rank: "K", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 1,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 5,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "K", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 5,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "Q", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 4,
|
|
||||||
sourceCardIndex: 2,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 5,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "J", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "c", rank: "Q", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 1,
|
|
||||||
cardsMoved: [{ suit: "c", rank: "Q", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "s", rank: "5", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 2,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "5", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "h", rank: "J", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 1,
|
|
||||||
cardsMoved: [{ suit: "h", rank: "J", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 4,
|
|
||||||
sourceCardIndex: 1,
|
|
||||||
destPileType: "tableauPiles",
|
|
||||||
destPileIndex: 1,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "T", faceUp: true }],
|
|
||||||
cardWasFlipped: true,
|
|
||||||
points: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "tableauPiles",
|
|
||||||
sourcePileIndex: 4,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 2,
|
|
||||||
cardsMoved: [{ suit: "s", rank: "6", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "5", faceUp: true } },
|
|
||||||
{
|
|
||||||
move: "move",
|
|
||||||
sourcePileType: "wastePile",
|
|
||||||
sourcePileIndex: null,
|
|
||||||
sourceCardIndex: 0,
|
|
||||||
destPileType: "foundationPiles",
|
|
||||||
destPileIndex: 3,
|
|
||||||
cardsMoved: [{ suit: "d", rank: "5", faceUp: true }],
|
|
||||||
cardWasFlipped: false,
|
|
||||||
points: 11,
|
|
||||||
},
|
|
||||||
{ move: "draw", card: { suit: "d", rank: "6", faceUp: true } },
|
|
||||||
],
|
|
||||||
hardMode: false,
|
|
||||||
autocompleting: false,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ export const updateManyUsers = flopoDB.transaction(async (users) => {
|
|||||||
try {
|
try {
|
||||||
await updateUser.run(user);
|
await updateUser.run(user);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("user update failed");
|
console.log(`[${Date.now().toLocaleString()}] user update failed`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ export async function settleAll(room) {
|
|||||||
});
|
});
|
||||||
p.bank = coins + hand.bet + res.delta;
|
p.bank = coins + hand.bet + res.delta;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,7 +326,7 @@ export async function settleAll(room) {
|
|||||||
hand.delta = res.delta;
|
hand.delta = res.delta;
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
||||||
const msg = await generalChannel.messages.fetch(p.msgId);
|
const msg = await generalChannel.messages.fetch(p.msgId);
|
||||||
const updatedEmbed = new EmbedBuilder()
|
const updatedEmbed = new EmbedBuilder()
|
||||||
.setDescription(`<@${p.id}> joue au Blackjack.`)
|
.setDescription(`<@${p.id}> joue au Blackjack.`)
|
||||||
@@ -346,7 +346,7 @@ export async function settleAll(room) {
|
|||||||
.setTimestamp(new Date());
|
.setTimestamp(new Date());
|
||||||
await msg.edit({ embeds: [updatedEmbed], components: [] });
|
await msg.edit({ embeds: [updatedEmbed], components: [] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { getUser, getUserElo, insertElos, updateElo, insertGame } from "../database/index.js";
|
import { getUser, getUserElo, insertElos, insertGame, updateElo } from "../database/index.js";
|
||||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
import { ButtonStyle, EmbedBuilder } from "discord.js";
|
||||||
import { client } from "../bot/client.js";
|
import { client } from "../bot/client.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +15,7 @@ export async function eloHandler(p1Id, p2Id, p1Score, p2Score, type) {
|
|||||||
const p1DB = getUser.get(p1Id);
|
const p1DB = getUser.get(p1Id);
|
||||||
const p2DB = getUser.get(p2Id);
|
const p2DB = getUser.get(p2Id);
|
||||||
if (!p1DB || !p2DB) {
|
if (!p1DB || !p2DB) {
|
||||||
console.error(`Elo Handler: Could not find user data for ${p1Id} or ${p2Id}.`);
|
console.error(`[${Date.now().toLocaleString()}] Elo Handler: Could not find user data for ${p1Id} or ${p2Id}.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,10 +51,14 @@ export async function eloHandler(p1Id, p2Id, p1Score, p2Score, type) {
|
|||||||
const finalP1Elo = Math.max(0, p1NewElo);
|
const finalP1Elo = Math.max(0, p1NewElo);
|
||||||
const finalP2Elo = Math.max(0, p2NewElo);
|
const finalP2Elo = Math.max(0, p2NewElo);
|
||||||
|
|
||||||
console.log(`Elo Update (${type}) for ${p1DB.globalName}: ${p1CurrentElo} -> ${finalP1Elo}`);
|
console.log(
|
||||||
console.log(`Elo Update (${type}) for ${p2DB.globalName}: ${p2CurrentElo} -> ${finalP2Elo}`);
|
`[${Date.now().toLocaleString()}] Elo Update (${type}) for ${p1DB.globalName}: ${p1CurrentElo} -> ${finalP1Elo}`,
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`[${Date.now().toLocaleString()}] Elo Update (${type}) for ${p2DB.globalName}: ${p2CurrentElo} -> ${finalP2Elo}`,
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
const generalChannel = await client.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = await client.channels.fetch(process.env.BOT_CHANNEL_ID);
|
||||||
const user1 = await client.users.fetch(p1Id);
|
const user1 = await client.users.fetch(p1Id);
|
||||||
const user2 = await client.users.fetch(p2Id);
|
const user2 = await client.users.fetch(p2Id);
|
||||||
const diff1 = finalP1Elo - p1CurrentElo;
|
const diff1 = finalP1Elo - p1CurrentElo;
|
||||||
@@ -70,7 +74,7 @@ export async function eloHandler(p1Id, p2Id, p1Score, p2Score, type) {
|
|||||||
.setColor("#5865f2");
|
.setColor("#5865f2");
|
||||||
await generalChannel.send({ embeds: [embed] });
|
await generalChannel.send({ embeds: [embed] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Failed to post elo update message`, e);
|
console.error(`[${Date.now().toLocaleString()}] Failed to post elo update message`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- 4. Update Database ---
|
// --- 4. Update Database ---
|
||||||
@@ -156,7 +160,7 @@ export async function pokerEloHandler(room) {
|
|||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error(`Error calculating new Elo for ${player.globalName}.`);
|
console.error(`[${Date.now().toLocaleString()}] Error calculating new Elo for ${player.globalName}.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export async function slowmodesHandler(message) {
|
|||||||
|
|
||||||
// Check if the slowmode duration has passed
|
// Check if the slowmode duration has passed
|
||||||
if (now > authorSlowmode.endAt) {
|
if (now > authorSlowmode.endAt) {
|
||||||
console.log(`Slowmode for ${author.username} has expired.`);
|
console.log(`[${Date.now().toLocaleString()}] Slowmode for ${author.username} has expired.`);
|
||||||
delete activeSlowmodes[author.id];
|
delete activeSlowmodes[author.id];
|
||||||
return { deleted: false, expired: true };
|
return { deleted: false, expired: true };
|
||||||
}
|
}
|
||||||
@@ -97,10 +97,10 @@ export async function slowmodesHandler(message) {
|
|||||||
if (authorSlowmode.lastMessage && now - authorSlowmode.lastMessage < 60 * 1000) {
|
if (authorSlowmode.lastMessage && now - authorSlowmode.lastMessage < 60 * 1000) {
|
||||||
try {
|
try {
|
||||||
await message.delete();
|
await message.delete();
|
||||||
console.log(`Deleted a message from slowmoded user: ${author.username}`);
|
console.log(`[${Date.now().toLocaleString()}] Deleted a message from slowmoded user: ${author.username}`);
|
||||||
return { deleted: true, expired: false };
|
return { deleted: true, expired: false };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Failed to delete slowmode message:`, err);
|
console.error(`[${Date.now().toLocaleString()}] Failed to delete slowmode message:`, err);
|
||||||
return { deleted: false, expired: false };
|
return { deleted: false, expired: false };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -144,7 +144,7 @@ export function randomSkinPrice() {
|
|||||||
* This function clears previous stats, awards the winner, and generates a new daily seed.
|
* This function clears previous stats, awards the winner, and generates a new daily seed.
|
||||||
*/
|
*/
|
||||||
export function initTodaysSOTD() {
|
export function initTodaysSOTD() {
|
||||||
console.log("Initializing new Solitaire of the Day...");
|
console.log(`[${Date.now().toLocaleString()}] Initializing new Solitaire of the Day...`);
|
||||||
|
|
||||||
// 1. Award previous day's winner
|
// 1. Award previous day's winner
|
||||||
const rankings = getAllSOTDStats.all();
|
const rankings = getAllSOTDStats.all();
|
||||||
@@ -165,7 +165,7 @@ export function initTodaysSOTD() {
|
|||||||
user_new_amount: newCoinTotal,
|
user_new_amount: newCoinTotal,
|
||||||
});
|
});
|
||||||
console.log(
|
console.log(
|
||||||
`${winnerUser.globalName || winnerUser.username} won the previous SOTD and received ${reward} coins.`,
|
`[${Date.now().toLocaleString()}] ${winnerUser.globalName || winnerUser.username} won the previous SOTD and received ${reward} coins.`,
|
||||||
);
|
);
|
||||||
insertGame.run({
|
insertGame.run({
|
||||||
id: `${winnerId}-${Date.now()}`,
|
id: `${winnerId}-${Date.now()}`,
|
||||||
@@ -206,8 +206,8 @@ export function initTodaysSOTD() {
|
|||||||
wastePile: JSON.stringify(todaysSOTD.wastePile),
|
wastePile: JSON.stringify(todaysSOTD.wastePile),
|
||||||
seed: newRandomSeed,
|
seed: newRandomSeed,
|
||||||
});
|
});
|
||||||
console.log("Today's SOTD is ready with a new seed.");
|
console.log(`[${Date.now().toLocaleString()}] Today's SOTD is ready with a new seed.`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error saving new SOTD to database:", e);
|
console.error(`[${Date.now().toLocaleString()}] Error saving new SOTD to database:`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// --- Constants for Deck Creation ---
|
// --- Constants for Deck Creation ---
|
||||||
import { sleep } from "openai/core";
|
import { emitSolitaireUpdate } from "../server/socket.js";
|
||||||
import { emitSolitaireUpdate, emitUpdate } from "../server/socket.js";
|
|
||||||
|
|
||||||
const SUITS = ["h", "d", "s", "c"]; // Hearts, Diamonds, Spades, Clubs
|
const SUITS = ["h", "d", "s", "c"]; // Hearts, Diamonds, Spades, Clubs
|
||||||
const RANKS = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"];
|
const RANKS = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"];
|
||||||
@@ -370,7 +369,6 @@ export function autoSolveMoves(userId, gameState) {
|
|||||||
*/
|
*/
|
||||||
export function undoMove(gameState) {
|
export function undoMove(gameState) {
|
||||||
if (!gameState.hist || gameState.hist.length === 0) {
|
if (!gameState.hist || gameState.hist.length === 0) {
|
||||||
console.log("No moves to undo.");
|
|
||||||
return; // Nothing to undo
|
return; // Nothing to undo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,11 +96,14 @@ export function apiRoutes(client, io) {
|
|||||||
user_new_amount: 5000,
|
user_new_amount: 5000,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`New registered user: ${discordUser.username} (${discordUser.id})`);
|
console.log(`[${Date.now().toLocaleString()}] New registered user: ${discordUser.username} (${discordUser.id})`);
|
||||||
|
|
||||||
res.status(200).json({ message: `Bienvenue ${discordUser.username} !` });
|
res.status(200).json({ message: `Bienvenue ${discordUser.username} !` });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Failed to register user ${discordUser.username} (${discordUser.id})`, e);
|
console.log(
|
||||||
|
`[${Date.now().toLocaleString()}] Failed to register user ${discordUser.username} (${discordUser.id})`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
res.status(500).json({ error: "Erreur lors de la création du nouvel utilisateur." });
|
res.status(500).json({ error: "Erreur lors de la création du nouvel utilisateur." });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -273,7 +276,6 @@ export function apiRoutes(client, io) {
|
|||||||
await socketEmit("daily-queried", { userId: id });
|
await socketEmit("daily-queried", { userId: id });
|
||||||
res.status(200).json({ message: `+${amount} FlopoCoins! Récompense récupérée !` });
|
res.status(200).json({ message: `+${amount} FlopoCoins! Récompense récupérée !` });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log();
|
|
||||||
res.status(500).json({ error: "Failed to process daily reward." });
|
res.status(500).json({ error: "Failed to process daily reward." });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -320,10 +322,12 @@ export function apiRoutes(client, io) {
|
|||||||
user_new_amount: newCoins,
|
user_new_amount: newCoins,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`${commandUserId} change nickname of ${userId}: ${old_nickname} -> ${nickname}`);
|
console.log(
|
||||||
|
`[${Date.now().toLocaleString()}] ${commandUserId} change nickname of ${userId}: ${old_nickname} -> ${nickname}`,
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setDescription(`<@${commandUserId}> a modifié le pseudo de <@${userId}>`)
|
.setDescription(`<@${commandUserId}> a modifié le pseudo de <@${userId}>`)
|
||||||
.addFields(
|
.addFields(
|
||||||
@@ -336,7 +340,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
await generalChannel.send({ embeds: [embed] });
|
await generalChannel.send({ embeds: [embed] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
@@ -380,7 +384,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setDescription(`<@${commandUserId}> a envoyé un spam ping à <@${userId}>`)
|
.setDescription(`<@${commandUserId}> a envoyé un spam ping à <@${userId}>`)
|
||||||
.setColor("#5865f2")
|
.setColor("#5865f2")
|
||||||
@@ -388,15 +392,15 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
await generalChannel.send({ embeds: [embed] });
|
await generalChannel.send({ embeds: [embed] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 1; i < 120; i++) {
|
for (let i = 1; i < 120; i++) {
|
||||||
await discordUser.send(`<@${userId}>`);
|
await discordUser.send(`<@${userId}>`);
|
||||||
await sleep(250);
|
await sleep(250);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (e) {
|
||||||
console.log(err);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
res.status(500).json({ message: "Oups ça n'a pas marché" });
|
res.status(500).json({ message: "Oups ça n'a pas marché" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -439,7 +443,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setDescription(`<@${commandUserId}> a retiré son slowmode`)
|
.setDescription(`<@${commandUserId}> a retiré son slowmode`)
|
||||||
.setColor("#5865f2")
|
.setColor("#5865f2")
|
||||||
@@ -447,7 +451,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
await generalChannel.send({ embeds: [embed] });
|
await generalChannel.send({ embeds: [embed] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
return res.status(200).json({ message: "Slowmode retiré" });
|
return res.status(200).json({ message: "Slowmode retiré" });
|
||||||
} else {
|
} else {
|
||||||
@@ -485,7 +489,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setDescription(`<@${commandUserId}> a mis <@${userId}> en slowmode pendant 1h`)
|
.setDescription(`<@${commandUserId}> a mis <@${userId}> en slowmode pendant 1h`)
|
||||||
.setColor("#5865f2")
|
.setColor("#5865f2")
|
||||||
@@ -493,7 +497,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
await generalChannel.send({ embeds: [embed] });
|
await generalChannel.send({ embeds: [embed] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
@@ -536,7 +540,7 @@ export function apiRoutes(client, io) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
return res.status(403).send({ message: `Impossible de time-out ${user.globalName}` });
|
return res.status(403).send({ message: `Impossible de time-out ${user.globalName}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,7 +558,7 @@ export function apiRoutes(client, io) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setDescription(`<@${commandUserId}> a retiré son time-out`)
|
.setDescription(`<@${commandUserId}> a retiré son time-out`)
|
||||||
.setColor("#5865f2")
|
.setColor("#5865f2")
|
||||||
@@ -562,7 +566,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
await generalChannel.send({ embeds: [embed] });
|
await generalChannel.send({ embeds: [embed] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
return res.status(200).json({ message: "Time-out retiré" });
|
return res.status(200).json({ message: "Time-out retiré" });
|
||||||
}
|
}
|
||||||
@@ -583,7 +587,7 @@ export function apiRoutes(client, io) {
|
|||||||
body: { communication_disabled_until: timeoutUntil },
|
body: { communication_disabled_until: timeoutUntil },
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
return res.status(403).send({ message: `Impossible de time-out ${user.globalName}` });
|
return res.status(403).send({ message: `Impossible de time-out ${user.globalName}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,7 +608,7 @@ export function apiRoutes(client, io) {
|
|||||||
await emitDataUpdated({ table: "users", action: "update" });
|
await emitDataUpdated({ table: "users", action: "update" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setDescription(`<@${commandUserId}> a time-out <@${userId}> pour 12h`)
|
.setDescription(`<@${commandUserId}> a time-out <@${userId}> pour 12h`)
|
||||||
.setColor("#5865f2")
|
.setColor("#5865f2")
|
||||||
@@ -612,7 +616,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
await generalChannel.send({ embeds: [embed] });
|
await generalChannel.send({ embeds: [embed] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).json({ message: `${user.globalName} est maintenant time-out pour 12h` });
|
return res.status(200).json({ message: `${user.globalName} est maintenant time-out pour 12h` });
|
||||||
@@ -645,7 +649,7 @@ export function apiRoutes(client, io) {
|
|||||||
let msgId;
|
let msgId;
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(`Prédiction de ${commandUser.username}`)
|
.setTitle(`Prédiction de ${commandUser.username}`)
|
||||||
.setDescription(`**${label}**`)
|
.setDescription(`**${label}**`)
|
||||||
@@ -684,7 +688,7 @@ export function apiRoutes(client, io) {
|
|||||||
});
|
});
|
||||||
msgId = msg.id;
|
msgId = msg.id;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
return res.status(500).send({ message: "Erreur lors de l'envoi du message" });
|
return res.status(500).send({ message: "Erreur lors de l'envoi du message" });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -825,7 +829,7 @@ export function apiRoutes(client, io) {
|
|||||||
user_new_amount: tempUser.coins + v.amount,
|
user_new_amount: tempUser.coins + v.amount,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Impossible de rembourser ${v.id} (${v.amount} coins)`);
|
console.log(`[${Date.now().toLocaleString()}] Impossible de rembourser ${v.id} (${v.amount} coins)`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
activePredis[predi].options[1].votes.forEach((v) => {
|
activePredis[predi].options[1].votes.forEach((v) => {
|
||||||
@@ -844,7 +848,7 @@ export function apiRoutes(client, io) {
|
|||||||
user_new_amount: tempUser.coins + v.amount,
|
user_new_amount: tempUser.coins + v.amount,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Impossible de rembourser ${v.id} (${v.amount} coins)`);
|
console.log(`[${Date.now().toLocaleString()}] Impossible de rembourser ${v.id} (${v.amount} coins)`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
activePredis[predi].closed = true;
|
activePredis[predi].closed = true;
|
||||||
@@ -870,7 +874,9 @@ export function apiRoutes(client, io) {
|
|||||||
user_new_amount: tempUser.coins + v.amount * (1 + ratio),
|
user_new_amount: tempUser.coins + v.amount * (1 + ratio),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Impossible de créditer ${v.id} (${v.amount} coins pariés, *${1 + ratio})`);
|
console.log(
|
||||||
|
`[${Date.now().toLocaleString()}] Impossible de créditer ${v.id} (${v.amount} coins pariés, *${1 + ratio})`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
activePredis[predi].paidTime = new Date();
|
activePredis[predi].paidTime = new Date();
|
||||||
@@ -880,7 +886,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
||||||
const message = await generalChannel.messages.fetch(activePredis[predi].msgId);
|
const message = await generalChannel.messages.fetch(activePredis[predi].msgId);
|
||||||
const updatedEmbed = new EmbedBuilder()
|
const updatedEmbed = new EmbedBuilder()
|
||||||
.setTitle(`Prédiction de ${commandUser.username}`)
|
.setTitle(`Prédiction de ${commandUser.username}`)
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
// /routes/blackjack.js
|
// /routes/blackjack.js
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import {
|
import {
|
||||||
createBlackjackRoom,
|
|
||||||
startBetting,
|
|
||||||
dealInitial,
|
|
||||||
autoActions,
|
|
||||||
everyoneDone,
|
|
||||||
dealerPlay,
|
|
||||||
settleAll,
|
|
||||||
applyAction,
|
applyAction,
|
||||||
publicPlayerView,
|
autoActions,
|
||||||
handValue,
|
createBlackjackRoom,
|
||||||
dealerShouldHit,
|
dealerShouldHit,
|
||||||
|
dealInitial,
|
||||||
draw,
|
draw,
|
||||||
|
everyoneDone,
|
||||||
|
handValue,
|
||||||
|
publicPlayerView,
|
||||||
|
settleAll,
|
||||||
|
startBetting,
|
||||||
} from "../../game/blackjack.js";
|
} from "../../game/blackjack.js";
|
||||||
|
|
||||||
// Optional: hook into your DB & Discord systems if available
|
// Optional: hook into your DB & Discord systems if available
|
||||||
import { getUser, updateUserCoins, insertLog } from "../../database/index.js";
|
import { getUser, insertLog, updateUserCoins } from "../../database/index.js";
|
||||||
import { client } from "../../bot/client.js";
|
import { client } from "../../bot/client.js";
|
||||||
import { emitToast, emitUpdate } from "../socket.js";
|
import { emitToast, emitUpdate } from "../socket.js";
|
||||||
import { EmbedBuilder } from "discord.js";
|
import { EmbedBuilder } from "discord.js";
|
||||||
@@ -154,7 +153,7 @@ export function blackjackRoutes(io) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setDescription(`<@${userId}> joue au Blackjack`)
|
.setDescription(`<@${userId}> joue au Blackjack`)
|
||||||
.addFields(
|
.addFields(
|
||||||
@@ -175,7 +174,7 @@ export function blackjackRoutes(io) {
|
|||||||
const msg = await generalChannel.send({ embeds: [embed] });
|
const msg = await generalChannel.send({ embeds: [embed] });
|
||||||
room.players[userId].msgId = msg.id;
|
room.players[userId].msgId = msg.id;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
emitUpdate("player-joined", snapshot(room));
|
emitUpdate("player-joined", snapshot(room));
|
||||||
@@ -188,7 +187,7 @@ export function blackjackRoutes(io) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
||||||
const msg = await generalChannel.messages.fetch(room.players[userId].msgId);
|
const msg = await generalChannel.messages.fetch(room.players[userId].msgId);
|
||||||
const updatedEmbed = new EmbedBuilder()
|
const updatedEmbed = new EmbedBuilder()
|
||||||
.setDescription(`<@${userId}> a quitté la table de Blackjack.`)
|
.setDescription(`<@${userId}> a quitté la table de Blackjack.`)
|
||||||
@@ -208,7 +207,7 @@ export function blackjackRoutes(io) {
|
|||||||
.setTimestamp(new Date());
|
.setTimestamp(new Date());
|
||||||
await msg.edit({ embeds: [updatedEmbed], components: [] });
|
await msg.edit({ embeds: [updatedEmbed], components: [] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
const p = room.players[userId];
|
const p = room.players[userId];
|
||||||
|
|||||||
@@ -79,9 +79,6 @@ export function marketRoutes(client, io) {
|
|||||||
router.post("/offers/:id/place-bid", async (req, res) => {
|
router.post("/offers/:id/place-bid", async (req, res) => {
|
||||||
const { buyer_id, bid_amount, timestamp } = req.body;
|
const { buyer_id, bid_amount, timestamp } = req.body;
|
||||||
try {
|
try {
|
||||||
console.log(getMarketOfferById.get(req.params.id));
|
|
||||||
console.log(buyer_id, bid_amount, timestamp);
|
|
||||||
|
|
||||||
const offer = getMarketOfferById.get(req.params.id);
|
const offer = getMarketOfferById.get(req.params.id);
|
||||||
if (!offer) return res.status(404).send({ error: "Offer not found" });
|
if (!offer) return res.status(404).send({ error: "Offer not found" });
|
||||||
if (offer.closing_at < timestamp) return res.status(403).send({ error: "Bidding period has ended" });
|
if (offer.closing_at < timestamp) return res.status(403).send({ error: "Bidding period has ended" });
|
||||||
@@ -129,7 +126,7 @@ export function marketRoutes(client, io) {
|
|||||||
|
|
||||||
res.status(200).send({ message: "Bid placed successfully" });
|
res.status(200).send({ message: "Bid placed successfully" });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
res.status(500).send({ error: e });
|
res.status(500).send({ error: e });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import { uniqueNamesGenerator, adjectives } from "unique-names-generator";
|
import { adjectives, uniqueNamesGenerator } from "unique-names-generator";
|
||||||
import pkg from "pokersolver";
|
import pkg from "pokersolver";
|
||||||
const { Hand } = pkg;
|
|
||||||
|
|
||||||
import { pokerRooms } from "../../game/state.js";
|
import { pokerRooms } from "../../game/state.js";
|
||||||
import {
|
import {
|
||||||
initialShuffledCards,
|
|
||||||
getFirstActivePlayerAfterDealer,
|
|
||||||
getNextActivePlayer,
|
|
||||||
checkEndOfBettingRound,
|
checkEndOfBettingRound,
|
||||||
checkRoomWinners,
|
checkRoomWinners,
|
||||||
|
getFirstActivePlayerAfterDealer,
|
||||||
|
getNextActivePlayer,
|
||||||
|
initialShuffledCards,
|
||||||
} from "../../game/poker.js";
|
} from "../../game/poker.js";
|
||||||
import { pokerEloHandler } from "../../game/elo.js";
|
import { getUser, insertLog, updateUserCoins } from "../../database/index.js";
|
||||||
import { getUser, updateUserCoins, insertLog } from "../../database/index.js";
|
|
||||||
import { sleep } from "openai/core";
|
import { sleep } from "openai/core";
|
||||||
import { client } from "../../bot/client.js";
|
import { client } from "../../bot/client.js";
|
||||||
import { emitPokerToast, emitPokerUpdate } from "../socket.js";
|
import { emitPokerToast, emitPokerUpdate } from "../socket.js";
|
||||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||||
import { formatAmount } from "../../utils/index.js";
|
import { formatAmount } from "../../utils/index.js";
|
||||||
|
|
||||||
|
const { Hand } = pkg;
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,7 +89,7 @@ export function pokerRoutes(client, io) {
|
|||||||
await emitPokerUpdate({ room: pokerRooms[id], type: "room-created" });
|
await emitPokerUpdate({ room: pokerRooms[id], type: "room-created" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const generalChannel = guild.channels.cache.find((ch) => ch.name === "général" || ch.name === "general");
|
const generalChannel = guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("Flopoker 🃏")
|
.setTitle("Flopoker 🃏")
|
||||||
.setDescription(`<@${creatorId}> a créé une table de poker`)
|
.setDescription(`<@${creatorId}> a créé une table de poker`)
|
||||||
@@ -119,7 +118,7 @@ export function pokerRoutes(client, io) {
|
|||||||
|
|
||||||
await generalChannel.send({ embeds: [embed], components: [row] });
|
await generalChannel.send({ embeds: [embed], components: [row] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(201).json({ roomId: id });
|
res.status(201).json({ roomId: id });
|
||||||
@@ -192,7 +191,7 @@ export function pokerRoutes(client, io) {
|
|||||||
await checkRoundCompletion(pokerRooms[roomId], io);
|
await checkRoundCompletion(pokerRooms[roomId], io);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
await emitPokerUpdate({ type: "player-afk" });
|
await emitPokerUpdate({ type: "player-afk" });
|
||||||
@@ -216,7 +215,7 @@ export function pokerRoutes(client, io) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
await emitPokerUpdate({ type: "player-left" });
|
await emitPokerUpdate({ type: "player-left" });
|
||||||
@@ -256,7 +255,7 @@ export function pokerRoutes(client, io) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(`[${Date.now().toLocaleString()}]`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
await emitPokerUpdate({ type: "player-kicked" });
|
await emitPokerUpdate({ type: "player-kicked" });
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
import { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||||
import {
|
import {
|
||||||
activeTicTacToeGames,
|
|
||||||
tictactoeQueue,
|
|
||||||
activeConnect4Games,
|
activeConnect4Games,
|
||||||
|
activeTicTacToeGames,
|
||||||
connect4Queue,
|
connect4Queue,
|
||||||
queueMessagesEndpoints,
|
queueMessagesEndpoints,
|
||||||
activePredis,
|
tictactoeQueue,
|
||||||
} from "../game/state.js";
|
} from "../game/state.js";
|
||||||
import {
|
import {
|
||||||
|
C4_ROWS,
|
||||||
|
checkConnect4Draw,
|
||||||
|
checkConnect4Win,
|
||||||
createConnect4Board,
|
createConnect4Board,
|
||||||
formatConnect4BoardForDiscord,
|
formatConnect4BoardForDiscord,
|
||||||
checkConnect4Win,
|
|
||||||
checkConnect4Draw,
|
|
||||||
C4_ROWS,
|
|
||||||
} from "../game/various.js";
|
} from "../game/various.js";
|
||||||
import { eloHandler } from "../game/elo.js";
|
import { eloHandler } from "../game/elo.js";
|
||||||
import { getUser } from "../database/index.js";
|
|
||||||
|
|
||||||
// --- Module-level State ---
|
// --- Module-level State ---
|
||||||
let io;
|
let io;
|
||||||
@@ -294,7 +292,7 @@ async function refreshQueuesForUser(userId, client) {
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
tictactoeQueue.splice(index, 1);
|
tictactoeQueue.splice(index, 1);
|
||||||
try {
|
try {
|
||||||
const generalChannel = await client.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = await client.channels.fetch(process.env.BOT_CHANNEL_ID);
|
||||||
const user = await client.users.fetch(userId);
|
const user = await client.users.fetch(userId);
|
||||||
const queueMsg = await generalChannel.messages.fetch(queueMessagesEndpoints[userId]);
|
const queueMsg = await generalChannel.messages.fetch(queueMessagesEndpoints[userId]);
|
||||||
const updatedEmbed = new EmbedBuilder()
|
const updatedEmbed = new EmbedBuilder()
|
||||||
@@ -313,7 +311,7 @@ async function refreshQueuesForUser(userId, client) {
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
connect4Queue.splice(index, 1);
|
connect4Queue.splice(index, 1);
|
||||||
try {
|
try {
|
||||||
const generalChannel = await client.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = await client.channels.fetch(process.env.BOT_CHANNEL_ID);
|
||||||
const user = await client.users.fetch(userId);
|
const user = await client.users.fetch(userId);
|
||||||
const queueMsg = await generalChannel.messages.fetch(queueMessagesEndpoints[userId]);
|
const queueMsg = await generalChannel.messages.fetch(queueMessagesEndpoints[userId]);
|
||||||
const updatedEmbed = new EmbedBuilder()
|
const updatedEmbed = new EmbedBuilder()
|
||||||
@@ -366,7 +364,7 @@ function getGameAssets(gameType) {
|
|||||||
|
|
||||||
async function postQueueToDiscord(client, playerId, title, url) {
|
async function postQueueToDiscord(client, playerId, title, url) {
|
||||||
try {
|
try {
|
||||||
const generalChannel = await client.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = await client.channels.fetch(process.env.BOT_CHANNEL_ID);
|
||||||
const user = await client.users.fetch(playerId);
|
const user = await client.users.fetch(playerId);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
@@ -390,7 +388,7 @@ async function postQueueToDiscord(client, playerId, title, url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateDiscordMessage(client, game, title, resultText = "") {
|
async function updateDiscordMessage(client, game, title, resultText = "") {
|
||||||
const channel = await client.channels.fetch(process.env.GENERAL_CHANNEL_ID).catch(() => null);
|
const channel = await client.channels.fetch(process.env.BOT_CHANNEL_ID).catch(() => null);
|
||||||
if (!channel) return null;
|
if (!channel) return null;
|
||||||
|
|
||||||
let description;
|
let description;
|
||||||
@@ -444,6 +442,7 @@ function cleanupStaleGames() {
|
|||||||
export async function socketEmit(event, data) {
|
export async function socketEmit(event, data) {
|
||||||
io.emit(event, data);
|
io.emit(event, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function emitDataUpdated(data) {
|
export async function emitDataUpdated(data) {
|
||||||
io.emit("data-updated", data);
|
io.emit("data-updated", data);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user