From 4108ff08db46eb9cb111c29a1ef266c61e7049f7 Mon Sep 17 00:00:00 2001 From: Wilbatronic <65288629+Wilbatronic@users.noreply.github.com> Date: Sat, 21 May 2022 20:29:03 +0100 Subject: [PATCH] Added Unclaim.ts Most likely wont work --- src/commands/orders/worker/unclaim.ts | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/commands/orders/worker/unclaim.ts diff --git a/src/commands/orders/worker/unclaim.ts b/src/commands/orders/worker/unclaim.ts new file mode 100644 index 0000000..ae565b9 --- /dev/null +++ b/src/commands/orders/worker/unclaim.ts @@ -0,0 +1,31 @@ +import { OrderStatus } from "@prisma/client"; +import { db } from "../../../database/database"; +import { generateOrderId, getClaimedOrder, hasActiveOrder, matchActiveOrder, matchOrderStatus } from "../../../database/order"; +import { client } from "../../../providers/client"; +import { config, text } from "../../../providers/config"; +import { mainGuild } from "../../../providers/discord"; +import { permissions } from "../../../providers/permissions"; +import { Command } from "../../../structures/Command"; +import { format } from "../../../utils/string"; + +export const command = new Command("unclaim", "Unclaims an order.") + .addPermission(permissions.employee) + .addOption("string", o => o.setRequired(true).setName("order").setDescription("The order to Unclaim.")) + .setExecutor(async int => { + if (await getClaimedOrder(int.user)) { + await int.reply(text.commands.claim.existing); + return; + } + const match = int.options.getString("order", true); + const order = await matchOrderStatus(match, OrderStatus.Unprepared); + if (order === null) { + await int.reply(text.common.invalidOrderId); + return; + } + if (order.user === int.user.id && !permissions.developer.hasPermission(int.user)) { + await int.reply(text.common.interactOwn); + return; + } + await db.order.update({ where: { id: order.id }, data: { claimer: null, status: OrderStatus.Preparing } }); + await int.reply(text.commands.claim.success); + });