fix hopefully: select fk at random
This commit is contained in:
parent
6857ab9714
commit
d48d4e67bd
36
index.js
36
index.js
@ -375,30 +375,31 @@ client.on("interactionCreate", async (interaction) => {
|
||||
);
|
||||
|
||||
// get members in voice channel
|
||||
const addupPlayers = Array.from(addup.members.values());
|
||||
if (addupPlayers.length === 0 && pickingPlayers.length <= 18) {
|
||||
const addupPlayers = [];
|
||||
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(
|
||||
"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 = [];
|
||||
|
||||
// select excess players to be sat out
|
||||
console.log(
|
||||
pickingPlayers.length,
|
||||
addupPlayers.length,
|
||||
pickingPlayers.length + addupPlayers.length
|
||||
);
|
||||
|
||||
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);
|
||||
let fk = await pickingPlayers.splice(idx, 1)[0];
|
||||
console.log(getApplicableName(fk));
|
||||
console.log(fk);
|
||||
fatkids.push(fk);
|
||||
}
|
||||
|
||||
@ -417,7 +418,6 @@ client.on("interactionCreate", async (interaction) => {
|
||||
// move players from picking to fatkid
|
||||
for (const fk of fatkids) {
|
||||
try {
|
||||
//if (picking.members.size <= 18) break;
|
||||
await fk.voice.setChannel(addup);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -466,7 +466,9 @@ client.on("interactionCreate", async (interaction) => {
|
||||
// select excess players to be sat out
|
||||
while (pickingPlayers.length + addupPlayers.length > 3) {
|
||||
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);
|
||||
let fk = await pickingPlayers.splice(idx, 1)[0];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user