Compare commits

...

2 Commits

Author SHA1 Message Date
ethanf
f7549776f6 feat: randomly select fatkids, rename old fk 2024-01-28 18:30:17 -06:00
ethanf
b995899870 feat: fun and passion are modifiable 2024-01-28 17:38:01 -06:00
2 changed files with 178 additions and 4 deletions

155
index.js
View File

@ -1,5 +1,5 @@
import fs from "fs";
import path from "path";
import path, { parse } from "path";
import { Client, GatewayIntentBits, Partials } from "discord.js";
const {
TOKEN,
@ -363,6 +363,129 @@ client.on("interactionCreate", async (interaction) => {
}
if (command === "fk" || command === "fatkid") {
// pull users in addup into picking, then randomly select other users in picking to be sat out until there are 18 in picking
await interaction.reply("Randomly choosing fatkids from picking...");
// get voice channels
const addup = interaction.guild.channels.cache.find(
(channel) => channel.name === "add-up" || channel.id === ADDUP_ID
);
const picking = interaction.guild.channels.cache.find(
(channel) => channel.name === "picking" || channel.id === PICKING_ID
);
// get members in voice channel
const addupPlayers = Array.from(addup.members.values());
if (addupPlayers.length === 0) {
return await interaction.followUp("Found no players in addup");
}
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
while (pickingPlayers.length + addupPlayers.length > 18) {
const idx = Math.floor(Math.random() * pickingPlayers.length);
fatkids.push(pickingPlayers.splice(idx, 1)[0]);
}
let errCount = 0;
// move players from addup to picking
for (const newPlayer of addupPlayers) {
try {
await newPlayer.voice.setChannel(picking);
} catch (error) {
console.error(error);
errCount++;
}
}
// 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);
errCount++;
}
}
interaction.followUp(
`Sat out ${fatkids.length} players${
errCount > 0 ? ` (error moving ${errCount} members)` : ""
}`
);
}
/*if (command === "testfk") {
// debug fk
// pull users in addup into picking, then randomly select other users in picking to be sat out until there are 18 in picking
await interaction.reply("Randomly choosing fatkids from picking...");
// get voice channels
const addup = interaction.guild.channels.cache.find(
(channel) => channel.name === "add-up" || channel.id === ADDUP_ID
);
const picking = interaction.guild.channels.cache.find(
(channel) => channel.name === "picking" || channel.id === PICKING_ID
);
// get members in voice channel
const addupPlayers = Array.from(addup.members.values());
if (addupPlayers.length === 0) {
return await interaction.followUp("Found no players in addup");
}
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
while (pickingPlayers.length + addupPlayers.length > 2) {
const idx = Math.floor(Math.random() * pickingPlayers.length);
fatkids.push(pickingPlayers.splice(idx, 1)[0]);
}
let errCount = 0;
// move players from addup to picking
for (const newPlayer of addupPlayers) {
try {
await newPlayer.voice.setChannel(picking);
} catch (error) {
console.error(error);
errCount++;
}
}
// move players from picking to fatkid
for (const fk of fatkids) {
try {
console.log(addup.members.size, picking.members.size)
if (picking.members.size <= 2) break;
await fk.voice.setChannel(addup);
} catch (error) {
console.error(error);
errCount++;
}
}
interaction.followUp(
`Sat out ${fatkids.length} players${
errCount > 0 ? ` (error moving ${errCount} members)` : ""
}`
);
}*/
if (command === "fklist" || command === "listfk") {
// moves players in picking to fatkid channel, for use in captain pugs
await interaction.reply("Moving fatkids...");
// get voice channels
@ -548,7 +671,7 @@ client.on("interactionCreate", async (interaction) => {
}
interaction.followUp(
`Teams selected and moved${
`Players moved into teams${
moveErr > 0 ? ` (error moving ${moveErr} members)` : ""
}`
);
@ -735,6 +858,34 @@ client.on("messageCreate", async (message) => {
}
}
if (args[0] === "fun") {
if (
args.length < 2 ||
isNaN(args[1]) ||
parseInt(args[1]) < 1 ||
parseInt(args[1]) > 10
)
return await message.reply(
`Current FUN value: ${funInput}\nUsage: \`fun <1-10>\``
);
funInput = parseInt(args[1]);
return await message.reply(`FUN value set to ${funInput}`);
}
if (args[0] === "passion") {
if (
args.length < 2 ||
isNaN(args[1]) ||
parseInt(args[1]) < 1 ||
parseInt(args[1]) > 5
)
return await message.reply(
`Current PASSION: ${passionInput}\nUsage: \`passion <1-5>\``
);
passionInput = parseInt(args[1]);
return await message.reply(`PASSION set to ${passionInput}`);
}
if (args[0] === "simulateteams") {
await message.reply("Simulating teams...");

View File

@ -1,5 +1,5 @@
import { REST, Routes } from "discord.js";
const { TOKEN, CLIENT_ID } = require("./config.json");
const { TOKEN, CLIENT_ID, GUILD_ID } = require("./config.json");
const commands = [
{
@ -20,10 +20,22 @@ const commands = [
},
{
name: "fatkid",
description: "Pulls addup channel members into fk channel and lists them",
description: "Moves added players to picking and randomly selects fatkids",
},
{
name: "fk",
description: "Moves added players to picking and randomly selects fatkids",
},
/*{
name: "testfk",
description: "debug fk",
},*/
{
name: "fklist",
description: "Pulls addup channel members into fk channel and lists them",
},
{
name: "listfk",
description: "Pulls addup channel members into fk channel and lists them",
},
{
@ -93,10 +105,21 @@ const rest = new REST({ version: "10" }).setToken(TOKEN);
try {
console.log("Started refreshing application (/) commands.");
// application reload
await rest.put(Routes.applicationCommands(CLIENT_ID), {
body: commands,
});
// guild reload, faster than application reload
//await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), {
// body: commands,
//});
// clear guild commands
//await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), {
// body: [],
//});
console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.error(error);