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",
"COMMAND_CHANNEL_ID": "1177469184192565288",
"ADDUP_ID": "1175649994674544721",
"PICKING_ID": "1175649967935856680",
"BLU_ID": "1175649793943552010",
"RED_ID": "1175649777648680971",
"FK_ID": "1176396207183106078"

View File

@ -1,5 +1,13 @@
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({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
@ -10,6 +18,7 @@ client.on("ready", () => {
});
client.on("interactionCreate", async (interaction) => {
const command = interaction.commandName;
if (!interaction.isChatInputCommand()) return;
if (interaction.channelId !== COMMAND_CHANNEL_ID) {
@ -20,15 +29,16 @@ client.on("interactionCreate", async (interaction) => {
return;
}
if (interaction.commandName === "hello") {
if (command === "hello") {
await interaction.reply("world");
}
if (
interaction.commandName === "pullTeams" ||
interaction.commandName === "end"
command === "topicking" ||
command === "end" ||
command === "resetteams"
) {
await interaction.deferReply({ ephemeral: true });
await interaction.deferReply();
// get voice channels
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
);
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
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) {
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
@ -56,45 +75,39 @@ client.on("interactionCreate", async (interaction) => {
members.forEach(async (member) => {
idx++;
try {
await member.voice.setChannel(addup);
await member.voice.setChannel(picking);
} catch (error) {
console.error(error);
eCount++;
} finally {
// respond when done
if (idx === members.size) {
if (eCount > 0) {
return await interaction.editReply({
content: `moved teams, error moving ${eCount} members`,
});
}
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 (
interaction.commandName === "fk" ||
interaction.commandName === "fatkid"
) {
if (command === "fk" || command === "fatkid") {
await interaction.deferReply();
// 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
);
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(
(channel) => channel.name === "fatkid" || channel.id === FK_ID
);
if (!fk) return console.error("Can't find channel 'fatkid'!");
const members = addup.members;
const members = picking.members;
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
@ -115,11 +128,13 @@ client.on("interactionCreate", async (interaction) => {
if (idx === members.size) {
if (eCount > 0) {
return await interaction.editReply({
content: `fatkids: ${str}, error moving ${eCount} members`,
content: `fatkids: ${str}`,
});
}
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" },
"scripts": {
"start": "bun run index.js",
"register": "bun run register.js"
"start": "bun --watch index.js",
"register": "bun register.js"
}
}

View File

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