all repos — stealth-developers @ 7630fcbf36d37076f1fd7e64a755a7d73fda56be

src/interactions/commands/bug/index.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
import {
	ActionRowBuilder,
	ButtonBuilder,
	type ButtonInteraction,
	ButtonStyle,
	type ChatInputCommandInteraction,
	type Client,
	type ModalSubmitInteraction,
	SlashCommandBuilder,
} from "discord.js";
import { buildReportModal } from "./_shared";
import {
	handleCloseButton,
	handleDeleteButton,
	handleEditButton,
	handleOpenButton,
	handleTrelloButton,
} from "./buttons";
import { handleEditModal, handleNewBugModal } from "./modals";

const commandData = new SlashCommandBuilder()
	.setName("bug")
	.setDescription("Make a bug report")
	.addSubcommand((subcommand) =>
		subcommand.setName("report").setDescription("Report a new bug"),
	)
	.addSubcommand((subcommand) =>
		subcommand
			.setName("help")
			.setDescription("Help a user report a bug")
			.addUserOption((option) =>
				option
					.setName("user")
					.setDescription("The user to send the button to")
					.setRequired(false),
			),
	);

async function execute(
	_client: Client,
	interaction: ChatInputCommandInteraction,
) {
	if (!interaction.isChatInputCommand()) return;

	const subcommand = interaction.options.getSubcommand();
	const commandId = interaction.commandId;

	switch (subcommand) {
		case "report":
			await interaction.showModal(buildReportModal());
			break;
		case "help": {
			const user = interaction.options.getUser("user", false);
			const command = `</bug report:${commandId}>`;

			const message = [
				"📝 ",
				user ? `<@${user.id}>, ` : "",
				"You can click the button below to report a bug, you will be shown a popup where you can enter the bug details & attach a relevant piece of media. ",
				`Alternatively, you can use the ${command} command, which does the same thing.`,
			].join("");

			const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
				new ButtonBuilder()
					.setCustomId("bug:new")
					.setLabel("Make a report")
					.setStyle(ButtonStyle.Primary),
			);

			await interaction.reply({
				content: message,
				components: [actionRow],
			});

			break;
		}
		default:
			await interaction.reply({
				content: "❌ Unknown subcommand.",
				flags: ["Ephemeral"],
			});
	}
}

async function buttonExecute(client: Client, interaction: ButtonInteraction) {
	const [, action] = interaction.customId.split(":");

	switch (action) {
		case "close":
			await handleCloseButton(client, interaction);
			break;
		case "open":
			await handleOpenButton(client, interaction);
			break;
		case "edit":
			await handleEditButton(client, interaction);
			break;
		case "delete":
			await handleDeleteButton(client, interaction);
			break;
		case "trello":
			await handleTrelloButton(client, interaction);
			break;
		case "new":
			await interaction.showModal(buildReportModal());
			break;
		default:
			await interaction.reply({
				content: "❌ Unknown button action.",
				flags: ["Ephemeral"],
			});
	}
}

async function modalExecute(
	client: Client,
	interaction: ModalSubmitInteraction,
) {
	const [, action] = interaction.customId.split(":");
	switch (action) {
		case "edit":
			await handleEditModal(client, interaction);
			break;
		case "report":
			await handleNewBugModal(client, interaction);
			break;
		default:
			await interaction.reply({
				content: "❌ Unknown modal action.",
				flags: ["Ephemeral"],
			});
	}
}

export default {
	data: commandData,
	buttonExecute,
	modalExecute,
	execute,
};