feat: commands to end game and list fk

This commit is contained in:
ethanf 2023-11-25 03:06:50 -06:00
parent a96549f6ad
commit aec6d6c98e
2 changed files with 135 additions and 2 deletions

119
index.js
View File

@ -1,6 +1,8 @@
import { Client, GatewayIntentBits } from "discord.js";
const { token } = require("./config.json");
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
@ -9,9 +11,124 @@ client.on("ready", () => {
client.on("interactionCreate", async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.channelId !== "1177469184192565288") {
await interaction.reply({
content: "wrong channel, or you lack the required permissions",
ephemeral: true,
});
return;
}
if (interaction.commandName === "hello") {
await interaction.reply("world");
}
if (
interaction.commandName === "pullTeams" ||
interaction.commandName === "end"
) {
await interaction.deferReply({ ephemeral: true });
// get voice channels
const blu = interaction.guild.channels.cache.find(
(channel) =>
channel.name === "blu" || channel.id === "1175649793943552010"
);
if (!blu) return console.error("Can't find channel 'blu'!");
const red = interaction.guild.channels.cache.find(
(channel) =>
channel.name === "red" || channel.id === "1175649777648680971"
);
if (!red) return console.error("Can't find channel 'red'!");
const addup = interaction.guild.channels.cache.find(
(channel) =>
channel.name === "add-up" || channel.id === "1175649994674544721"
);
if (!addup) return console.error("Can't find channel 'add-up'!");
// get members in voice channel
const members = blu.members.concat(red.members);
if (members.size === 0) {
return await interaction.editReply("found no members in teams");
}
// move members to addup
let idx = 0,
eCount = 0;
members.forEach(async (member) => {
idx++;
try {
await member.voice.setChannel(addup);
} 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`,
});
}
}
});
}
if (
interaction.commandName === "fk" ||
interaction.commandName === "fatkid"
) {
await interaction.deferReply();
// get voice channels
const addup = interaction.guild.channels.cache.find(
(channel) =>
channel.name === "add-up" || channel.id === "1175649994674544721"
);
if (!addup) return console.error("Can't find channel 'add-up'!");
const fk = interaction.guild.channels.cache.find(
(channel) =>
channel.name === "fatkid" || channel.id === "1176396207183106078"
);
if (!fk) return console.error("Can't find channel 'fatkid'!");
const members = addup.members;
if (members.size === 0) {
return await interaction.editReply("found no members in addup");
}
// get members in voice channel
let idx = 0,
eCount = 0,
str = "";
members.forEach(async (member) => {
idx++;
try {
await member.voice.setChannel(fk);
if (str.length > 0) str += ", ";
str += member.user.globalName;
} catch (error) {
console.error(error);
eCount++;
} finally {
// list members when done
if (idx === members.size) {
if (eCount > 0) {
return await interaction.editReply({
content: `fatkids: ${str}, error moving ${eCount} members`,
});
}
return await interaction.editReply({
content: `fatkids: ${str}`,
});
}
}
});
}
});
client.login(token);

View File

@ -6,6 +6,22 @@ const commands = [
name: "hello",
description: "Replies 'world'",
},
{
name: "pullteams",
description: "Pulls team channel members into addup channel",
},
{
name: "end",
description: "Pulls team channel members into addup channel",
},
{
name: "fatkid",
description: "Pulls addup channel members into fk channel and lists them",
},
{
name: "fk",
description: "Pulls addup channel members into fk channel and lists them",
}
];
const rest = new REST({ version: "10" }).setToken(token);
@ -13,7 +29,7 @@ const rest = new REST({ version: "10" }).setToken(token);
try {
console.log("Started refreshing application (/) commands.");
await rest.put(Routes.applicationGuildCommands(client_id, guild_id), {
await rest.put(Routes.applicationCommands(client_id), {
body: commands,
});