fix hopefully: select fk at random

This commit is contained in:
ethanf 2024-01-31 16:35:11 -06:00
parent 6857ab9714
commit d48d4e67bd

View File

@ -375,30 +375,31 @@ client.on("interactionCreate", async (interaction) => {
); );
// get members in voice channel // get members in voice channel
const addupPlayers = Array.from(addup.members.values()); const addupPlayers = [];
if (addupPlayers.length === 0 && pickingPlayers.length <= 18) { const pickingPlayers = [];
addup.members.forEach((member) => addupPlayers.push(member));
picking.members.forEach((member) => pickingPlayers.push(member));
if (pickingPlayers.length < addupPlayers.length) {
// move all addup into empty picking
addup.members.forEach((member) => {
member.voice.setChannel(picking);
});
return await interaction.followUp( return await interaction.followUp(
"Found no players in addup and picking has 18 or fewer players" "Found too few players in picking to fatkid, moved all addup players to picking instead"
); );
} }
const pickingPlayers = Array.from(picking.members.values());
if (pickingPlayers.length === 0) {
return await interaction.followUp("Found no players in picking");
}
let fatkids = []; let fatkids = [];
// select excess players to be sat out // select excess players to be sat out
console.log(
pickingPlayers.length,
addupPlayers.length,
pickingPlayers.length + addupPlayers.length
);
while (pickingPlayers.length + addupPlayers.length > 18) { while (pickingPlayers.length + addupPlayers.length > 18) {
if (pickingPlayers.length === 0) {
return await interaction.followUp(
"Error: ran out of players in picking to fatkid"
);
}
const idx = Math.floor(Math.random() * pickingPlayers.length); const idx = Math.floor(Math.random() * pickingPlayers.length);
let fk = await pickingPlayers.splice(idx, 1)[0]; let fk = await pickingPlayers.splice(idx, 1)[0];
console.log(getApplicableName(fk)); console.log(fk);
fatkids.push(fk); fatkids.push(fk);
} }
@ -417,7 +418,6 @@ client.on("interactionCreate", async (interaction) => {
// move players from picking to fatkid // move players from picking to fatkid
for (const fk of fatkids) { for (const fk of fatkids) {
try { try {
//if (picking.members.size <= 18) break;
await fk.voice.setChannel(addup); await fk.voice.setChannel(addup);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -466,7 +466,9 @@ client.on("interactionCreate", async (interaction) => {
// select excess players to be sat out // select excess players to be sat out
while (pickingPlayers.length + addupPlayers.length > 3) { while (pickingPlayers.length + addupPlayers.length > 3) {
if (pickingPlayers.length === 0) { if (pickingPlayers.length === 0) {
return await interaction.followUp("Error: ran out of players in picking to fatkid"); return await interaction.followUp(
"Error: ran out of players in picking to fatkid"
);
} }
const idx = Math.floor(Math.random() * pickingPlayers.length); const idx = Math.floor(Math.random() * pickingPlayers.length);
let fk = await pickingPlayers.splice(idx, 1)[0]; let fk = await pickingPlayers.splice(idx, 1)[0];