Compare commits
No commits in common. "6673965c3e20d7af4dc47664106d9e853455e997" and "df85f29f73f2f7bfdad3a85d2f700fd1ab430069" have entirely different histories.
6673965c3e
...
df85f29f73
@ -1,25 +0,0 @@
|
||||
import { SlashCommandBuilder } from "discord.js";
|
||||
import { client } from "..";
|
||||
import { ROLE_ID_RUNNER } from "../config.json";
|
||||
|
||||
const data = new SlashCommandBuilder()
|
||||
.setName("clear")
|
||||
.setDescription("Clears bot messages in this channel");
|
||||
|
||||
const permissions = [ROLE_ID_RUNNER];
|
||||
|
||||
const execute = async (interaction) => {
|
||||
await interaction.reply("Clearing messages...");
|
||||
interaction.channel.messages
|
||||
.fetch({ limit: 250 })
|
||||
.then((messages) => {
|
||||
messages.forEach((message) => {
|
||||
if (message.author.id === client.user.id) {
|
||||
message.delete();
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
};
|
||||
|
||||
export { data, permissions, execute };
|
||||
@ -1,71 +0,0 @@
|
||||
import { SlashCommandBuilder } from "discord.js";
|
||||
import { findChannelfromCache } from "../utils.js";
|
||||
import { ROLE_ID_RUNNER, VOICE_ID_PICKING, VOICE_ID_BLU, VOICE_ID_RED } from "../config.json";
|
||||
|
||||
const data = new SlashCommandBuilder()
|
||||
.setName("end")
|
||||
.setDescription("Moves the team channel members back to the picking channel");
|
||||
|
||||
const permissions = [ROLE_ID_RUNNER];
|
||||
|
||||
const execute = async (interaction) => {
|
||||
await interaction.reply("Moving members...");
|
||||
|
||||
// get voice channels
|
||||
const picking = findChannelfromCache(
|
||||
interaction.guild.channels.cache,
|
||||
"picking",
|
||||
VOICE_ID_PICKING
|
||||
);
|
||||
const blu = findChannelfromCache(
|
||||
interaction.guild.channels.cache,
|
||||
"blu",
|
||||
VOICE_ID_BLU
|
||||
);
|
||||
const red = findChannelfromCache(
|
||||
interaction.guild.channels.cache,
|
||||
"red",
|
||||
VOICE_ID_RED
|
||||
);
|
||||
if (!picking || !blu || !red) {
|
||||
return console.error("Could not find all channels for /end");
|
||||
}
|
||||
|
||||
// get members in voice channel
|
||||
let members = blu.members.concat(red.members);
|
||||
if (members.size === 0) {
|
||||
return await interaction.followUp("Found no members in blu or red");
|
||||
}
|
||||
|
||||
let eCount = 0;
|
||||
|
||||
// move members to picking
|
||||
const moveToPicking = async (member) => {
|
||||
try {
|
||||
await member.voice.setChannel(picking);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
eCount++;
|
||||
}
|
||||
};
|
||||
|
||||
const moveAllToPicking = async () => {
|
||||
return Promise.all(
|
||||
Array.from(members, async ([memberId, member]) => {
|
||||
await moveToPicking(member);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
moveAllToPicking().then(() =>
|
||||
interaction.followUp(
|
||||
`Moved members in blu and red${
|
||||
eCount > 0 ? ` (error moving ${eCount} members)` : ""
|
||||
}`
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const synonyms = ["resetteams"];
|
||||
|
||||
export { data, permissions, execute, synonyms };
|
||||
@ -1,6 +1,5 @@
|
||||
import { SlashCommandBuilder } from "discord.js";
|
||||
import { findChannelfromCache } from "../utils";
|
||||
import { ROLE_ID_RUNNER, VOICE_ID_ADDUP, VOICE_ID_PICKING } from "../config.json";
|
||||
import { RUNNER_ROLE_ID, ADDUP_ID, PICKING_ID } from "../config.json";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
@ -57,26 +56,19 @@ const data = new SlashCommandBuilder()
|
||||
.setDescription("Player to protect from sitting out, intended for medic")
|
||||
);
|
||||
|
||||
const permissions = [ROLE_ID_RUNNER];
|
||||
const permissions = [RUNNER_ROLE_ID];
|
||||
|
||||
const execute = async (interaction) => {
|
||||
// pull users in addup into picking, then randomly select other users in picking to be sat out until there are 18 in picking
|
||||
await interaction.reply("Randomly choosing fatkids from picking...");
|
||||
|
||||
// get voice channels
|
||||
const addup = findChannelfromCache(
|
||||
interaction.guild.channels.cache,
|
||||
"add-up",
|
||||
VOICE_ID_ADDUP
|
||||
const addup = interaction.guild.channels.cache.find(
|
||||
(channel) => channel.name === "add-up" || channel.id === ADDUP_ID
|
||||
);
|
||||
const picking = findChannelfromCache(
|
||||
interaction.guild.channels.cache,
|
||||
"picking",
|
||||
VOICE_ID_PICKING
|
||||
const picking = interaction.guild.channels.cache.find(
|
||||
(channel) => channel.name === "picking" || channel.id === PICKING_ID
|
||||
);
|
||||
if (!addup || !picking) {
|
||||
return console.error("Could not find all channels for /fk");
|
||||
}
|
||||
|
||||
// get members in voice channel
|
||||
const addupPlayers = [];
|
||||
@ -123,7 +115,7 @@ const execute = async (interaction) => {
|
||||
let exceptions = [];
|
||||
for (const option of ["exception1", "exception2"]) {
|
||||
const exception = interaction.options.getUser(option);
|
||||
if (exception) exceptions.push(exception.id);
|
||||
if (exception) exceptions.push(exception);
|
||||
}
|
||||
if (addupPlayers.length > targetPlayerCount - exceptions.length) {
|
||||
exceptions = [];
|
||||
@ -148,7 +140,7 @@ const execute = async (interaction) => {
|
||||
fkAttempts++;
|
||||
const idx = Math.floor(Math.random() * pickingPlayers.length);
|
||||
let fk = pickingPlayers[idx];
|
||||
if (exceptions.includes(fk.id)) {
|
||||
if (exceptions.includes(fk)) {
|
||||
continue;
|
||||
}
|
||||
if (protectedFk.includes(fk.id)) {
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
import { SlashCommandBuilder } from "discord.js";
|
||||
import { findChannelfromCache, findPlayer, getApplicableName } from "../utils";
|
||||
import { ROLE_ID_RUNNER, VOICE_ID_PICKING, VOICE_ID_FK } from "../config.json";
|
||||
|
||||
// not really used since fks are now determined randomly
|
||||
const data = new SlashCommandBuilder()
|
||||
.setName("fklist")
|
||||
.setDescription("Pulls addup channel members into fk channel and lists them");
|
||||
|
||||
const permissions = [ROLE_ID_RUNNER];
|
||||
|
||||
const synonyms = ["listfk"];
|
||||
|
||||
const execute = async (interaction) => {
|
||||
await interaction.reply("Moving fatkids...");
|
||||
|
||||
// get voice channels
|
||||
const picking = findChannelfromCache(
|
||||
interaction.guild.channels.cache,
|
||||
"picking",
|
||||
VOICE_ID_PICKING
|
||||
);
|
||||
const fk = findChannelfromCache(
|
||||
interaction.guild.channels.cache,
|
||||
"fatkid",
|
||||
VOICE_ID_FK
|
||||
);
|
||||
if (!picking || !fk) {
|
||||
return console.error("Could not find all channels for /fklist");
|
||||
}
|
||||
|
||||
// get members in voice channel
|
||||
const members = picking.members;
|
||||
if (members.size === 0) {
|
||||
return await interaction.followUp("Found no members in picking");
|
||||
}
|
||||
|
||||
let names = [],
|
||||
eCount = 0;
|
||||
|
||||
const logFk = async (member) => {
|
||||
try {
|
||||
await member.voice.setChannel(fk);
|
||||
names.push(getApplicableName(member));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
eCount++;
|
||||
}
|
||||
};
|
||||
|
||||
const logAllFks = async () => {
|
||||
return Promise.all(
|
||||
Array.from(members, async ([memberId, member]) => {
|
||||
await logFk(member);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
logAllFks().then(() =>
|
||||
interaction.followUp(
|
||||
`Fatkids: ${names.join(', ')}${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export { data, permissions, execute, synonyms };
|
||||
@ -1,14 +0,0 @@
|
||||
import { SlashCommandBuilder } from "discord.js";
|
||||
import { ROLE_ID_RUNNER } from "../config.json";
|
||||
|
||||
const data = new SlashCommandBuilder()
|
||||
.setName("hello")
|
||||
.setDescription("Replies 'world'");
|
||||
|
||||
const permissions = [ROLE_ID_RUNNER];
|
||||
|
||||
const execute = async (interaction) => {
|
||||
await interaction.reply("world");
|
||||
}
|
||||
|
||||
export { data, permissions, execute };
|
||||
@ -1,5 +1,5 @@
|
||||
import { SlashCommandBuilder } from "discord.js";
|
||||
import { ROLE_ID_PLAYER } from "../config.json";
|
||||
import { PLAYER_ROLE_ID } from "../config.json";
|
||||
|
||||
const data = new SlashCommandBuilder()
|
||||
.setName("roll")
|
||||
@ -12,7 +12,7 @@ const data = new SlashCommandBuilder()
|
||||
.setMinValue(1)
|
||||
);
|
||||
|
||||
const permissions = [ROLE_ID_PLAYER];
|
||||
const permissions = [PLAYER_ROLE_ID];
|
||||
|
||||
const execute = async (interaction) => {
|
||||
const max = interaction.options.getInteger("max");
|
||||
|
||||
20
config.json
20
config.json
@ -1,15 +1,15 @@
|
||||
{
|
||||
"TOKEN": "redacted",
|
||||
"CLIENT_ID": "1177748390092742767",
|
||||
"GUILD_ID": "1175646363707523132",
|
||||
"USER_ID_CLIENT": "1177748390092742767",
|
||||
"USER_ID_DEBUG": "233036215610245120",
|
||||
"ROLE_ID_PLAYER": "1175646999140384778",
|
||||
"ROLE_ID_RUNNER": "1175646976235282452",
|
||||
"TEXT_ID_COMMAND": "1177469184192565288",
|
||||
"VOICE_ID_ADDUP": "1175649994674544721",
|
||||
"VOICE_ID_PICKING": "1175649967935856680",
|
||||
"VOICE_ID_BLU": "1175649793943552010",
|
||||
"VOICE_ID_RED": "1175649777648680971",
|
||||
"VOICE_ID_FK": "1176396207183106078",
|
||||
"PLAYER_ROLE_ID": "1175646999140384778",
|
||||
"RUNNER_ROLE_ID": "1175646976235282452",
|
||||
"COMMAND_CHANNEL_ID": "1177469184192565288",
|
||||
"ADDUP_ID": "1175649994674544721",
|
||||
"PICKING_ID": "1175649967935856680",
|
||||
"BLU_ID": "1175649793943552010",
|
||||
"RED_ID": "1175649777648680971",
|
||||
"FK_ID": "1176396207183106078",
|
||||
"CAPTAIN_ID": "1178475124563919018",
|
||||
"RANKING_WHITELIST": "233036215610245120"
|
||||
}
|
||||
|
||||
268
index.js
268
index.js
@ -1,20 +1,21 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import path, { parse } from "path";
|
||||
import { Client, Collection, GatewayIntentBits, Partials } from "discord.js";
|
||||
import { getApplicableName, findPlayer } from "./utils.js";
|
||||
const {
|
||||
TOKEN,
|
||||
GUILD_ID,
|
||||
USER_ID_DEBUG,
|
||||
TEXT_ID_COMMAND,
|
||||
VOICE_ID_PICKING,
|
||||
VOICE_ID_BLU,
|
||||
VOICE_ID_RED,
|
||||
RUNNER_ROLE_ID,
|
||||
COMMAND_CHANNEL_ID,
|
||||
PICKING_ID,
|
||||
BLU_ID,
|
||||
RED_ID,
|
||||
FK_ID,
|
||||
CAPTAIN_ID,
|
||||
} = require("./config.json");
|
||||
|
||||
let whitelistStr = require("./config.json").RANKING_WHITELIST;
|
||||
|
||||
export const client = new Client({
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
@ -35,11 +36,6 @@ for (const file of commandFiles) {
|
||||
const command = require(`./commands/${file}`);
|
||||
if ("data" in command && "execute" in command) {
|
||||
client.fileCommands.set(command.data.name, command);
|
||||
if (command.synonyms) {
|
||||
for (const synonym of command.synonyms) {
|
||||
client.fileCommands.set(synonym, command);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error(`${__filename}: Invalid command file: ${file}`);
|
||||
}
|
||||
@ -48,6 +44,43 @@ for (const file of commandFiles) {
|
||||
const backticks = "```";
|
||||
const rankingsPath = path.join(__dirname, "rankings.json");
|
||||
|
||||
const matchString = (str, search) => {
|
||||
if (!str || !search) return false;
|
||||
return str.toLowerCase().includes(search.toLowerCase());
|
||||
};
|
||||
|
||||
const findPlayer = (guild, searchName) => {
|
||||
// search display name
|
||||
let player = guild.members.cache.find((member) =>
|
||||
matchString(member.displayName, searchName)
|
||||
);
|
||||
if (!player) {
|
||||
// search global name
|
||||
player = guild.members.cache.find((member) =>
|
||||
matchString(member.user.globalName, searchName)
|
||||
);
|
||||
}
|
||||
if (!player) {
|
||||
// search username
|
||||
player = guild.members.cache.find((member) =>
|
||||
matchString(member.user.username, searchName)
|
||||
);
|
||||
}
|
||||
if (!player) {
|
||||
// match id
|
||||
player = guild.members.cache.find((member) => member.id === searchName);
|
||||
}
|
||||
return player;
|
||||
};
|
||||
|
||||
const getApplicableName = (player) => {
|
||||
return (
|
||||
player.displayName ||
|
||||
player.user.globalName ||
|
||||
player.user.username ||
|
||||
player.id
|
||||
);
|
||||
};
|
||||
|
||||
const avgDiff = (arr) => {
|
||||
// average absolute difference between all pairs of rank properties in a given array
|
||||
@ -174,9 +207,9 @@ const balanceArrays = (a1, a2) => {
|
||||
client.on("ready", () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
console.log(
|
||||
`Deleting old messages from this bot in command channel: ${TEXT_ID_COMMAND}...`
|
||||
`Deleting old messages from this bot in command channel: ${COMMAND_CHANNEL_ID}...`
|
||||
);
|
||||
let channel = client.channels.cache.get(TEXT_ID_COMMAND);
|
||||
let channel = client.channels.cache.get(COMMAND_CHANNEL_ID);
|
||||
if (!channel) return console.error("(ready) Can't find command channel");
|
||||
channel.messages
|
||||
.fetch({ limit: 100 })
|
||||
@ -193,11 +226,11 @@ client.on("ready", () => {
|
||||
// send message on error
|
||||
client.on("error", (error) => {
|
||||
console.error(error);
|
||||
let channel = client.channels.cache.get(TEXT_ID_COMMAND);
|
||||
let channel = client.channels.cache.get(COMMAND_CHANNEL_ID);
|
||||
if (!channel) return console.error("Can't find command channel");
|
||||
client.channels.cache
|
||||
.get(TEXT_ID_COMMAND)
|
||||
.send(`Internal error: ${error.message}`)
|
||||
.get(COMMAND_CHANNEL_ID)
|
||||
.send("Internal error")
|
||||
.catch(console.error);
|
||||
});
|
||||
|
||||
@ -211,7 +244,7 @@ client.on("interactionCreate", async (interaction) => {
|
||||
if (fileCommand.permissions) {
|
||||
const member = interaction.member;
|
||||
for (const permission of fileCommand.permissions) {
|
||||
if (!member.roles.cache.has(permission) && member.id !== USER_ID_DEBUG) {
|
||||
if (!member.roles.cache.has(permission)) {
|
||||
await interaction.reply({
|
||||
content: "You lack the required permissions",
|
||||
ephemeral: true,
|
||||
@ -228,8 +261,8 @@ client.on("interactionCreate", async (interaction) => {
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
} else if (interaction.channelId !== TEXT_ID_COMMAND) {
|
||||
//let isRunner = await interaction.member.roles.cache.has(ROLE_ID_RUNNER);
|
||||
} else if (interaction.channelId !== COMMAND_CHANNEL_ID) {
|
||||
//let isRunner = await interaction.member.roles.cache.has(RUNNER_ROLE_ID);
|
||||
//if (!isRunner) {
|
||||
await interaction.reply({
|
||||
content: "Wrong channel, or you lack the required permissions",
|
||||
@ -238,20 +271,191 @@ client.on("interactionCreate", async (interaction) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
command === "scout" ||
|
||||
command === "soldier" ||
|
||||
command === "pyro" ||
|
||||
command === "demoman" ||
|
||||
command === "demo" ||
|
||||
command === "heavy" ||
|
||||
command === "engineer" ||
|
||||
command === "engi" ||
|
||||
command === "medic" ||
|
||||
command === "sniper" ||
|
||||
command === "spy"
|
||||
) {
|
||||
// get voice channels
|
||||
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'!");
|
||||
const captain = interaction.guild.channels.cache.find(
|
||||
(channel) => channel.name === "captains" || channel.id === CAPTAIN_ID
|
||||
);
|
||||
if (!captain) return console.error("Can't find channel 'captains'!");
|
||||
|
||||
// make sure user is in picking or captain channel
|
||||
if (
|
||||
!picking.members.has(interaction.user.id) &&
|
||||
!captain.members.has(interaction.user.id)
|
||||
) {
|
||||
await interaction.reply({
|
||||
content: "Must be in picking or captains channel to use this command",
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
await interaction.reply({
|
||||
content: "Checking picking channel...",
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
// set role name
|
||||
let roleName = command;
|
||||
if (command === "demoman") roleName = "demo";
|
||||
if (command === "engi") roleName = "engineer";
|
||||
|
||||
// check each member in picking channel for role
|
||||
let str = `In picking (${roleName}):`;
|
||||
for (const member of picking.members.values()) {
|
||||
if (member.roles.cache.find((role) => role.name === roleName)) {
|
||||
if (str !== `In picking (${roleName}):`) str += ",";
|
||||
str += " " + getApplicableName(member);
|
||||
}
|
||||
}
|
||||
if (str === `In picking (${roleName}):`)
|
||||
str = `None found ¯\\_(ツ)_/¯ (${roleName})`;
|
||||
|
||||
// respond
|
||||
return await interaction.followUp(str);
|
||||
}
|
||||
}
|
||||
|
||||
if (command === "hello") {
|
||||
await interaction.reply("world");
|
||||
}
|
||||
|
||||
if (
|
||||
command === "topicking" ||
|
||||
command === "end" ||
|
||||
command === "resetteams"
|
||||
) {
|
||||
await interaction.reply("Moving members...");
|
||||
|
||||
// get voice channels
|
||||
const blu = interaction.guild.channels.cache.find(
|
||||
(channel) => channel.name === "blu" || channel.id === BLU_ID
|
||||
);
|
||||
if (!blu) return console.error("Can't find channel 'blu'!");
|
||||
const red = interaction.guild.channels.cache.find(
|
||||
(channel) => channel.name === "red" || channel.id === RED_ID
|
||||
);
|
||||
if (!red) return console.error("Can't find channel 'red'!");
|
||||
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
|
||||
let members = blu.members.concat(red.members);
|
||||
if (members.size === 0) {
|
||||
return await interaction.followUp("Found no members in blu or red");
|
||||
}
|
||||
|
||||
let eCount = 0;
|
||||
|
||||
// move members to picking
|
||||
const moveToPicking = async (member) => {
|
||||
try {
|
||||
await member.voice.setChannel(picking);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
eCount++;
|
||||
}
|
||||
};
|
||||
|
||||
const moveAllToPicking = async () => {
|
||||
return Promise.all(
|
||||
Array.from(members, async ([memberId, member]) => {
|
||||
await moveToPicking(member);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
moveAllToPicking().then(() =>
|
||||
interaction.followUp(
|
||||
`Moved members in blu and red${
|
||||
eCount > 0 ? ` (error moving ${eCount} members)` : ""
|
||||
}`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (command === "fklist" || command === "listfk") {
|
||||
// moves players in picking to fatkid channel, for use in captain pugs
|
||||
await interaction.reply("Moving fatkids...");
|
||||
|
||||
// get voice channels
|
||||
const picking = interaction.guild.channels.cache.find(
|
||||
(channel) => channel.name === "picking" || channel.id === PICKING_ID
|
||||
);
|
||||
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'!");
|
||||
|
||||
// get members in voice channel
|
||||
const members = picking.members;
|
||||
if (members.size === 0) {
|
||||
return await interaction.followUp("Found no members in picking");
|
||||
}
|
||||
|
||||
let str = "",
|
||||
eCount = 0;
|
||||
|
||||
const logFk = async (member) => {
|
||||
try {
|
||||
await member.voice.setChannel(fk);
|
||||
if (str.length > 0) str += ", ";
|
||||
str += getApplicableName(member);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
eCount++;
|
||||
}
|
||||
};
|
||||
|
||||
const logAllFks = async () => {
|
||||
return Promise.all(
|
||||
Array.from(members, async ([memberId, member]) => {
|
||||
await logFk(member);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
logAllFks().then(() =>
|
||||
interaction.followUp(
|
||||
`Fatkids: ${str}${
|
||||
eCount > 0 ? ` (error moving ${eCount} members)` : ""
|
||||
}`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (command === "pick" || command === "autocaptain") {
|
||||
await interaction.reply("Picking teams...");
|
||||
|
||||
// get voice channels
|
||||
const picking = interaction.guild.channels.cache.find(
|
||||
(channel) => channel.name === "picking" || channel.id === VOICE_ID_PICKING
|
||||
(channel) => channel.name === "picking" || channel.id === PICKING_ID
|
||||
);
|
||||
if (!picking) return console.error("Can't find channel 'picking'!");
|
||||
const blu = interaction.guild.channels.cache.find(
|
||||
(channel) => channel.name === "blu" || channel.id === VOICE_ID_BLU
|
||||
(channel) => channel.name === "blu" || channel.id === BLU_ID
|
||||
);
|
||||
if (!blu) return console.error("Can't find channel 'blu'!");
|
||||
const red = interaction.guild.channels.cache.find(
|
||||
(channel) => channel.name === "red" || channel.id === VOICE_ID_RED
|
||||
(channel) => channel.name === "red" || channel.id === RED_ID
|
||||
);
|
||||
if (!red) return console.error("Can't find channel 'red'!");
|
||||
|
||||
@ -404,6 +608,22 @@ client.on("interactionCreate", async (interaction) => {
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
if (command === "clear" || command === "bclear") {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
91
register.js
91
register.js
@ -5,6 +5,86 @@ const path = require("path");
|
||||
|
||||
// set static commands
|
||||
const commands = [
|
||||
{
|
||||
name: "hello",
|
||||
description: "Replies 'world'",
|
||||
},
|
||||
{
|
||||
name: "topicking",
|
||||
description: "Pulls team and addup channel members into picking channel",
|
||||
},
|
||||
{
|
||||
name: "end",
|
||||
description: "Pulls team and addup channel members into picking channel",
|
||||
},
|
||||
{
|
||||
name: "resetteams",
|
||||
description: "Pulls team channel members into picking channel",
|
||||
},
|
||||
/*{
|
||||
name: "testfk",
|
||||
description: "debug fk",
|
||||
},*/
|
||||
{
|
||||
name: "fklist",
|
||||
description: "Pulls addup channel members into fk channel and lists them",
|
||||
},
|
||||
{
|
||||
name: "listfk",
|
||||
description: "Pulls addup channel members into fk channel and lists them",
|
||||
},
|
||||
{
|
||||
name: "clear",
|
||||
description: "Clears bot messages in command channel",
|
||||
},
|
||||
{
|
||||
name: "bclear",
|
||||
description: "Clears bot messages in command channel",
|
||||
},
|
||||
{
|
||||
name: "scout",
|
||||
description: "Lists picking channel members with scout role",
|
||||
},
|
||||
{
|
||||
name: "soldier",
|
||||
description: "Lists picking channel members with soldier role",
|
||||
},
|
||||
{
|
||||
name: "pyro",
|
||||
description: "Lists picking channel members with pyro role",
|
||||
},
|
||||
{
|
||||
name: "demo",
|
||||
description: "Lists picking channel members with demo role",
|
||||
},
|
||||
{
|
||||
name: "demoman",
|
||||
description: "Alias of /demo",
|
||||
},
|
||||
{
|
||||
name: "heavy",
|
||||
description: "Lists picking channel members with heavy role",
|
||||
},
|
||||
{
|
||||
name: "engineer",
|
||||
description: "Lists picking channel members with engineer role",
|
||||
},
|
||||
{
|
||||
name: "engi",
|
||||
description: "Alias of /engineer",
|
||||
},
|
||||
{
|
||||
name: "medic",
|
||||
description: "Lists picking channel members with medic role",
|
||||
},
|
||||
{
|
||||
name: "sniper",
|
||||
description: "Lists picking channel members with sniper role",
|
||||
},
|
||||
{
|
||||
name: "spy",
|
||||
description: "Lists picking channel members with spy role",
|
||||
},
|
||||
{
|
||||
name: "pick",
|
||||
description: "Automatically picks teams",
|
||||
@ -22,16 +102,7 @@ const commandFiles = fs.readdirSync(commandsPath);
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`./commands/${file}`);
|
||||
if ("data" in command && "execute" in command) {
|
||||
let commandData = command.data;
|
||||
commands.push(commandData);
|
||||
if (command.synonyms) {
|
||||
for (const synonym of command.synonyms) {
|
||||
commands.push({
|
||||
...commandData,
|
||||
name: synonym,
|
||||
});
|
||||
}
|
||||
}
|
||||
commands.push(command.data.toJSON());
|
||||
} else {
|
||||
console.error(`${__filename}: Invalid command file: ${file}`);
|
||||
}
|
||||
|
||||
43
utils.js
43
utils.js
@ -1,43 +0,0 @@
|
||||
export const findChannelfromCache = (channelCache, name, id) => {
|
||||
return channelCache.find(
|
||||
(channel) => channel.name === name || channel.id === id
|
||||
);
|
||||
}
|
||||
|
||||
export const matchString = (str, search) => {
|
||||
if (!str || !search) return false;
|
||||
return str.toLowerCase().includes(search.toLowerCase());
|
||||
};
|
||||
|
||||
export const findPlayer = (guild, searchName) => {
|
||||
// search display name
|
||||
let player = guild.members.cache.find((member) =>
|
||||
matchString(member.displayName, searchName)
|
||||
);
|
||||
if (!player) {
|
||||
// search global name
|
||||
player = guild.members.cache.find((member) =>
|
||||
matchString(member.user.globalName, searchName)
|
||||
);
|
||||
}
|
||||
if (!player) {
|
||||
// search username
|
||||
player = guild.members.cache.find((member) =>
|
||||
matchString(member.user.username, searchName)
|
||||
);
|
||||
}
|
||||
if (!player) {
|
||||
// match id
|
||||
player = guild.members.cache.find((member) => member.id === searchName);
|
||||
}
|
||||
return player;
|
||||
};
|
||||
|
||||
export const getApplicableName = (player) => {
|
||||
return (
|
||||
player.displayName ||
|
||||
player.user.globalName ||
|
||||
player.user.username ||
|
||||
player.id
|
||||
);
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user