This commit is contained in:
Wizzard 2025-02-05 22:12:55 -05:00
parent 129a20c894
commit 4943964b77

View File

@ -7,18 +7,26 @@ let cooldownTime = 0;
let checkInterval = null; let checkInterval = null;
const getRandomDelay = () => { const getRandomDelay = () => {
return Math.floor(Math.random() * 250) + 100; const delay = Math.floor(Math.random() * 250) + 100;
console.log(`[KICKVC] Generated event delay: ${delay}ms`);
return delay;
}; };
const getRandomCheckDelay = () => { const getRandomCheckDelay = () => {
return Math.floor(Math.random() * 250) + 200; const delay = Math.floor(Math.random() * 250) + 200;
console.log(`[KICKVC] Generated interval check delay: ${delay}ms`);
return delay;
}; };
const getCooldown = (kicks) => { const getCooldown = (kicks) => {
if (kicks <= 3) return 200; let cooldown;
if (kicks <= 5) return 500; if (kicks <= 3) cooldown = 200;
if (kicks <= 10) return 1000; else if (kicks <= 5) cooldown = 500;
return 2000; else if (kicks <= 10) cooldown = 1000;
else cooldown = 2500;
console.log(`[KICKVC] New cooldown calculated for ${kicks} kicks: ${cooldown}ms`);
return cooldown;
}; };
module.exports = { module.exports = {
@ -48,6 +56,7 @@ module.exports = {
const userId = args[0]; const userId = args[0];
if (!userId || !/^\d{17,19}$/.test(userId)) { if (!userId || !/^\d{17,19}$/.test(userId)) {
console.log('[KICKVC] Invalid user ID provided');
message.channel.send('Please provide a valid user ID.') message.channel.send('Please provide a valid user ID.')
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout)); .then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
return; return;
@ -59,9 +68,11 @@ module.exports = {
if (voiceStateHandler) { if (voiceStateHandler) {
message.client.removeListener('voiceStateUpdate', voiceStateHandler); message.client.removeListener('voiceStateUpdate', voiceStateHandler);
console.log('[KICKVC] Removed old voice state handler');
} }
if (checkInterval) { if (checkInterval) {
clearInterval(checkInterval); clearInterval(checkInterval);
console.log('[KICKVC] Cleared old check interval');
} }
const kickUser = async (member, guild, fromEvent = false) => { const kickUser = async (member, guild, fromEvent = false) => {
@ -71,33 +82,46 @@ module.exports = {
const timeSinceLastKick = currentTime - lastKickTime; const timeSinceLastKick = currentTime - lastKickTime;
if (timeSinceLastKick < cooldownTime) { if (timeSinceLastKick < cooldownTime) {
console.log(`[KICKVC] On cooldown - ${cooldownTime - timeSinceLastKick}ms remaining`);
return; return;
} }
try { try {
const delay = fromEvent ? getRandomDelay() : getRandomCheckDelay(); const delay = fromEvent ? getRandomDelay() : getRandomCheckDelay();
console.log(`[KICKVC] Waiting ${delay}ms before kick attempt...`);
await new Promise(resolve => setTimeout(resolve, delay)); await new Promise(resolve => setTimeout(resolve, delay));
if (!member.voice.channel) return; if (!member.voice.channel) {
console.log('[KICKVC] Target no longer in voice after delay');
return;
}
console.log(`[KICKVC] Target in voice: ${member.user.tag} | ${guild.name} | ${member.voice.channel.name}`); console.log(`[KICKVC] Target detected in voice: ${member.user.tag} | Server: ${guild.name} | Channel: ${member.voice.channel.name}`);
await member.voice.disconnect(); await member.voice.disconnect();
lastKickTime = currentTime; lastKickTime = currentTime;
consecutiveKicks++; consecutiveKicks++;
const oldCooldown = cooldownTime;
cooldownTime = getCooldown(consecutiveKicks); cooldownTime = getCooldown(consecutiveKicks);
console.log(`[KICKVC] Kick successful - Consecutive kicks: ${consecutiveKicks} | New cooldown: ${cooldownTime}ms (was ${oldCooldown}ms)`);
setTimeout(() => { setTimeout(() => {
if (consecutiveKicks > 0) { if (consecutiveKicks > 0) {
const oldKicks = consecutiveKicks;
const oldCd = cooldownTime;
consecutiveKicks--; consecutiveKicks--;
cooldownTime = getCooldown(consecutiveKicks); cooldownTime = getCooldown(consecutiveKicks);
console.log(`[KICKVC] Decay timer - Kicks reduced: ${oldKicks} -> ${consecutiveKicks} | Cooldown: ${oldCd}ms -> ${cooldownTime}ms`);
} }
}, 15000); }, 15000);
} catch { } catch (error) {
console.log('[KICKVC] Primary disconnect failed, trying alternate methods');
try { try {
await member.voice.setChannel(null); await member.voice.setChannel(null);
console.log('[KICKVC] Alternate method 1 successful (setChannel null)');
} catch { } catch {
try { try {
await member.voice.channel.permissionOverwrites.create(member, { await member.voice.channel.permissionOverwrites.create(member, {
@ -105,7 +129,10 @@ module.exports = {
Speak: false Speak: false
}); });
await member.voice.disconnect(); await member.voice.disconnect();
} catch { } console.log('[KICKVC] Alternate method 2 successful (permissions + disconnect)');
} catch {
console.log('[KICKVC] All disconnection methods failed');
}
} }
} }
}; };
@ -119,16 +146,22 @@ module.exports = {
const voiceState = newState?.channelId ? newState : oldState; const voiceState = newState?.channelId ? newState : oldState;
if (!voiceState?.channel) return; if (!voiceState?.channel) return;
console.log('[KICKVC] Voice state update detected for target');
try { try {
const guild = voiceState.guild; const guild = voiceState.guild;
const member = await guild.members.fetch(targetUserId).catch(() => null); const member = await guild.members.fetch(targetUserId).catch(() => null);
if (member?.voice?.channel) { if (member?.voice?.channel) {
await kickUser(member, guild, true); await kickUser(member, guild, true);
} }
} catch { } } catch (error) {
console.log('[KICKVC] Error in voice state handler:', error);
}
}; };
const intervalTime = Math.floor(Math.random() * 500) + 1000; const intervalTime = Math.floor(Math.random() * 500) + 1000;
console.log(`[KICKVC] Setting up interval check every ${intervalTime}ms`);
checkInterval = setInterval(async () => { checkInterval = setInterval(async () => {
if (!isKickActive) return; if (!isKickActive) return;
@ -143,19 +176,24 @@ module.exports = {
}, intervalTime); }, intervalTime);
message.client.on('voiceStateUpdate', voiceStateHandler); message.client.on('voiceStateUpdate', voiceStateHandler);
console.log('[KICKVC] New voice state handler and check interval registered');
try { try {
const user = await message.client.users.fetch(userId); const user = await message.client.users.fetch(userId);
console.log(`[KICKVC] Successfully fetched target user: ${user.tag}`);
message.channel.send(`Now automatically kicking ${user.tag} (${userId}) from voice channels.`) message.channel.send(`Now automatically kicking ${user.tag} (${userId}) from voice channels.`)
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout)); .then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
console.log('[KICKVC] Performing initial guild check');
message.client.guilds.cache.forEach(async (guild) => { message.client.guilds.cache.forEach(async (guild) => {
const member = await guild.members.fetch(userId).catch(() => null); const member = await guild.members.fetch(userId).catch(() => null);
if (member?.voice?.channel) { if (member?.voice?.channel) {
console.log(`[KICKVC] Target found in voice during initial check - Server: ${guild.name}`);
await kickUser(member, guild, true); await kickUser(member, guild, true);
} }
}); });
} catch { } catch (error) {
console.log('[KICKVC] Could not fetch user information:', error);
message.channel.send(`Now automatically kicking user ID ${userId} from voice channels.`) message.channel.send(`Now automatically kicking user ID ${userId} from voice channels.`)
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout)); .then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
} }