apps/bot/src/feats/tickets/buttons.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 141 142 |
import { ButtonBuilder, ButtonStyle } from "discord.js";
import { Result } from "@sapphire/framework";
import { option } from "@purrkit/router";
import { kitten } from "@/client";
import { errorMessage, PublicError } from "@/lib";
import * as actions from "./actions";
export const closeTicketButton = kitten.button("b-close-ticket", {
options: {
ticketId: option.string({ required: true }),
},
async run(interaction) {
if (!interaction.guild)
return errorMessage(interaction, "You must run this command in a guild");
const modal = await actions.triggerCloseTicket(
interaction.user,
interaction.guild,
interaction.channelId,
);
await interaction.showModal(modal);
},
});
export const deleteTicketButton = kitten.button("delete-ticket", {
options: {
ticketId: option.string({ required: true }),
},
async run() {},
});
export const claimTicketButton = kitten.button("claim-ticket", {
options: {
ticketId: option.string({ required: true }),
},
async run() {},
});
export const unclaimTicketButton = kitten.button("unclaim-ticket", {
options: {
ticketId: option.string({ required: true }),
},
async run() {},
});
export const thankButton = kitten.button("thank", {
options: {
ticketId: option.string({ required: true }),
},
async run() {},
});
export const commentsButton = kitten.button("comments", {
options: {
ticketId: option.string({ required: true }),
},
async run() {},
});
export const newTicketButton = kitten.button("open-ticket", {
run: async (interaction) => {
if (!interaction.guild)
return errorMessage(interaction, "You must run this command in a guild");
const func = actions.createTicket(interaction.member ?? interaction.user, interaction.guild);
const ticketResult = await Result.fromAsync(async () => func);
if (ticketResult.isErr()) {
const error = ticketResult.unwrapErr();
if (error instanceof PublicError) {
return errorMessage(interaction, error.message);
} else {
console.error(error);
return errorMessage(interaction, "An unexpected error occurred while creating the ticket.");
}
}
const { channelId } = ticketResult.unwrap();
return interaction.reply({
content: `Opened ticket <#${channelId}>.`,
flags: ["Ephemeral"],
});
},
});
export const TicketButtons = [
newTicketButton,
closeTicketButton,
deleteTicketButton,
claimTicketButton,
thankButton,
commentsButton,
];
export const TicketButtonPresets = {
close: (id: string) =>
new ButtonBuilder()
.setCustomId(closeTicketButton.id({ ticketId: id }))
.setLabel("Close Ticket")
.setStyle(ButtonStyle.Danger),
delete: (id: string) =>
new ButtonBuilder()
.setCustomId(deleteTicketButton.id({ ticketId: id }))
.setLabel("Delete Ticket")
.setStyle(ButtonStyle.Danger),
claim: (id: string) =>
new ButtonBuilder()
.setCustomId(claimTicketButton.id({ ticketId: id }))
.setLabel("Claim Ticket")
.setStyle(ButtonStyle.Primary),
thank: (id: string) =>
new ButtonBuilder()
.setCustomId(thankButton.id({ ticketId: id }))
.setLabel("Thank your moderator")
.setEmoji("💖")
.setStyle(ButtonStyle.Primary),
comments: (id: string) =>
new ButtonBuilder()
.setCustomId(commentsButton.id({ ticketId: id }))
.setLabel("View comments")
.setStyle(ButtonStyle.Primary),
transcript: (id: string) =>
new ButtonBuilder()
.setLabel("View Transcript")
.setURL(`https://tickets.vt3e.cat/tickets/${id}`)
.setStyle(ButtonStyle.Link),
create: () =>
new ButtonBuilder()
.setLabel("Open a Ticket")
.setStyle(ButtonStyle.Success)
.setCustomId(newTicketButton.id()),
upload: (id: string) =>
new ButtonBuilder()
.setLabel("Upload a video")
.setStyle(ButtonStyle.Link)
.setURL(`https://tickets.vt3e.cat/upload/${id}`),
};
export default TicketButtonPresets;
|