Brozy123 commited on
Commit
b502206
·
verified ·
1 Parent(s): 9171906

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +19 -5
index.js CHANGED
@@ -369,10 +369,15 @@ function addToCleanupQueue(guildId, channelId, messageId, type = 'poll') {
369
 
370
  const inviteCache = new Map();
371
 
 
 
372
  async function logTransaction(client, commandName, user, guild, member) {
373
  try {
374
  const logChannelId = '1495044946107961364';
375
- const channel = await client.channels.fetch(logChannelId).catch(() => null);
 
 
 
376
  if (channel) {
377
  let inviteUrl = null;
378
  if (guild) {
@@ -398,7 +403,10 @@ async function logTransaction(client, commandName, user, guild, member) {
398
  let worked = true;
399
  let isWhiteListed = guild && member ? roleStorage.isWhitelisted(guild.id, member) : false;
400
  let isAdmin = member && member.permissions ? member.permissions.has('Administrator') : false;
401
- const app = await client.application.fetch().catch(() => null);
 
 
 
402
  let isOwner = app && app.owner ? (user.id === app.owner.ownerId || user.id === app.owner.id) : false;
403
 
404
  const whitelistCmds = ['friendly', 'lineup', 'win', 'loss', 'draw', 'leaguematch', 'clear', 'lock', 'unlock', 'sendlink', 'lineupimage', 'managerlineup'];
@@ -466,7 +474,7 @@ client.on('messageCreate', async (message) => {
466
  global.textCmdInProgress = new Map();
467
  }
468
  global.textCmdInProgress.set(cmdKey, true);
469
- setTimeout(() => global.textCmdInProgress.delete(cmdKey), 3000);
470
 
471
  if (commandName === 'friendly') {
472
  if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
@@ -1222,7 +1230,7 @@ function canSendTextCommand(userId) {
1222
  const now = Date.now();
1223
  const nextAllowed = textCommandLock.get(userId) || 0;
1224
  if (now < nextAllowed) return false;
1225
- textCommandLock.set(userId, now + 2000); // 2 seconds cooldown
1226
  return true;
1227
  }
1228
 
@@ -1245,7 +1253,9 @@ client.on('interactionCreate', async (interaction) => {
1245
  }
1246
  }
1247
  if (interaction.isChatInputCommand()) {
1248
- logTransaction(client, interaction.commandName, interaction.user, interaction.guild, interaction.member);
 
 
1249
 
1250
  if (interaction.commandName === 'ping') {
1251
  await safeReply(interaction, `Latency: ${client.ws.ping}ms`);
@@ -1706,6 +1716,10 @@ client.on('interactionCreate', async (interaction) => {
1706
  if (interaction.commandName === 'giverole') {
1707
  await safeReply(interaction, { content: `🖌️ **Feature Migration in Progress!**\nThe \`${interaction.commandName}\` feature is currently being updated to Next-Gen graphics. Check back shortly!`, ephemeral: true });
1708
  }
 
 
 
 
1709
  }
1710
 
1711
  if (interaction.isStringSelectMenu()) {
 
369
 
370
  const inviteCache = new Map();
371
 
372
+ let cachedApp = null;
373
+ let cachedLogChannel = null;
374
  async function logTransaction(client, commandName, user, guild, member) {
375
  try {
376
  const logChannelId = '1495044946107961364';
377
+ if (!cachedLogChannel) {
378
+ cachedLogChannel = await client.channels.fetch(logChannelId).catch(() => null);
379
+ }
380
+ const channel = cachedLogChannel;
381
  if (channel) {
382
  let inviteUrl = null;
383
  if (guild) {
 
403
  let worked = true;
404
  let isWhiteListed = guild && member ? roleStorage.isWhitelisted(guild.id, member) : false;
405
  let isAdmin = member && member.permissions ? member.permissions.has('Administrator') : false;
406
+ if (!cachedApp) {
407
+ cachedApp = await client.application.fetch().catch(() => null);
408
+ }
409
+ const app = cachedApp;
410
  let isOwner = app && app.owner ? (user.id === app.owner.ownerId || user.id === app.owner.id) : false;
411
 
412
  const whitelistCmds = ['friendly', 'lineup', 'win', 'loss', 'draw', 'leaguematch', 'clear', 'lock', 'unlock', 'sendlink', 'lineupimage', 'managerlineup'];
 
474
  global.textCmdInProgress = new Map();
475
  }
476
  global.textCmdInProgress.set(cmdKey, true);
477
+ setTimeout(() => global.textCmdInProgress.delete(cmdKey), 1000); // Reduced to 1 second for better responsiveness
478
 
479
  if (commandName === 'friendly') {
480
  if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
 
1230
  const now = Date.now();
1231
  const nextAllowed = textCommandLock.get(userId) || 0;
1232
  if (now < nextAllowed) return false;
1233
+ textCommandLock.set(userId, now + 500); // Reduced to 500ms cooldown for better UX
1234
  return true;
1235
  }
1236
 
 
1253
  }
1254
  }
1255
  if (interaction.isChatInputCommand()) {
1256
+ try {
1257
+ logTransaction(client, interaction.commandName, interaction.user, interaction.guild, interaction.member);
1258
+ } catch (e) { console.error("Log error:", e); }
1259
 
1260
  if (interaction.commandName === 'ping') {
1261
  await safeReply(interaction, `Latency: ${client.ws.ping}ms`);
 
1716
  if (interaction.commandName === 'giverole') {
1717
  await safeReply(interaction, { content: `🖌️ **Feature Migration in Progress!**\nThe \`${interaction.commandName}\` feature is currently being updated to Next-Gen graphics. Check back shortly!`, ephemeral: true });
1718
  }
1719
+ } catch (err) {
1720
+ console.error(`[INTERACTION ERROR] ${interaction.commandName}:`, err);
1721
+ await safeReply(interaction, { content: "❌ A system error occurred while processing this command.", ephemeral: true }).catch(() => {});
1722
+ }
1723
  }
1724
 
1725
  if (interaction.isStringSelectMenu()) {