Give/remove +2/+3 pings bot command

Closes #925
This commit is contained in:
Kalle 2022-09-07 17:29:27 +03:00
parent 13fab0bcc4
commit 9ae6ed9fcb
3 changed files with 73 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import { lfgRoleCommand } from "./lfg";
import { accessCommand } from "./access";
import { plusCommand } from "./plus";
import { updateAllCommand } from "./updateall";
import { pingRolesCommand } from "./pings";
import type { BotCommand } from "discord-bot/types";
export const commands = [
@ -11,6 +12,7 @@ export const commands = [
accessCommand,
plusCommand,
updateAllCommand,
pingRolesCommand,
];
export const commandsMap = Object.fromEntries(commands.map((c) => [c.name, c]));

View File

@ -0,0 +1,69 @@
import { SlashCommandBuilder } from "@discordjs/builders";
import type { GuildMemberRoleManager } from "discord.js";
import ids from "../ids";
import type { BotCommand } from "../types";
const COMMAND_NAME = "pings";
const TIER_ARG = "tier";
const ACTION_ARG = "action";
export const pingRolesCommand: BotCommand = {
guilds: [ids.guilds.plusServer],
name: COMMAND_NAME,
builder: new SlashCommandBuilder()
.setName(COMMAND_NAME)
.setDescription(
"Turn on/off pings when people are looking for someone to play with"
)
.addStringOption((option) =>
option
.setName(TIER_ARG)
.setDescription("+2 or +3?")
.setRequired(true)
.addChoices(
{
name: "+2",
value: "+2",
},
{
name: "+3",
value: "+3",
}
)
)
.addStringOption((option) =>
option
.setName(ACTION_ARG)
.setDescription("Add or remove the role?")
.setRequired(true)
.addChoices(
{
name: "add",
value: "add",
},
{
name: "remove",
value: "remove",
}
)
),
execute: async ({ interaction }) => {
const roleBeingAdded = interaction.options.getString(ACTION_ARG) === "add";
const tier = interaction.options.getString(TIER_ARG);
const role =
tier === "+2" ? ids.roles.plusTwoPings : ids.roles.plusThreePings;
const commandUserRoles = interaction.member
?.roles as GuildMemberRoleManager;
if (roleBeingAdded) {
await commandUserRoles.add(role);
} else {
await commandUserRoles.remove(role);
}
return interaction.reply({
content: `${tier} pings role ${roleBeingAdded ? "added" : "removed"}`,
ephemeral: true,
});
},
};

View File

@ -10,6 +10,8 @@ const ids = {
plusTwo: "678169134416265260",
plusThree: "815267885601521696",
// TESTING VALUES
// plusTwoPings: "1017077667276783657",
// plusThreePings: "1017077722813575290",
// plusOne: "992852036334911638",
// plusTwo: "992852055251234936",
// plusThree: "992852066403893258",