aboutsummaryrefslogtreecommitdiff
path: root/174bg/discord-bot/commands
diff options
context:
space:
mode:
Diffstat (limited to '174bg/discord-bot/commands')
-rw-r--r--174bg/discord-bot/commands/_index.js6
-rw-r--r--174bg/discord-bot/commands/close.js55
-rw-r--r--174bg/discord-bot/commands/requisition.js32
3 files changed, 93 insertions, 0 deletions
diff --git a/174bg/discord-bot/commands/_index.js b/174bg/discord-bot/commands/_index.js
new file mode 100644
index 0000000..06615dd
--- /dev/null
+++ b/174bg/discord-bot/commands/_index.js
@@ -0,0 +1,6 @@
+import requisition from "./requisition.js";
+import close from "./close.js";
+
+export { requisition, close };
+
+export default [requisition, close];
diff --git a/174bg/discord-bot/commands/close.js b/174bg/discord-bot/commands/close.js
new file mode 100644
index 0000000..25bdd41
--- /dev/null
+++ b/174bg/discord-bot/commands/close.js
@@ -0,0 +1,55 @@
+import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
+
+export default {
+ data: new SlashCommandBuilder()
+ .setName("close")
+ .setDescription(
+ "Closes the current ticket by logging the contents and deleting the channel.",
+ )
+ .setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
+ execute: async (interaction) => {
+ const channel = interaction.channel;
+
+ if (!channel || !channel.name.startsWith("ticket-")) {
+ return await interaction.reply({
+ content: "This command can only be used in a ticket channel.",
+ ephemeral: true,
+ });
+ }
+
+ // log the contents of the ticket and send to the logs channel if it exists
+ const messages = await channel.messages.fetch({ limit: 100 });
+ const log = messages
+ .map((message) => `${message.author.tag}: ${message.content}`)
+ .reverse()
+ .join("\n");
+
+ console.log(`Ticket log for ${channel.name}:\n${log}`);
+
+ const logsChannel = interaction.guild.channels.cache.find(
+ (ch) => ch.name === "logs" && ch.isTextBased(),
+ );
+
+ if (logsChannel)
+ await logsChannel.send({
+ content: `# Ticket log for ${channel.name}`,
+ files: [
+ {
+ name: `${channel.name}.txt`,
+ attachment: Buffer.from(
+ messages
+ .map(
+ (message) =>
+ `${message.author.tag}/${message.author.id}: ${message.content}`,
+ )
+ .reverse()
+ .join("\n"),
+ ),
+ },
+ ],
+ });
+
+ // delete the channel
+ await channel.delete();
+ },
+};
diff --git a/174bg/discord-bot/commands/requisition.js b/174bg/discord-bot/commands/requisition.js
new file mode 100644
index 0000000..be3cb8a
--- /dev/null
+++ b/174bg/discord-bot/commands/requisition.js
@@ -0,0 +1,32 @@
+import { SlashCommandBuilder } from "discord.js";
+import createTicket from "../utilities/createTicket.js";
+import notifyRoleByName from "../utilities/notifyRoleByName.js";
+
+export default {
+ data: new SlashCommandBuilder()
+ .setName("requisition")
+ .setDescription(
+ "Request items from the quartermaster. A new requisition ticket will be created.",
+ )
+ .addStringOption((option) =>
+ option
+ .setName("contents")
+ .setDescription("What are you requesting? Be as specific as possible.")
+ .setRequired(true),
+ ),
+ execute: async (interaction) => {
+ const contents = interaction.options.getString("contents");
+
+ const ticket = await createTicket(interaction, ["quartermaster"]);
+
+ await ticket.send({
+ content: `**New requisition request from <@${interaction.user.id}>**: ${contents}`,
+ });
+
+ // reply to the user
+ await interaction.reply({
+ content: `Your requisition ticket has been created: <#${ticket.id}>`,
+ ephemeral: true,
+ });
+ },
+};