Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -453,28 +453,8 @@ client.on('messageCreate', async (message) => {
|
|
| 453 |
return;
|
| 454 |
}
|
| 455 |
|
| 456 |
-
//
|
| 457 |
-
// Single-reply per command per user: 3-second lock per (guild, user, command)
|
| 458 |
-
if (typeof textCmdInProgress === 'undefined') {
|
| 459 |
-
// Will be defined below in global scope; this is a guard for patching safety
|
| 460 |
-
}
|
| 461 |
-
// Enforce a minimal cooldown between consecutive text commands per user
|
| 462 |
const userId = String(message.author?.id || 'unknown');
|
| 463 |
-
if (!canSendTextCommand(userId)) {
|
| 464 |
-
// Silently ignore if still cooling down
|
| 465 |
-
return;
|
| 466 |
-
}
|
| 467 |
-
|
| 468 |
-
// Ensure only a single reply per command for this user within a short window
|
| 469 |
-
const cmdKey = `${message.guildId}:${commandName}:${userId}`;
|
| 470 |
-
if (global.textCmdInProgress && global.textCmdInProgress.has(cmdKey)) {
|
| 471 |
-
return;
|
| 472 |
-
}
|
| 473 |
-
if (!global.textCmdInProgress) {
|
| 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);
|
|
@@ -1225,14 +1205,7 @@ async function sendNoPermission(ctx) {
|
|
| 1225 |
}
|
| 1226 |
|
| 1227 |
// Simple per-user cooldown: 2 seconds between text commands (hard lock to ensure one reply)
|
| 1228 |
-
|
| 1229 |
-
function canSendTextCommand(userId) {
|
| 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 |
|
| 1237 |
// Interaction Handler
|
| 1238 |
client.on('interactionCreate', async (interaction) => {
|
|
|
|
| 453 |
return;
|
| 454 |
}
|
| 455 |
|
| 456 |
+
// Removed locks for better responsiveness as requested by user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
const userId = String(message.author?.id || 'unknown');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
|
| 459 |
if (commandName === 'friendly') {
|
| 460 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
|
|
|
|
| 1205 |
}
|
| 1206 |
|
| 1207 |
// Simple per-user cooldown: 2 seconds between text commands (hard lock to ensure one reply)
|
| 1208 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1209 |
|
| 1210 |
// Interaction Handler
|
| 1211 |
client.on('interactionCreate', async (interaction) => {
|