Compare commits

..

No commits in common. "52a5c63230ebe41d61804d01b67964cd81b45026" and "7217e968ddd88e694dbb3401ade00b70339aae59" have entirely different histories.

View File

@ -94,7 +94,7 @@ client.on("error", (error) => {
if (!channel) return console.error("Can't find command channel"); if (!channel) return console.error("Can't find command channel");
client.channels.cache client.channels.cache
.get(COMMAND_CHANNEL_ID) .get(COMMAND_CHANNEL_ID)
.send(`Error: ${error.message}`) .send(`error: ${error.message}`)
.catch(console.error); .catch(console.error);
}); });
@ -131,13 +131,13 @@ client.on("interactionCreate", async (interaction) => {
!captain.members.has(interaction.user.id) !captain.members.has(interaction.user.id)
) { ) {
await interaction.reply({ await interaction.reply({
content: "Must be in picking or captains channel to use this command", content: "must be in picking or captains channel to use this command",
ephemeral: true, ephemeral: true,
}); });
return; return;
} else { } else {
await interaction.reply({ await interaction.reply({
content: "Checking picking channel...", content: "checking picking channel...",
ephemeral: true, ephemeral: true,
}); });
@ -151,7 +151,7 @@ client.on("interactionCreate", async (interaction) => {
for (const member of picking.members.values()) { for (const member of picking.members.values()) {
if (member.roles.cache.find((role) => role.name === roleName)) { if (member.roles.cache.find((role) => role.name === roleName)) {
if (str !== `In picking (${roleName}):`) str += ","; if (str !== `In picking (${roleName}):`) str += ",";
str += " " + getApplicableName(member); str += " " + member.user.globalName;
} }
} }
if (str === `In picking (${roleName}):`) if (str === `In picking (${roleName}):`)
@ -164,7 +164,7 @@ client.on("interactionCreate", async (interaction) => {
if (interaction.channelId !== COMMAND_CHANNEL_ID) { if (interaction.channelId !== COMMAND_CHANNEL_ID) {
await interaction.reply({ await interaction.reply({
content: "Wrong channel, or you lack the required permissions", content: "wrong channel, or you lack the required permissions",
ephemeral: true, ephemeral: true,
}); });
return; return;
@ -179,7 +179,7 @@ client.on("interactionCreate", async (interaction) => {
command === "end" || command === "end" ||
command === "resetteams" command === "resetteams"
) { ) {
await interaction.reply("Moving members..."); await interaction.reply("moving members...");
// get voice channels // get voice channels
const blu = interaction.guild.channels.cache.find( const blu = interaction.guild.channels.cache.find(
@ -204,7 +204,7 @@ client.on("interactionCreate", async (interaction) => {
if (command !== "resetteams") members = members.concat(addup.members); if (command !== "resetteams") members = members.concat(addup.members);
if (members.size === 0) { if (members.size === 0) {
return await interaction.followUp( return await interaction.followUp(
`Found no members in ${ `found no members in ${
command === "resetteams" ? "blu" : "addup, blu," command === "resetteams" ? "blu" : "addup, blu,"
} or red` } or red`
); );
@ -233,7 +233,7 @@ client.on("interactionCreate", async (interaction) => {
moveAllToAddup().then(() => moveAllToAddup().then(() =>
interaction.followUp( interaction.followUp(
`Moved members in ${ `moved members in ${
command === "resetteams" ? "blu" : "addup, blu," command === "resetteams" ? "blu" : "addup, blu,"
} and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}` } and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`
) )
@ -241,7 +241,7 @@ client.on("interactionCreate", async (interaction) => {
} }
if (command === "fk" || command === "fatkid") { if (command === "fk" || command === "fatkid") {
await interaction.reply("Moving fatkids..."); await interaction.reply("moving fatkids...");
// get voice channels // get voice channels
const picking = interaction.guild.channels.cache.find( const picking = interaction.guild.channels.cache.find(
@ -256,7 +256,7 @@ client.on("interactionCreate", async (interaction) => {
// get members in voice channel // get members in voice channel
const members = picking.members; const members = picking.members;
if (members.size === 0) { if (members.size === 0) {
return await interaction.followUp("Found no members in picking"); return await interaction.followUp("found no members in picking");
} }
let str = "", let str = "",
@ -266,7 +266,7 @@ client.on("interactionCreate", async (interaction) => {
try { try {
await member.voice.setChannel(fk); await member.voice.setChannel(fk);
if (str.length > 0) str += ", "; if (str.length > 0) str += ", ";
str += getApplicableName(member); str += member.user.globalName;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
eCount++; eCount++;
@ -283,7 +283,7 @@ client.on("interactionCreate", async (interaction) => {
logAllFks().then(() => logAllFks().then(() =>
interaction.followUp( interaction.followUp(
`Fatkids: ${str}${ `fatkids: ${str}${
eCount > 0 ? ` (error moving ${eCount} members)` : "" eCount > 0 ? ` (error moving ${eCount} members)` : ""
}` }`
) )
@ -291,7 +291,7 @@ client.on("interactionCreate", async (interaction) => {
} }
if (command === "clear" || command === "bclear") { if (command === "clear" || command === "bclear") {
await interaction.reply("Clearing messages..."); await interaction.reply("clearing messages...");
let channel = client.channels.cache.get(COMMAND_CHANNEL_ID); let channel = client.channels.cache.get(COMMAND_CHANNEL_ID);
if (!channel) return console.error("Can't find command channel"); if (!channel) return console.error("Can't find command channel");
channel.messages channel.messages
@ -307,15 +307,6 @@ client.on("interactionCreate", async (interaction) => {
} }
}); });
/*
* DM commands
* - setrank: saves a player's rank
* - getrank: prints a player's rank
* - rankings: prints all players' ranks
* - whitelist: adds an admin to the whitelist to use DM commands
* - getwhitelist: prints the whitelist
* - clearwhitelist: clears the whitelist completely, security measure
*/
client.on("messageCreate", async (message) => { client.on("messageCreate", async (message) => {
if (message.author.bot || message.guild) return; if (message.author.bot || message.guild) return;
@ -325,13 +316,13 @@ client.on("messageCreate", async (message) => {
} }
if (message.content.toLowerCase().includes("hello penguin")) { if (message.content.toLowerCase().includes("hello penguin")) {
await message.reply(`Hello ${message.author.username}`); await message.reply(`hello ${message.author.username}`);
return; return;
} }
const pickupGuild = client.guilds.cache.get(GUILD_ID); const pickupGuild = client.guilds.cache.get(GUILD_ID);
if (!pickupGuild) { if (!pickupGuild) {
await message.reply("Could not find guild"); await message.reply("could not find guild");
return; return;
} }
@ -340,7 +331,7 @@ client.on("messageCreate", async (message) => {
if (args[0] === "setrank") { if (args[0] === "setrank") {
if (args.length < 3) { if (args.length < 3) {
await message.reply( await message.reply(
"Invalid number of arguments. usage: `setrank <player name or id> <rank (0-5)>`" "invalid number of arguments. usage: `setrank <player name or id> <rank (0-5)>`"
); );
return; return;
} }
@ -348,7 +339,7 @@ client.on("messageCreate", async (message) => {
const player = findPlayer(pickupGuild, args[1]); const player = findPlayer(pickupGuild, args[1]);
if (!player) { if (!player) {
await message.reply( await message.reply(
`Could not find player ${args[1]}. If this issue persists, try copy/pasting the player's Discord handle or user ID` `could not find player ${args[1]}. if this issue persists, try copy/pasting the player's discord handle or user id`
); );
return; return;
} }
@ -359,7 +350,7 @@ client.on("messageCreate", async (message) => {
const rank = parseInt(args[2]); const rank = parseInt(args[2]);
if (isNaN(rank) || rank < 0 || rank > 5) { if (isNaN(rank) || rank < 0 || rank > 5) {
await message.reply( await message.reply(
`Invalid rank ${args[2]}. Supply an integer between 0 and 5` `invalid rank ${args[2]}. must be an integer between 0 and 5`
); );
return; return;
} }
@ -375,7 +366,7 @@ client.on("messageCreate", async (message) => {
rankings[playerId] = rank; rankings[playerId] = rank;
console.log( console.log(
`Setting rank of ${applicableName}, ${playerId} to ${rank} at ${rankingsPath}...` `setting rank of ${applicableName}, ${playerId} to ${rank} at ${rankingsPath}...`
); );
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
fs.writeFile(rankingsPath, JSON.stringify(rankings), (err) => { fs.writeFile(rankingsPath, JSON.stringify(rankings), (err) => {
@ -385,9 +376,9 @@ client.on("messageCreate", async (message) => {
}).then((res, err) => { }).then((res, err) => {
if (err) { if (err) {
console.error(err); console.error(err);
message.reply(`Error setting rank: ${err.message}`); message.reply(`error setting rank: ${err.message}`);
} else { } else {
message.reply(`Set rank of ${applicableName} to ${rank}`); message.reply(`set rank of ${applicableName} to ${rank}`);
} }
}); });
} }
@ -395,7 +386,7 @@ client.on("messageCreate", async (message) => {
if (args[0] === "getrank") { if (args[0] === "getrank") {
if (args.length < 2) { if (args.length < 2) {
await message.reply( await message.reply(
"Invalid number of arguments. Usage: `getrank <player name or id>`" "invalid number of arguments. usage: `getrank <player name or id>`"
); );
return; return;
} }
@ -403,7 +394,7 @@ client.on("messageCreate", async (message) => {
const player = findPlayer(pickupGuild, args[1]); const player = findPlayer(pickupGuild, args[1]);
if (!player) { if (!player) {
await message.reply( await message.reply(
`Could not find player ${args[1]}. If this issue persists, try copy/pasting the player's Discord handle or user ID` `could not find player ${args[1]}. if this issue persists, try using the player's id`
); );
return; return;
} }
@ -413,7 +404,7 @@ client.on("messageCreate", async (message) => {
try { try {
console.log( console.log(
`Getting rank of ${applicableName}, ${playerId} at ${rankingsPath}...` `getting rank of ${applicableName}, ${playerId} at ${rankingsPath}...`
); );
if (!fs.existsSync(rankingsPath)) { if (!fs.existsSync(rankingsPath)) {
fs.writeFileSync(rankingsPath, "{}"); fs.writeFileSync(rankingsPath, "{}");
@ -426,14 +417,14 @@ client.on("messageCreate", async (message) => {
); );
} catch (error) { } catch (error) {
console.error(error); console.error(error);
await message.reply(`Error getting rank: ${error.message}`); await message.reply(`error getting rank: ${error.message}`);
} }
} }
if (args[0] === "rankings") { if (args[0] === "rankings") {
await message.reply("Getting rankings..."); await message.reply("getting rankings...");
try { try {
console.log(`Getting rankings at ${rankingsPath}...`); console.log(`getting rankings at ${rankingsPath}...`);
if (!fs.existsSync(rankingsPath)) { if (!fs.existsSync(rankingsPath)) {
fs.writeFileSync(rankingsPath, "{}"); fs.writeFileSync(rankingsPath, "{}");
} }
@ -462,11 +453,11 @@ client.on("messageCreate", async (message) => {
str += `${name.padEnd(maxNameLength, " ")} - ${"*".repeat(rank)}\n`; str += `${name.padEnd(maxNameLength, " ")} - ${"*".repeat(rank)}\n`;
} }
str += backticks; str += backticks;
if (str === backticks + backticks) str = "No rankings found"; if (str === backticks + backticks) str = "no rankings found";
await message.reply(str); await message.reply(str);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
await message.reply(`Error getting rankings: ${error.message}`); await message.reply(`error getting rankings: ${error.message}`);
} }
} }
@ -474,7 +465,7 @@ client.on("messageCreate", async (message) => {
// add user to config.json whitelist // add user to config.json whitelist
if (args.length < 2) { if (args.length < 2) {
await message.reply( await message.reply(
"Invalid number of arguments. Usage: `whitelist <name>`" "invalid number of arguments. usage: `whitelist <name>`"
); );
return; return;
} }
@ -483,7 +474,7 @@ client.on("messageCreate", async (message) => {
const player = findPlayer(pickupGuild, name); const player = findPlayer(pickupGuild, name);
if (!player) { if (!player) {
await message.reply( await message.reply(
`Could not find player ${name}. If this issue persists, try copy/pasting the player's Discord handle or user ID` `could not find player ${name}. if this issue persists, try copy/pasting the player's discord handle or user id`
); );
return; return;
} }
@ -493,7 +484,7 @@ client.on("messageCreate", async (message) => {
if (whitelistStr.includes(playerId)) { if (whitelistStr.includes(playerId)) {
await message.reply( await message.reply(
`User ${applicableName} (${playerId}) is already whitelisted` `user ${applicableName} (${playerId}) is already whitelisted`
); );
return; return;
} }
@ -510,10 +501,10 @@ client.on("messageCreate", async (message) => {
}).then((res, err) => { }).then((res, err) => {
if (err) { if (err) {
console.error(err); console.error(err);
message.reply(`Error whitelisting user: ${err.message}`); message.reply(`error whitelisting user: ${err.message}`);
} else { } else {
message.reply( message.reply(
`Whitelisted user ${applicableName} (${playerId}). If this was done in error, please contact an admin` `whitelisted user ${applicableName} (${playerId}). if this was done in error, please contact an admin`
); );
} }
}); });
@ -535,7 +526,7 @@ client.on("messageCreate", async (message) => {
if (args[0] === "clearwhitelist") { if (args[0] === "clearwhitelist") {
if (args[1] !== "confirm") { if (args[1] !== "confirm") {
await message.reply( await message.reply(
"This command will clear the whitelist and prevent further DM commands. This will require manual intervention to undo. To confirm, use `clearwhitelist confirm`" "this command will clear the whitelist and prevent further dm commands. this will require manual intervention to undo. to confirm, use `clearwhitelist confirm`"
); );
return; return;
} else { } else {
@ -551,9 +542,9 @@ client.on("messageCreate", async (message) => {
}).then((res, err) => { }).then((res, err) => {
if (err) { if (err) {
console.error(err); console.error(err);
message.reply(`Error clearing whitelist: ${err.message}`); message.reply(`error clearing whitelist: ${err.message}`);
} else { } else {
message.reply("Whitelist cleared, please alert an admin"); message.reply("whitelist cleared, please alert an admin");
} }
}); });
} }