M
apps/bot/src/feats/tickets/buttons.ts
→
apps/bot/src/feats/tickets/buttons.ts
@@ -1,6 +1,6 @@
import { option } from "@purrkit/router";
import { Result } from "@sapphire/framework";
-import { type TicketWithRelations, getTicketsByUser } from "@stealth-developers/db";
+import { type TicketWithRelations, editTicket, getTicketsByUser } from "@stealth-developers/db";
import {
ActionRowBuilder,
ButtonBuilder,
@@ -10,7 +10,7 @@ TextDisplayBuilder,
} from "discord.js";
import { kitten } from "@/client";
-import { PublicError, errorMessage, handleError } from "@/lib";
+import { PublicError, errorMessage, getTextChannel, handleError } from "@/lib";
import { useGetTicketData } from "@/middleware";
import * as actions from "./actions";
@@ -230,11 +230,37 @@ if (result.isErr()) return errorMessage(interaction, "Failed to delete ticket channel");
},
});
-export const thankButton = kitten.button("b-thank-ticket", {
+export const thankButton = useGetTicketData.button("b-thank-ticket", {
options: {
ticketId: option.string({ required: true }),
},
- async run() {},
+ async run(interaction, _, ctx) {
+ const { guild, ticket } = ctx;
+ if (!guild) return errorMessage(interaction, "Failed to find guild");
+ if (!ticket) return errorMessage(interaction, "Failed to find ticket");
+
+ const thankedAt = ticket.thankedAt;
+ if (thankedAt) return errorMessage(interaction, "You already thanked for this ticket");
+
+ const channelRes = await Result.fromAsync(getTextChannel(guild.ticketLogChannel!));
+ if (!channelRes.unwrapErr())
+ return errorMessage(interaction, "Failed to find ticket log channel");
+ const channel = channelRes.unwrap();
+
+ await editTicket(ticket.id, {
+ thankedAt: new Date(),
+ });
+
+ Promise.all([
+ channel.send({
+ content: `The reporter said thank you for handling ticket #${ticket.localId}! 💖`,
+ }),
+ interaction.reply({
+ content: "A thank you has been sent! 💖",
+ ephemeral: true,
+ }),
+ ]).catch(() => {});
+ },
});
//