diff --git a/src/bot/handlers/messageCreate.js b/src/bot/handlers/messageCreate.js index 3d84eaf..d572844 100644 --- a/src/bot/handlers/messageCreate.js +++ b/src/bot/handlers/messageCreate.js @@ -1,9 +1,10 @@ import { sleep } from 'openai/core'; import { gork } from '../../utils/ai.js'; -import { formatTime, postAPOBuy, getAPOUsers } from '../../utils/index.js'; +import {formatTime, postAPOBuy, getAPOUsers, getAkhys} from '../../utils/index.js'; import { channelPointsHandler, slowmodesHandler, randomSkinPrice, initTodaysSOTD } from '../../game/points.js'; import { requestTimestamps, activeSlowmodes, activePolls, skins } from '../../game/state.js'; import { flopoDB, getUser, getAllUsers, updateManyUsers } from '../../database/index.js'; +import {client} from "../client.js"; // Constants for the AI rate limiter const MAX_REQUESTS_PER_INTERVAL = parseInt(process.env.MAX_REQUESTS || "5"); @@ -187,5 +188,7 @@ async function handleAdminCommands(message) { message.reply(`SQL Error: ${e.message}`); } break; + case `${prefix}:fetch-data`: + await getAkhys(client); } } \ No newline at end of file diff --git a/src/utils/index.js b/src/utils/index.js index 6419f4f..186dd8b 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -8,7 +8,7 @@ import { DiscordRequest } from '../api/discord.js'; import { initTodaysSOTD } from '../game/points.js'; import { insertManyUsers, insertManySkins, resetDailyReward, - pruneOldLogs, getAllUsers as dbGetAllUsers, getSOTD, + pruneOldLogs, getAllUsers as dbGetAllUsers, getSOTD, getUser, getAllUsers, } from '../database/index.js'; import { activeInventories, activeSearchs, activePredis, pokerRooms, skins } from '../game/state.js'; @@ -34,6 +34,7 @@ export async function InstallGlobalCommands(appId, commands) { export async function getAkhys(client) { try { // 1. Fetch Discord Members + const initial_akhys = getAllUsers.all().length; const guild = await client.guilds.fetch(process.env.GUILD_ID); const members = await guild.members.fetch(); const akhys = members.filter(m => !m.user.bot && m.roles.cache.has(process.env.AKHY_ROLE_ID)); @@ -47,7 +48,11 @@ export async function getAkhys(client) { if (usersToInsert.length > 0) { insertManyUsers(usersToInsert); } - console.log(`[Sync] Found and synced ${akhys.size} users with the 'Akhy' role.`); + + const new_akhys = getAllUsers.all().length; + const diff = new_akhys - initial_akhys + + console.log(`[Sync] Found and synced ${usersToInsert.length} ${diff !== 0 ? '(' + (diff > 0 ? '+' + diff : diff) + ') ' : ''}users with the 'Akhy' role. (ID:${process.env.AKHY_ROLE_ID})`); // 2. Fetch Valorant Skins const [fetchedSkins, fetchedTiers] = await Promise.all([getValorantSkins(), getSkinTiers()]);