Compare commits

..

No commits in common. "1c53aeeeeef14f25319e609c3e66231db6a10d20" and "949a08956abb226355ccbb90a7f902fd62c886f0" have entirely different histories.

4 changed files with 33 additions and 53 deletions

View File

@ -4,7 +4,6 @@
"GUILD_ID": "658490352189046784", "GUILD_ID": "658490352189046784",
"COMMAND_CHANNEL_ID": "1177469184192565288", "COMMAND_CHANNEL_ID": "1177469184192565288",
"ADDUP_ID": "1175649994674544721", "ADDUP_ID": "1175649994674544721",
"PICKING_ID": "1175649967935856680",
"BLU_ID": "1175649793943552010", "BLU_ID": "1175649793943552010",
"RED_ID": "1175649777648680971", "RED_ID": "1175649777648680971",
"FK_ID": "1176396207183106078" "FK_ID": "1176396207183106078"

View File

@ -1,13 +1,5 @@
import { Client, GatewayIntentBits } from "discord.js"; import { Client, GatewayIntentBits } from "discord.js";
const { const { TOKEN, COMMAND_CHANNEL_ID, ADDUP_ID, BLU_ID, RED_ID, FK_ID } = require("./config.json");
TOKEN,
COMMAND_CHANNEL_ID,
ADDUP_ID,
PICKING_ID,
BLU_ID,
RED_ID,
FK_ID,
} = require("./config.json");
const client = new Client({ const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates], intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
@ -18,7 +10,6 @@ client.on("ready", () => {
}); });
client.on("interactionCreate", async (interaction) => { client.on("interactionCreate", async (interaction) => {
const command = interaction.commandName;
if (!interaction.isChatInputCommand()) return; if (!interaction.isChatInputCommand()) return;
if (interaction.channelId !== COMMAND_CHANNEL_ID) { if (interaction.channelId !== COMMAND_CHANNEL_ID) {
@ -29,16 +20,15 @@ client.on("interactionCreate", async (interaction) => {
return; return;
} }
if (command === "hello") { if (interaction.commandName === "hello") {
await interaction.reply("world"); await interaction.reply("world");
} }
if ( if (
command === "topicking" || interaction.commandName === "pullTeams" ||
command === "end" || interaction.commandName === "end"
command === "resetteams"
) { ) {
await interaction.deferReply(); await interaction.deferReply({ ephemeral: true });
// get voice channels // get voice channels
const blu = interaction.guild.channels.cache.find( const blu = interaction.guild.channels.cache.find(
@ -53,20 +43,11 @@ client.on("interactionCreate", async (interaction) => {
(channel) => channel.name === "add-up" || channel.id === ADDUP_ID (channel) => channel.name === "add-up" || channel.id === ADDUP_ID
); );
if (!addup) return console.error("Can't find channel 'add-up'!"); if (!addup) return console.error("Can't find channel 'add-up'!");
const picking = interaction.guild.channels.cache.find(
(channel) => channel.name === "picking" || channel.id === PICKING_ID
);
if (!picking) return console.error("Can't find channel 'picking'!");
// get members in voice channel // get members in voice channel
let members = blu.members.concat(red.members); const members = blu.members.concat(red.members);
if (commandName !== "resetteams") members = members.concat(addup.members);
if (members.size === 0) { if (members.size === 0) {
return await interaction.editReply( return await interaction.editReply("found no members in teams");
`found no members in ${
command === "resetteams" ? "blu" : "addup, blu,"
} or red`
);
} }
// move members to addup // move members to addup
@ -75,39 +56,45 @@ client.on("interactionCreate", async (interaction) => {
members.forEach(async (member) => { members.forEach(async (member) => {
idx++; idx++;
try { try {
await member.voice.setChannel(picking); await member.voice.setChannel(addup);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
eCount++; eCount++;
} finally { } finally {
// respond when done // respond when done
if (idx === members.size) { if (idx === members.size) {
if (eCount > 0) {
return await interaction.editReply({
content: `moved teams, error moving ${eCount} members`,
});
}
return await interaction.editReply({ return await interaction.editReply({
content: `moved members in ${ content: `moved teams`,
command === "resetteams" ? "blu" : "addup, blu,"
} and red.${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`,
}); });
} }
} }
}); });
} }
if (command === "fk" || command === "fatkid") { if (
interaction.commandName === "fk" ||
interaction.commandName === "fatkid"
) {
await interaction.deferReply(); await interaction.deferReply();
// get voice channels // get voice channels
const picking = interaction.guild.channels.cache.find( const addup = interaction.guild.channels.cache.find(
(channel) => channel.name === "picking" || channel.id === PICKING_ID (channel) => channel.name === "add-up" || channel.id === ADDUP_ID
); );
if (!picking) return console.error("Can't find channel 'add-up'!"); if (!addup) return console.error("Can't find channel 'add-up'!");
const fk = interaction.guild.channels.cache.find( const fk = interaction.guild.channels.cache.find(
(channel) => channel.name === "fatkid" || channel.id === FK_ID (channel) => channel.name === "fatkid" || channel.id === FK_ID
); );
if (!fk) return console.error("Can't find channel 'fatkid'!"); if (!fk) return console.error("Can't find channel 'fatkid'!");
const members = picking.members; const members = addup.members;
if (members.size === 0) { if (members.size === 0) {
return await interaction.editReply("found no members in picking"); return await interaction.editReply("found no members in addup");
} }
// get members in voice channel // get members in voice channel
@ -128,13 +115,11 @@ client.on("interactionCreate", async (interaction) => {
if (idx === members.size) { if (idx === members.size) {
if (eCount > 0) { if (eCount > 0) {
return await interaction.editReply({ return await interaction.editReply({
content: `fatkids: ${str}`, content: `fatkids: ${str}, error moving ${eCount} members`,
}); });
} }
return await interaction.editReply({ return await interaction.editReply({
content: `fatkids: ${str}${ content: `fatkids: ${str}`,
eCount > 0 ? ` (error moving ${eCount} members)` : ""
}`,
}); });
} }
} }

View File

@ -1,6 +1,6 @@
{ "dependencies": { "discord.js": "^14.14.1" }, { "dependencies": { "discord.js": "^14.14.1" },
"scripts": { "scripts": {
"start": "bun --watch index.js", "start": "bun run index.js",
"register": "bun register.js" "register": "bun run register.js"
} }
} }

View File

@ -1,5 +1,5 @@
import { REST, Routes } from "discord.js"; import { REST, Routes } from "discord.js";
const { TOKEN, CLIENT_ID } = require("./config.json"); const { token, client_id } = require("./config.json");
const commands = [ const commands = [
{ {
@ -7,16 +7,12 @@ const commands = [
description: "Replies 'world'", description: "Replies 'world'",
}, },
{ {
name: "topicking", name: "pullteams",
description: "Pulls team and addup channel members into picking channel", description: "Pulls team channel members into addup channel",
}, },
{ {
name: "end", name: "end",
description: "Pulls team and addup channel members into picking channel", description: "Pulls team channel members into addup channel",
},
{
name: "resetteams",
description: "Pulls team channel members into picking channel",
}, },
{ {
name: "fatkid", name: "fatkid",
@ -28,12 +24,12 @@ const commands = [
} }
]; ];
const rest = new REST({ version: "10" }).setToken(TOKEN); const rest = new REST({ version: "10" }).setToken(token);
try { try {
console.log("Started refreshing application (/) commands."); console.log("Started refreshing application (/) commands.");
await rest.put(Routes.applicationCommands(CLIENT_ID), { await rest.put(Routes.applicationCommands(client_id), {
body: commands, body: commands,
}); });