Compare commits

...

2 Commits

Author SHA1 Message Date
ethanf
1c53aeeeee chore: improve scripts with anticrash 2023-11-29 00:48:54 -06:00
ethanf
18a30e459c fix: updated addup commands to picking + register 2023-11-29 00:48:39 -06:00
4 changed files with 53 additions and 33 deletions

View File

@ -4,6 +4,7 @@
"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,5 +1,13 @@
import { Client, GatewayIntentBits } from "discord.js"; import { Client, GatewayIntentBits } from "discord.js";
const { TOKEN, COMMAND_CHANNEL_ID, ADDUP_ID, BLU_ID, RED_ID, FK_ID } = require("./config.json"); const {
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],
@ -10,6 +18,7 @@ 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) {
@ -20,15 +29,16 @@ client.on("interactionCreate", async (interaction) => {
return; return;
} }
if (interaction.commandName === "hello") { if (command === "hello") {
await interaction.reply("world"); await interaction.reply("world");
} }
if ( if (
interaction.commandName === "pullTeams" || command === "topicking" ||
interaction.commandName === "end" command === "end" ||
command === "resetteams"
) { ) {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply();
// get voice channels // get voice channels
const blu = interaction.guild.channels.cache.find( const blu = interaction.guild.channels.cache.find(
@ -43,11 +53,20 @@ 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
const members = blu.members.concat(red.members); let 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("found no members in teams"); return await interaction.editReply(
`found no members in ${
command === "resetteams" ? "blu" : "addup, blu,"
} or red`
);
} }
// move members to addup // move members to addup
@ -56,45 +75,39 @@ client.on("interactionCreate", async (interaction) => {
members.forEach(async (member) => { members.forEach(async (member) => {
idx++; idx++;
try { try {
await member.voice.setChannel(addup); await member.voice.setChannel(picking);
} 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 teams`, content: `moved members in ${
command === "resetteams" ? "blu" : "addup, blu,"
} and red.${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`,
}); });
} }
} }
}); });
} }
if ( if (command === "fk" || command === "fatkid") {
interaction.commandName === "fk" ||
interaction.commandName === "fatkid"
) {
await interaction.deferReply(); await interaction.deferReply();
// get voice channels // get voice channels
const addup = interaction.guild.channels.cache.find( const picking = interaction.guild.channels.cache.find(
(channel) => channel.name === "add-up" || channel.id === ADDUP_ID (channel) => channel.name === "picking" || channel.id === PICKING_ID
); );
if (!addup) return console.error("Can't find channel 'add-up'!"); if (!picking) 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 = addup.members; const members = picking.members;
if (members.size === 0) { if (members.size === 0) {
return await interaction.editReply("found no members in addup"); return await interaction.editReply("found no members in picking");
} }
// get members in voice channel // get members in voice channel
@ -115,11 +128,13 @@ 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}, error moving ${eCount} members`, content: `fatkids: ${str}`,
}); });
} }
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 run index.js", "start": "bun --watch index.js",
"register": "bun run register.js" "register": "bun 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,12 +7,16 @@ const commands = [
description: "Replies 'world'", description: "Replies 'world'",
}, },
{ {
name: "pullteams", name: "topicking",
description: "Pulls team channel members into addup channel", description: "Pulls team and addup channel members into picking channel",
}, },
{ {
name: "end", name: "end",
description: "Pulls team channel members into addup channel", description: "Pulls team and addup channel members into picking channel",
},
{
name: "resetteams",
description: "Pulls team channel members into picking channel",
}, },
{ {
name: "fatkid", name: "fatkid",
@ -24,12 +28,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,
}); });