Compare commits

...

2 Commits

Author SHA1 Message Date
ethanf
9da39df8fc feat: clear command 2024-01-16 17:07:14 -06:00
ethanf
713f44835e fix: async-friendly collection iteration 2024-01-16 17:04:31 -06:00
2 changed files with 41 additions and 15 deletions

View File

@ -163,24 +163,31 @@ client.on("interactionCreate", async (interaction) => {
// move members to addup
let idx = 0,
eCount = 0;
members.forEach(async (member) => {
idx++;
console.log(idx, members.size);
const moveToAddup = async (member) => {
try {
await member.voice.setChannel(picking);
} catch (error) {
console.error(error);
eCount++;
}
// respond when done
if (idx === members.size) {
return await interaction.followUp(
`moved members in ${
command === "resetteams" ? "blu" : "addup, blu,"
} and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`
);
}
});
};
const moveAllToAddup = async () => {
return Promise.all(
Array.from(members, async ([memberId, member]) => {
await moveToAddup(member);
})
);
};
moveAllToAddup().then(() =>
interaction.followUp(
`moved members in ${
command === "resetteams" ? "blu" : "addup, blu,"
} and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`
)
);
}
if (command === "fk" || command === "fatkid") {
@ -196,12 +203,12 @@ client.on("interactionCreate", async (interaction) => {
);
if (!fk) return console.error("Can't find channel 'fatkid'!");
// get members in voice channel
const members = picking.members;
if (members.size === 0) {
return await interaction.followUp("found no members in picking");
}
// get members in voice channel
let str = "",
eCount = 0;
@ -216,7 +223,7 @@ client.on("interactionCreate", async (interaction) => {
}
};
const processAllEntries = async () => {
const logAllFks = async () => {
return Promise.all(
Array.from(members, async ([memberId, member]) => {
await logFk(member);
@ -224,7 +231,7 @@ client.on("interactionCreate", async (interaction) => {
);
};
processAllEntries().then(() =>
logAllFks().then(() =>
interaction.followUp(
`fatkids: ${str}${
eCount > 0 ? ` (error moving ${eCount} members)` : ""
@ -232,6 +239,21 @@ client.on("interactionCreate", async (interaction) => {
)
);
}
if (command === "clear") {
await interaction.reply("clearing messages...");
let channel = client.channels.cache.get(COMMAND_CHANNEL_ID);
if (!channel) return console.error("Can't find command channel");
channel.messages
.fetch({ limit: 100 })
.then((messages) => {
messages.forEach((message) => {
if (message.author.id === client.user.id) {
message.delete();
}
});
})
.catch(console.error);
}
});
client.login(TOKEN);

View File

@ -26,6 +26,10 @@ const commands = [
name: "fk",
description: "Pulls addup channel members into fk channel and lists them",
},
{
name: "clear",
description: "Clears bot messages in command channel",
},
{
name: "scout",
description: "Lists picking channel members with scout role",