mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-03-18 21:40:27 +01:00
Merge pull request #82 from cassoule/milo-260310
reduce discord requests
This commit is contained in:
@@ -12,7 +12,7 @@ export async function handleInfoCommand(req, res, client) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch the guild object from the client
|
// Fetch the guild object from the client
|
||||||
const guild = await client.guilds.fetch(guild_id);
|
const guild = client.guilds.cache.get(guild_id);
|
||||||
|
|
||||||
// Fetch all members to ensure the cache is up to date
|
// Fetch all members to ensure the cache is up to date
|
||||||
await guild.members.fetch();
|
await guild.members.fetch();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { activeInventories, skins } from "../../game/state.js";
|
|||||||
import * as skinService from "../../services/skin.service.js";
|
import * as skinService from "../../services/skin.service.js";
|
||||||
import * as csSkinService from "../../services/csSkin.service.js";
|
import * as csSkinService from "../../services/csSkin.service.js";
|
||||||
import { RarityToColor } from "../../utils/cs.utils.js";
|
import { RarityToColor } from "../../utils/cs.utils.js";
|
||||||
|
import { resolveMember } from "../../utils/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the /inventory slash command.
|
* Handles the /inventory slash command.
|
||||||
@@ -31,8 +32,8 @@ export async function handleInventoryCommand(req, res, client, interactionId) {
|
|||||||
const targetUserId = data.options && data.options.length > 0 ? data.options[0].value : commandUserId;
|
const targetUserId = data.options && data.options.length > 0 ? data.options[0].value : commandUserId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(guild_id);
|
const guild = client.guilds.cache.get(guild_id);
|
||||||
const targetMember = await guild.members.fetch(targetUserId);
|
const targetMember = await resolveMember(guild, targetUserId);
|
||||||
|
|
||||||
// Fetch both Valorant and CS2 inventories
|
// Fetch both Valorant and CS2 inventories
|
||||||
const valoSkins = await skinService.getUserInventory(targetUserId);
|
const valoSkins = await skinService.getUserInventory(targetUserId);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
} from "discord-interactions";
|
} from "discord-interactions";
|
||||||
import { activeSearchs, skins } from "../../game/state.js";
|
import { activeSearchs, skins } from "../../game/state.js";
|
||||||
import * as skinService from "../../services/skin.service.js";
|
import * as skinService from "../../services/skin.service.js";
|
||||||
|
import { resolveMember } from "../../utils/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the /search slash command.
|
* Handles the /search slash command.
|
||||||
@@ -52,7 +53,7 @@ export async function handleSearchCommand(req, res, client, interactionId) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// --- 4. Prepare Initial Embed Content ---
|
// --- 4. Prepare Initial Embed Content ---
|
||||||
const guild = await client.guilds.fetch(guild_id);
|
const guild = client.guilds.cache.get(guild_id);
|
||||||
const currentSkin = resultSkins[0];
|
const currentSkin = resultSkins[0];
|
||||||
const skinData = skins.find((s) => s.uuid === currentSkin.uuid);
|
const skinData = skins.find((s) => s.uuid === currentSkin.uuid);
|
||||||
if (!skinData) {
|
if (!skinData) {
|
||||||
@@ -63,7 +64,7 @@ export async function handleSearchCommand(req, res, client, interactionId) {
|
|||||||
let ownerText = "";
|
let ownerText = "";
|
||||||
if (currentSkin.userId) {
|
if (currentSkin.userId) {
|
||||||
try {
|
try {
|
||||||
const owner = await guild.members.fetch(currentSkin.userId);
|
const owner = await resolveMember(guild, currentSkin.userId);
|
||||||
ownerText = `| **@${owner.user.globalName || owner.user.username}** ✅`;
|
ownerText = `| **@${owner.user.globalName || owner.user.username}** ✅`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`Could not fetch owner for user ID: ${currentSkin.userId}`);
|
console.warn(`Could not fetch owner for user ID: ${currentSkin.userId}`);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { InteractionResponseType } from "discord-interactions";
|
import { InteractionResponseType } from "discord-interactions";
|
||||||
import * as skinService from "../../services/skin.service.js";
|
import * as skinService from "../../services/skin.service.js";
|
||||||
|
import { resolveMember } from "../../utils/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the /skins slash command.
|
* Handles the /skins slash command.
|
||||||
@@ -14,7 +15,7 @@ export async function handleSkinsCommand(req, res, client) {
|
|||||||
try {
|
try {
|
||||||
// --- 1. Fetch Data ---
|
// --- 1. Fetch Data ---
|
||||||
const topSkins = await skinService.getTopSkins();
|
const topSkins = await skinService.getTopSkins();
|
||||||
const guild = await client.guilds.fetch(guild_id);
|
const guild = client.guilds.cache.get(guild_id);
|
||||||
const fields = [];
|
const fields = [];
|
||||||
|
|
||||||
// --- 2. Build Embed Fields Asynchronously ---
|
// --- 2. Build Embed Fields Asynchronously ---
|
||||||
@@ -25,7 +26,7 @@ export async function handleSkinsCommand(req, res, client) {
|
|||||||
// If the skin has an owner, fetch their details
|
// If the skin has an owner, fetch their details
|
||||||
if (skin.userId) {
|
if (skin.userId) {
|
||||||
try {
|
try {
|
||||||
const owner = await guild.members.fetch(skin.userId);
|
const owner = await resolveMember(guild, skin.userId);
|
||||||
// Use globalName if available, otherwise fallback to username
|
// Use globalName if available, otherwise fallback to username
|
||||||
ownerText = `**@${owner.user.globalName || owner.user.username}** ✅`;
|
ownerText = `**@${owner.user.globalName || owner.user.username}** ✅`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
ButtonStyleTypes,
|
ButtonStyleTypes,
|
||||||
} from "discord-interactions";
|
} from "discord-interactions";
|
||||||
|
|
||||||
import { formatTime, getOnlineUsersWithRole } from "../../utils/index.js";
|
import { formatTime, getOnlineUsersWithRole, resolveMember } from "../../utils/index.js";
|
||||||
import { DiscordRequest } from "../../api/discord.js";
|
import { DiscordRequest } from "../../api/discord.js";
|
||||||
import { activePolls } from "../../game/state.js";
|
import { activePolls } from "../../game/state.js";
|
||||||
import { getSocketIo } from "../../server/socket.js";
|
import { getSocketIo } from "../../server/socket.js";
|
||||||
@@ -28,9 +28,9 @@ export async function handleTimeoutCommand(req, res, client) {
|
|||||||
const time = options[1].value;
|
const time = options[1].value;
|
||||||
|
|
||||||
// Fetch member objects from Discord
|
// Fetch member objects from Discord
|
||||||
const guild = await client.guilds.fetch(guild_id);
|
const guild = client.guilds.cache.get(guild_id);
|
||||||
const fromMember = await guild.members.fetch(userId);
|
const fromMember = await resolveMember(guild, userId);
|
||||||
const toMember = await guild.members.fetch(targetUserId);
|
const toMember = await resolveMember(guild, targetUserId);
|
||||||
|
|
||||||
// --- Validation Checks ---
|
// --- Validation Checks ---
|
||||||
// 1. Check if a poll is already running for the target user
|
// 1. Check if a poll is already running for the target user
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
import { DiscordRequest } from "../../api/discord.js";
|
import { DiscordRequest } from "../../api/discord.js";
|
||||||
import { activeInventories } from "../../game/state.js";
|
import { activeInventories } from "../../game/state.js";
|
||||||
import { buildSkinEmbed } from "../commands/inventory.js";
|
import { buildSkinEmbed } from "../commands/inventory.js";
|
||||||
|
import { resolveMember } from "../../utils/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles navigation button clicks (Previous/Next) for the inventory embed.
|
* Handles navigation button clicks (Previous/Next) for the inventory embed.
|
||||||
@@ -55,8 +56,8 @@ export async function handleInventoryNav(req, res, client) {
|
|||||||
const currentPage = inventorySession.page;
|
const currentPage = inventorySession.page;
|
||||||
const currentSkin = inventorySkins[currentPage];
|
const currentSkin = inventorySkins[currentPage];
|
||||||
|
|
||||||
const guild = await client.guilds.fetch(guild_id);
|
const guild = client.guilds.cache.get(guild_id);
|
||||||
const targetMember = await guild.members.fetch(inventorySession.akhyId);
|
const targetMember = await resolveMember(guild, inventorySession.akhyId);
|
||||||
const totalPrice = inventorySkins.reduce((sum, skin) => {
|
const totalPrice = inventorySkins.reduce((sum, skin) => {
|
||||||
return sum + (skin._type === "cs" ? skin.price || 0 : skin.currentPrice || 0);
|
return sum + (skin._type === "cs" ? skin.price || 0 : skin.currentPrice || 0);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
|
|
||||||
import { DiscordRequest } from "../../api/discord.js";
|
import { DiscordRequest } from "../../api/discord.js";
|
||||||
import { activeSearchs, skins } from "../../game/state.js";
|
import { activeSearchs, skins } from "../../game/state.js";
|
||||||
|
import { resolveUser } from "../../utils/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles navigation button clicks (Previous/Next) for the search results embed.
|
* Handles navigation button clicks (Previous/Next) for the search results embed.
|
||||||
@@ -67,7 +68,7 @@ export async function handleSearchNav(req, res, client) {
|
|||||||
let ownerText = "";
|
let ownerText = "";
|
||||||
if (currentSkin.userId) {
|
if (currentSkin.userId) {
|
||||||
try {
|
try {
|
||||||
const owner = await client.users.fetch(currentSkin.userId);
|
const owner = await resolveUser(client, currentSkin.userId);
|
||||||
ownerText = `| **@${owner.globalName || owner.username}** ✅`;
|
ownerText = `| **@${owner.globalName || owner.username}** ✅`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`Could not fetch owner for user ID: ${currentSkin.userId}`);
|
console.warn(`Could not fetch owner for user ID: ${currentSkin.userId}`);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
MAX_ATTS_PER_MESSAGE,
|
MAX_ATTS_PER_MESSAGE,
|
||||||
stripMentionsOfBot,
|
stripMentionsOfBot,
|
||||||
} from "../../utils/ai.js";
|
} from "../../utils/ai.js";
|
||||||
import { calculateBasePrice, calculateMaxPrice, formatTime, getAkhys } from "../../utils/index.js";
|
import { calculateBasePrice, calculateMaxPrice, formatTime, getAkhys, resolveMember } 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 prisma from "../../prisma/client.js";
|
import prisma from "../../prisma/client.js";
|
||||||
@@ -106,7 +106,7 @@ async function handleAiMention(message, client, io) {
|
|||||||
// Apply timeout if warn count is too high
|
// Apply timeout if warn count is too high
|
||||||
if (authorDB.warns > (parseInt(process.env.MAX_WARNS) || 10)) {
|
if (authorDB.warns > (parseInt(process.env.MAX_WARNS) || 10)) {
|
||||||
try {
|
try {
|
||||||
const member = await message.guild.members.fetch(authorId);
|
const member = await resolveMember(message.guild, authorId);
|
||||||
const time = parseInt(process.env.SPAM_TIMEOUT_TIME);
|
const time = parseInt(process.env.SPAM_TIMEOUT_TIME);
|
||||||
await member.timeout(time, "Spam excessif du bot AI.");
|
await member.timeout(time, "Spam excessif du bot AI.");
|
||||||
message.channel
|
message.channel
|
||||||
@@ -255,7 +255,7 @@ async function handleAdminCommands(message) {
|
|||||||
await getAkhys(client);
|
await getAkhys(client);
|
||||||
break;
|
break;
|
||||||
case `${prefix}:avatars`:
|
case `${prefix}:avatars`:
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const members = await guild.members.fetch();
|
const members = await guild.members.fetch();
|
||||||
const akhys = members.filter((m) => !m.user.bot && m.roles.cache.has(process.env.AKHY_ROLE_ID));
|
const akhys = members.filter((m) => !m.user.bot && m.roles.cache.has(process.env.AKHY_ROLE_ID));
|
||||||
|
|
||||||
|
|||||||
@@ -323,8 +323,8 @@ export async function settleAll(room) {
|
|||||||
hand.result = res.result;
|
hand.result = res.result;
|
||||||
hand.delta = res.delta;
|
hand.delta = res.delta;
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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.`)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import * as userService from "../services/user.service.js";
|
|||||||
import * as gameService from "../services/game.service.js";
|
import * as gameService from "../services/game.service.js";
|
||||||
import { ButtonStyle, EmbedBuilder } from "discord.js";
|
import { ButtonStyle, EmbedBuilder } from "discord.js";
|
||||||
import { client } from "../bot/client.js";
|
import { client } from "../bot/client.js";
|
||||||
|
import { resolveUser } from "../utils/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles Elo calculation for a standard 1v1 game.
|
* Handles Elo calculation for a standard 1v1 game.
|
||||||
@@ -72,9 +73,9 @@ export async function eloHandler(p1Id, p2Id, p1Score, p2Score, type, scores = nu
|
|||||||
console.log(`Elo Update (${type}) for ${p1DB.globalName}: ${p1CurrentElo} -> ${finalP1Elo}`);
|
console.log(`Elo Update (${type}) for ${p1DB.globalName}: ${p1CurrentElo} -> ${finalP1Elo}`);
|
||||||
console.log(`Elo Update (${type}) for ${p2DB.globalName}: ${p2CurrentElo} -> ${finalP2Elo}`);
|
console.log(`Elo Update (${type}) for ${p2DB.globalName}: ${p2CurrentElo} -> ${finalP2Elo}`);
|
||||||
try {
|
try {
|
||||||
const generalChannel = await client.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const generalChannel = client.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
const user1 = await client.users.fetch(p1Id);
|
const user1 = await resolveUser(client, p1Id);
|
||||||
const user2 = await client.users.fetch(p2Id);
|
const user2 = await resolveUser(client, p2Id);
|
||||||
const diff1 = finalP1Elo - p1CurrentElo;
|
const diff1 = finalP1Elo - p1CurrentElo;
|
||||||
const diff2 = finalP2Elo - p2CurrentElo;
|
const diff2 = finalP2Elo - p2CurrentElo;
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import * as csSkinService from "../../services/csSkin.service.js";
|
|||||||
import { activePolls, activePredis, activeSlowmodes, skins, activeSnakeGames } from "../../game/state.js";
|
import { activePolls, activePredis, activeSlowmodes, skins, activeSnakeGames } from "../../game/state.js";
|
||||||
|
|
||||||
// --- Utility and API Imports ---
|
// --- Utility and API Imports ---
|
||||||
import { formatTime, isMeleeSkin, isVCTSkin, isChampionsSkin, getVCTRegion } from "../../utils/index.js";
|
import { formatTime, isMeleeSkin, isVCTSkin, isChampionsSkin, getVCTRegion, resolveUser, resolveMember } from "../../utils/index.js";
|
||||||
import { DiscordRequest } from "../../api/discord.js";
|
import { DiscordRequest } from "../../api/discord.js";
|
||||||
|
|
||||||
// --- Discord.js Builder Imports ---
|
// --- Discord.js Builder Imports ---
|
||||||
@@ -64,7 +64,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
router.post("/register-user", requireAuth, async (req, res) => {
|
router.post("/register-user", requireAuth, async (req, res) => {
|
||||||
const discordUserId = req.userId;
|
const discordUserId = req.userId;
|
||||||
const discordUser = await client.users.fetch(discordUserId);
|
const discordUser = await resolveUser(client, discordUserId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await userService.insertUser({
|
await userService.insertUser({
|
||||||
@@ -594,7 +594,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
router.get("/user/:id/avatar", async (req, res) => {
|
router.get("/user/:id/avatar", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const user = await client.users.fetch(req.params.id);
|
const user = await resolveUser(client, req.params.id);
|
||||||
const avatarUrl = user.displayAvatarURL({ format: "png", size: 256 });
|
const avatarUrl = user.displayAvatarURL({ format: "png", size: 256 });
|
||||||
res.json({ avatarUrl });
|
res.json({ avatarUrl });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -604,7 +604,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
router.get("/user/:id/username", async (req, res) => {
|
router.get("/user/:id/username", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const user = await client.users.fetch(req.params.id);
|
const user = await resolveUser(client, req.params.id);
|
||||||
res.json({ user });
|
res.json({ user });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(404).json({ error: "User not found." });
|
res.status(404).json({ error: "User not found." });
|
||||||
@@ -729,8 +729,8 @@ export function apiRoutes(client, io) {
|
|||||||
router.post("/timedout", requireAuth, async (req, res) => {
|
router.post("/timedout", requireAuth, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.userId;
|
const userId = req.userId;
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const member = await guild.members.fetch(userId);
|
const member = await resolveMember(guild, userId);
|
||||||
res.status(200).json({ isTimedOut: member?.isCommunicationDisabled() || false });
|
res.status(200).json({ isTimedOut: member?.isCommunicationDisabled() || false });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(404).send({ message: "Member not found or guild unavailable." });
|
res.status(404).send({ message: "Member not found or guild unavailable." });
|
||||||
@@ -747,8 +747,8 @@ export function apiRoutes(client, io) {
|
|||||||
if (commandUser.coins < 1000) return res.status(403).json({ message: "Pas assez de FlopoCoins (1000 requis)." });
|
if (commandUser.coins < 1000) return res.status(403).json({ message: "Pas assez de FlopoCoins (1000 requis)." });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const member = await guild.members.fetch(userId);
|
const member = await resolveMember(guild, userId);
|
||||||
const old_nickname = member.nickname;
|
const old_nickname = member.nickname;
|
||||||
await member.setNickname(nickname);
|
await member.setNickname(nickname);
|
||||||
|
|
||||||
@@ -766,7 +766,7 @@ export function apiRoutes(client, io) {
|
|||||||
console.log(`${commandUserId} change nickname of ${userId}: ${old_nickname} -> ${nickname}`);
|
console.log(`${commandUserId} change nickname of ${userId}: ${old_nickname} -> ${nickname}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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(
|
||||||
@@ -802,7 +802,7 @@ export function apiRoutes(client, io) {
|
|||||||
if (commandUser.coins < 5000) return res.status(403).json({ message: "Pas assez de coins" });
|
if (commandUser.coins < 5000) return res.status(403).json({ message: "Pas assez de coins" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const discordUser = await client.users.fetch(userId);
|
const discordUser = await resolveUser(client, userId);
|
||||||
|
|
||||||
await discordUser.send(`<@${userId}>`);
|
await discordUser.send(`<@${userId}>`);
|
||||||
|
|
||||||
@@ -820,8 +820,8 @@ export function apiRoutes(client, io) {
|
|||||||
await emitDataUpdated({ table: "users", action: "update" });
|
await emitDataUpdated({ table: "users", action: "update" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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")
|
||||||
@@ -877,8 +877,8 @@ export function apiRoutes(client, io) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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")
|
||||||
@@ -920,8 +920,8 @@ export function apiRoutes(client, io) {
|
|||||||
await emitDataUpdated({ table: "users", action: "update" });
|
await emitDataUpdated({ table: "users", action: "update" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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")
|
||||||
@@ -952,8 +952,8 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
if (!user) return res.status(403).send({ message: "Oups petit problème" });
|
if (!user) return res.status(403).send({ message: "Oups petit problème" });
|
||||||
|
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const member = await guild.members.fetch(userId);
|
const member = await resolveMember(guild, userId);
|
||||||
|
|
||||||
if (userId === commandUserId) {
|
if (userId === commandUserId) {
|
||||||
if (
|
if (
|
||||||
@@ -988,7 +988,7 @@ export function apiRoutes(client, io) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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")
|
||||||
@@ -1035,7 +1035,7 @@ export function apiRoutes(client, io) {
|
|||||||
await emitDataUpdated({ table: "users", action: "update" });
|
await emitDataUpdated({ table: "users", action: "update" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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")
|
||||||
@@ -1076,8 +1076,8 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
let msgId;
|
let msgId;
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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}**`)
|
||||||
@@ -1298,8 +1298,8 @@ export function apiRoutes(client, io) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.GENERAL_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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}`)
|
||||||
@@ -1570,7 +1570,7 @@ export function apiRoutes(client, io) {
|
|||||||
|
|
||||||
// Notify user via Discord if possible
|
// Notify user via Discord if possible
|
||||||
try {
|
try {
|
||||||
const discordUser = await client.users.fetch(commandUserId);
|
const discordUser = await resolveUser(client, commandUserId);
|
||||||
await discordUser.send(
|
await discordUser.send(
|
||||||
`✅ Votre achat de ${expectedCoins} FlopoCoins a été confirmé ! Merci pour votre soutien !`,
|
`✅ Votre achat de ${expectedCoins} FlopoCoins a été confirmé ! Merci pour votre soutien !`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { client } from "../../bot/client.js";
|
|||||||
import { emitToast, emitUpdate, emitPlayerUpdate } from "../socket.js";
|
import { emitToast, emitUpdate, emitPlayerUpdate } from "../socket.js";
|
||||||
import { EmbedBuilder, time } from "discord.js";
|
import { EmbedBuilder, time } from "discord.js";
|
||||||
import { requireAuth } from "../middleware/auth.js";
|
import { requireAuth } from "../middleware/auth.js";
|
||||||
|
import { resolveUser } from "../../utils/index.js";
|
||||||
|
|
||||||
export function blackjackRoutes(io) {
|
export function blackjackRoutes(io) {
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@@ -126,7 +127,7 @@ export function blackjackRoutes(io) {
|
|||||||
const userId = req.userId;
|
const userId = req.userId;
|
||||||
if (room.players[userId]) return res.status(200).json({ message: "Already here" });
|
if (room.players[userId]) return res.status(200).json({ message: "Already here" });
|
||||||
|
|
||||||
const user = await client.users.fetch(userId);
|
const user = await resolveUser(client, userId);
|
||||||
const bank = (await userService.getUser(userId))?.coins ?? 0;
|
const bank = (await userService.getUser(userId))?.coins ?? 0;
|
||||||
|
|
||||||
room.players[userId] = {
|
room.players[userId] = {
|
||||||
@@ -155,8 +156,8 @@ export function blackjackRoutes(io) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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(
|
||||||
@@ -194,8 +195,8 @@ export function blackjackRoutes(io) {
|
|||||||
if (!room.players[userId]) return res.status(403).json({ message: "not in room" });
|
if (!room.players[userId]) return res.status(403).json({ message: "not in room" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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.`)
|
||||||
@@ -226,7 +227,7 @@ export function blackjackRoutes(io) {
|
|||||||
} else {
|
} else {
|
||||||
delete room.players[userId];
|
delete room.players[userId];
|
||||||
emitUpdate("player-left", snapshot(room));
|
emitUpdate("player-left", snapshot(room));
|
||||||
const user = await client.users.fetch(userId);
|
const user = await resolveUser(client, userId);
|
||||||
emitPlayerUpdate({
|
emitPlayerUpdate({
|
||||||
id: userId,
|
id: userId,
|
||||||
msg: `${user?.globalName || user?.username} a quitté la table de Blackjack.`,
|
msg: `${user?.globalName || user?.username} a quitté la table de Blackjack.`,
|
||||||
@@ -367,7 +368,7 @@ export function blackjackRoutes(io) {
|
|||||||
// Remove leavers
|
// Remove leavers
|
||||||
for (const userId of Object.keys(room.leavingAfterRound)) {
|
for (const userId of Object.keys(room.leavingAfterRound)) {
|
||||||
delete room.players[userId];
|
delete room.players[userId];
|
||||||
const user = await client.users.fetch(userId);
|
const user = await resolveUser(client, userId);
|
||||||
emitPlayerUpdate({
|
emitPlayerUpdate({
|
||||||
id: userId,
|
id: userId,
|
||||||
msg: `${user?.globalName || user?.username} a quitté la table de Blackjack.`,
|
msg: `${user?.globalName || user?.username} a quitté la table de Blackjack.`,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import express from "express";
|
|||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import { erinyesRooms } from "../../game/state.js";
|
import { erinyesRooms } from "../../game/state.js";
|
||||||
import { socketEmit } from "../socket.js";
|
import { socketEmit } from "../socket.js";
|
||||||
|
import { resolveUser } from "../../utils/index.js";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ export function erinyesRoutes(client, io) {
|
|||||||
res.status(404).json({ message: "You are already in a room." });
|
res.status(404).json({ message: "You are already in a room." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const creator = await client.users.fetch(creatorId);
|
const creator = await resolveUser(client, creatorId);
|
||||||
const id = uuidv4();
|
const id = uuidv4();
|
||||||
|
|
||||||
createRoom({
|
createRoom({
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ 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, resolveUser } from "../../utils/index.js";
|
||||||
import { requireAuth } from "../middleware/auth.js";
|
import { requireAuth } from "../middleware/auth.js";
|
||||||
|
|
||||||
const { Hand } = pkg;
|
const { Hand } = pkg;
|
||||||
@@ -53,8 +53,8 @@ export function pokerRoutes(client, io) {
|
|||||||
return res.status(403).json({ message: "You are already in a poker room." });
|
return res.status(403).json({ message: "You are already in a poker room." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const creator = await client.users.fetch(creatorId);
|
const creator = await resolveUser(client, creatorId);
|
||||||
const id = uuidv4();
|
const id = uuidv4();
|
||||||
const name = uniqueNamesGenerator({
|
const name = uniqueNamesGenerator({
|
||||||
dictionaries: [adjectives, ["Poker"]],
|
dictionaries: [adjectives, ["Poker"]],
|
||||||
@@ -91,7 +91,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 = await guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(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`)
|
||||||
@@ -365,7 +365,7 @@ export function pokerRoutes(client, io) {
|
|||||||
// --- Helper Functions ---
|
// --- Helper Functions ---
|
||||||
|
|
||||||
async function joinRoom(roomId, userId, io) {
|
async function joinRoom(roomId, userId, io) {
|
||||||
const user = await client.users.fetch(userId);
|
const user = await resolveUser(client, userId);
|
||||||
const userDB = await userService.getUser(userId);
|
const userDB = await userService.getUser(userId);
|
||||||
const room = pokerRooms[roomId];
|
const room = pokerRooms[roomId];
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
} from "../game/various.js";
|
} from "../game/various.js";
|
||||||
import { eloHandler } from "../game/elo.js";
|
import { eloHandler } from "../game/elo.js";
|
||||||
import { verifyToken } from "./middleware/auth.js";
|
import { verifyToken } from "./middleware/auth.js";
|
||||||
|
import { resolveUser } from "../utils/index.js";
|
||||||
|
|
||||||
// --- Module-level State ---
|
// --- Module-level State ---
|
||||||
let io;
|
let io;
|
||||||
@@ -319,7 +320,7 @@ async function createGame(client, gameType) {
|
|||||||
const { queue, activeGames, title } = getGameAssets(gameType);
|
const { queue, activeGames, title } = getGameAssets(gameType);
|
||||||
const p1Id = queue.shift();
|
const p1Id = queue.shift();
|
||||||
const p2Id = queue.shift();
|
const p2Id = queue.shift();
|
||||||
const [p1, p2] = await Promise.all([client.users.fetch(p1Id), client.users.fetch(p2Id)]);
|
const [p1, p2] = await Promise.all([resolveUser(client, p1Id), resolveUser(client, p2Id)]);
|
||||||
|
|
||||||
let lobby;
|
let lobby;
|
||||||
if (gameType === "tictactoe") {
|
if (gameType === "tictactoe") {
|
||||||
@@ -426,9 +427,9 @@ async function refreshQueuesForUser(userId, client) {
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
tictactoeQueue.splice(index, 1);
|
tictactoeQueue.splice(index, 1);
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
const user = await client.users.fetch(userId);
|
const user = await resolveUser(client, 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()
|
||||||
.setTitle("Tic Tac Toe")
|
.setTitle("Tic Tac Toe")
|
||||||
@@ -446,9 +447,9 @@ async function refreshQueuesForUser(userId, client) {
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
connect4Queue.splice(index, 1);
|
connect4Queue.splice(index, 1);
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
const user = await client.users.fetch(userId);
|
const user = await resolveUser(client, 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()
|
||||||
.setTitle("Puissance 4")
|
.setTitle("Puissance 4")
|
||||||
@@ -466,9 +467,9 @@ async function refreshQueuesForUser(userId, client) {
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
snakeQueue.splice(index, 1);
|
snakeQueue.splice(index, 1);
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const generalChannel = await guild.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const generalChannel = guild.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
const user = await client.users.fetch(userId);
|
const user = await resolveUser(client, 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()
|
||||||
.setTitle("Snake 1v1")
|
.setTitle("Snake 1v1")
|
||||||
@@ -491,7 +492,7 @@ async function emitQueueUpdate(client, gameType) {
|
|||||||
const { queue, activeGames } = getGameAssets(gameType);
|
const { queue, activeGames } = getGameAssets(gameType);
|
||||||
const names = await Promise.all(
|
const names = await Promise.all(
|
||||||
queue.map(async (id) => {
|
queue.map(async (id) => {
|
||||||
const user = await client.users.fetch(id).catch(() => null);
|
const user = await resolveUser(client, id).catch(() => null);
|
||||||
return user?.globalName || user?.username;
|
return user?.globalName || user?.username;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -528,8 +529,8 @@ 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.BOT_CHANNEL_ID);
|
const generalChannel = client.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
const user = await client.users.fetch(playerId);
|
const user = await resolveUser(client, playerId);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setDescription(`**${user.globalName || user.username}** est dans la file d'attente.`)
|
.setDescription(`**${user.globalName || user.username}** est dans la file d'attente.`)
|
||||||
@@ -552,7 +553,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.BOT_CHANNEL_ID).catch(() => null);
|
const channel = client.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
if (!channel) return null;
|
if (!channel) return null;
|
||||||
|
|
||||||
let description;
|
let description;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export async function getAkhys(client) {
|
|||||||
try {
|
try {
|
||||||
// 1. Fetch Discord Members
|
// 1. Fetch Discord Members
|
||||||
const initial_akhys = (await userService.getAllUsers()).length;
|
const initial_akhys = (await userService.getAllUsers()).length;
|
||||||
const guild = await client.guilds.fetch(process.env.GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const members = await guild.members.fetch();
|
const members = await guild.members.fetch();
|
||||||
const akhys = members.filter((m) => !m.user.bot && m.roles.cache.has(process.env.AKHY_ROLE_ID));
|
const akhys = members.filter((m) => !m.user.bot && m.roles.cache.has(process.env.AKHY_ROLE_ID));
|
||||||
|
|
||||||
@@ -547,3 +547,11 @@ export function isChampionsSkin(skinName) {
|
|||||||
const name = skinName.toLowerCase();
|
const name = skinName.toLowerCase();
|
||||||
return name.includes("champions");
|
return name.includes("champions");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function resolveUser(client, userId) {
|
||||||
|
return client.users.cache.get(userId) || await client.users.fetch(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resolveMember(guild, userId) {
|
||||||
|
return guild.members.cache.get(userId) || await guild.members.fetch(userId);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import * as skinService from "../services/skin.service.js";
|
|||||||
import * as csSkinService from "../services/csSkin.service.js";
|
import * as csSkinService from "../services/csSkin.service.js";
|
||||||
import * as marketService from "../services/market.service.js";
|
import * as marketService from "../services/market.service.js";
|
||||||
import { EmbedBuilder } from "discord.js";
|
import { EmbedBuilder } from "discord.js";
|
||||||
|
import { resolveUser } from "./index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the skin display name and icon from an offer, supporting both Valorant and CS2 skins.
|
* Gets the skin display name and icon from an offer, supporting both Valorant and CS2 skins.
|
||||||
@@ -24,7 +25,7 @@ export async function handleNewMarketOffer(offerId, client) {
|
|||||||
if (!offer) return;
|
if (!offer) return;
|
||||||
const { name: skinName, icon: skinIcon } = await getOfferSkinInfo(offer);
|
const { name: skinName, icon: skinIcon } = await getOfferSkinInfo(offer);
|
||||||
|
|
||||||
const discordUserSeller = await client.users.fetch(offer.sellerId);
|
const discordUserSeller = await resolveUser(client, offer.sellerId);
|
||||||
try {
|
try {
|
||||||
const userSeller = await userService.getUser(offer.sellerId);
|
const userSeller = await userService.getUser(offer.sellerId);
|
||||||
if (discordUserSeller && userSeller?.isAkhy) {
|
if (discordUserSeller && userSeller?.isAkhy) {
|
||||||
@@ -67,7 +68,7 @@ export async function handleNewMarketOffer(offerId, client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guildChannel = await client.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const guildChannel = client.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("🔔 Nouvelle offre")
|
.setTitle("🔔 Nouvelle offre")
|
||||||
.setDescription(`Une offre pour le skin **${skinName}** a été créée !`)
|
.setDescription(`Une offre pour le skin **${skinName}** a été créée !`)
|
||||||
@@ -105,7 +106,7 @@ export async function handleMarketOfferOpening(offerId, client) {
|
|||||||
const { name: skinName, icon: skinIcon } = await getOfferSkinInfo(offer);
|
const { name: skinName, icon: skinIcon } = await getOfferSkinInfo(offer);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const discordUserSeller = await client.users.fetch(offer.sellerId);
|
const discordUserSeller = await resolveUser(client, offer.sellerId);
|
||||||
const userSeller = await userService.getUser(offer.sellerId);
|
const userSeller = await userService.getUser(offer.sellerId);
|
||||||
if (discordUserSeller && userSeller?.isAkhy) {
|
if (discordUserSeller && userSeller?.isAkhy) {
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
@@ -145,7 +146,7 @@ export async function handleMarketOfferOpening(offerId, client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guildChannel = await client.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const guildChannel = client.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("🔔 Début des enchères")
|
.setTitle("🔔 Début des enchères")
|
||||||
.setDescription(
|
.setDescription(
|
||||||
@@ -177,7 +178,7 @@ export async function handleMarketOfferClosing(offerId, client) {
|
|||||||
const { name: skinName, icon: skinIcon } = await getOfferSkinInfo(offer);
|
const { name: skinName, icon: skinIcon } = await getOfferSkinInfo(offer);
|
||||||
const bids = await marketService.getOfferBids(offer.id);
|
const bids = await marketService.getOfferBids(offer.id);
|
||||||
|
|
||||||
const discordUserSeller = await client.users.fetch(offer.sellerId);
|
const discordUserSeller = await resolveUser(client, offer.sellerId);
|
||||||
try {
|
try {
|
||||||
const userSeller = await userService.getUser(offer.sellerId);
|
const userSeller = await userService.getUser(offer.sellerId);
|
||||||
if (discordUserSeller && userSeller?.isAkhy) {
|
if (discordUserSeller && userSeller?.isAkhy) {
|
||||||
@@ -204,7 +205,7 @@ export async function handleMarketOfferClosing(offerId, client) {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const highestBid = bids[0];
|
const highestBid = bids[0];
|
||||||
const highestBidderUser = await client.users.fetch(highestBid.bidderId);
|
const highestBidderUser = await resolveUser(client, highestBid.bidderId);
|
||||||
embed.addFields(
|
embed.addFields(
|
||||||
{
|
{
|
||||||
name: "✅ Enchères terminées avec succès !",
|
name: "✅ Enchères terminées avec succès !",
|
||||||
@@ -225,8 +226,8 @@ export async function handleMarketOfferClosing(offerId, client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.fetch(process.env.BOT_GUILD_ID);
|
const guild = client.guilds.cache.get(process.env.GUILD_ID);
|
||||||
const guildChannel = await guild.channels?.fetch(process.env.BOT_CHANNEL_ID);
|
const guildChannel = guild.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("🔔 Fin des enchères")
|
.setTitle("🔔 Fin des enchères")
|
||||||
.setDescription(
|
.setDescription(
|
||||||
@@ -243,12 +244,12 @@ export async function handleMarketOfferClosing(offerId, client) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const highestBid = bids[0];
|
const highestBid = bids[0];
|
||||||
const highestBidderUser = await client.users.fetch(highestBid.bidderId);
|
const highestBidderUser = await resolveUser(client, highestBid.bidderId);
|
||||||
embed.addFields({
|
embed.addFields({
|
||||||
name: "✅ Enchères terminées avec succès !",
|
name: "✅ Enchères terminées avec succès !",
|
||||||
value: `Le skin de <@${offer.sellerId}> ${discordUserSeller ? "(" + discordUserSeller.username + ")" : ""} a été vendu pour \`${highestBid.offerAmount} coins\` à <@${highestBid.bidderId}> ${highestBidderUser ? "(" + highestBidderUser.username + ")" : ""}.`,
|
value: `Le skin de <@${offer.sellerId}> ${discordUserSeller ? "(" + discordUserSeller.username + ")" : ""} a été vendu pour \`${highestBid.offerAmount} coins\` à <@${highestBid.bidderId}> ${highestBidderUser ? "(" + highestBidderUser.username + ")" : ""}.`,
|
||||||
});
|
});
|
||||||
const discordUserBidder = await client.users.fetch(highestBid.bidderId);
|
const discordUserBidder = await resolveUser(client, highestBid.bidderId);
|
||||||
const userBidder = await userService.getUser(highestBid.bidderId);
|
const userBidder = await userService.getUser(highestBid.bidderId);
|
||||||
if (discordUserBidder && userBidder?.isAkhy) {
|
if (discordUserBidder && userBidder?.isAkhy) {
|
||||||
const bidderEmbed = new EmbedBuilder()
|
const bidderEmbed = new EmbedBuilder()
|
||||||
@@ -280,9 +281,9 @@ export async function handleNewMarketOfferBid(offerId, bidId, client) {
|
|||||||
if (!bid) return;
|
if (!bid) return;
|
||||||
const { name: skinName, icon: skinIcon } = await getOfferSkinInfo(offer);
|
const { name: skinName, icon: skinIcon } = await getOfferSkinInfo(offer);
|
||||||
|
|
||||||
const bidderUser = client.users.fetch(bid.bidderId);
|
const bidderUser = await resolveUser(client, bid.bidderId);
|
||||||
try {
|
try {
|
||||||
const discordUserSeller = await client.users.fetch(offer.sellerId);
|
const discordUserSeller = await resolveUser(client, offer.sellerId);
|
||||||
const userSeller = await userService.getUser(offer.sellerId);
|
const userSeller = await userService.getUser(offer.sellerId);
|
||||||
|
|
||||||
if (discordUserSeller && userSeller?.isAkhy) {
|
if (discordUserSeller && userSeller?.isAkhy) {
|
||||||
@@ -323,7 +324,7 @@ export async function handleNewMarketOfferBid(offerId, bidId, client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const discordUserNewBidder = await client.users.fetch(bid.bidderId);
|
const discordUserNewBidder = await resolveUser(client, bid.bidderId);
|
||||||
const userNewBidder = await userService.getUser(bid.bidderId);
|
const userNewBidder = await userService.getUser(bid.bidderId);
|
||||||
if (discordUserNewBidder && userNewBidder?.isAkhy) {
|
if (discordUserNewBidder && userNewBidder?.isAkhy) {
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
@@ -350,7 +351,7 @@ export async function handleNewMarketOfferBid(offerId, bidId, client) {
|
|||||||
const offerBids = await marketService.getOfferBids(offer.id);
|
const offerBids = await marketService.getOfferBids(offer.id);
|
||||||
if (offerBids.length < 2) return;
|
if (offerBids.length < 2) return;
|
||||||
|
|
||||||
const discordUserPreviousBidder = await client.users.fetch(offerBids[1].bidderId);
|
const discordUserPreviousBidder = await resolveUser(client, offerBids[1].bidderId);
|
||||||
const userPreviousBidder = await userService.getUser(offerBids[1].bidderId);
|
const userPreviousBidder = await userService.getUser(offerBids[1].bidderId);
|
||||||
if (discordUserPreviousBidder && userPreviousBidder?.isAkhy) {
|
if (discordUserPreviousBidder && userPreviousBidder?.isAkhy) {
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
@@ -382,10 +383,10 @@ export async function handleNewMarketOfferBid(offerId, bidId, client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function handleCaseOpening(caseType, userId, skinUuid, client) {
|
export async function handleCaseOpening(caseType, userId, skinUuid, client) {
|
||||||
const discordUser = await client.users.fetch(userId);
|
const discordUser = await resolveUser(client, userId);
|
||||||
const skin = await skinService.getSkin(skinUuid);
|
const skin = await skinService.getSkin(skinUuid);
|
||||||
try {
|
try {
|
||||||
const guildChannel = await client.channels.fetch(process.env.BOT_CHANNEL_ID);
|
const guildChannel = client.channels.cache.get(process.env.BOT_CHANNEL_ID);
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("🔔 Ouverture de caisse")
|
.setTitle("🔔 Ouverture de caisse")
|
||||||
.setDescription(
|
.setDescription(
|
||||||
|
|||||||
Reference in New Issue
Block a user