Compare commits
2 Commits
7217e968dd
...
52a5c63230
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52a5c63230 | ||
|
|
bd555b17c8 |
83
index.js
83
index.js
@ -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 += " " + member.user.globalName;
|
str += " " + getApplicableName(member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 += member.user.globalName;
|
str += getApplicableName(member);
|
||||||
} 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,6 +307,15 @@ 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;
|
||||||
|
|
||||||
@ -316,13 +325,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +340,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;
|
||||||
}
|
}
|
||||||
@ -339,7 +348,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;
|
||||||
}
|
}
|
||||||
@ -350,7 +359,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]}. must be an integer between 0 and 5`
|
`Invalid rank ${args[2]}. Supply an integer between 0 and 5`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -366,7 +375,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) => {
|
||||||
@ -376,9 +385,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}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -386,7 +395,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;
|
||||||
}
|
}
|
||||||
@ -394,7 +403,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 using the player's id`
|
`Could not find player ${args[1]}. If this issue persists, try copy/pasting the player's Discord handle or user ID`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -404,7 +413,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, "{}");
|
||||||
@ -417,14 +426,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, "{}");
|
||||||
}
|
}
|
||||||
@ -453,11 +462,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}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +474,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;
|
||||||
}
|
}
|
||||||
@ -474,7 +483,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;
|
||||||
}
|
}
|
||||||
@ -484,7 +493,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;
|
||||||
}
|
}
|
||||||
@ -501,10 +510,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`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -526,7 +535,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 {
|
||||||
@ -542,9 +551,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");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user