Skip to content

Commit

Permalink
allow dropping orders
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhappyma committed Nov 16, 2024
1 parent 788ee09 commit c02b3c0
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/modules/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { emojiInline } from "../utils/emoji";
import updateOrderStatusMessage from "../utils/updateOrderStatusMessage";
import {
KitchenChannel,
clearKitchenMessages,
editKitchenMessage,
sendKitchenMessage,
} from "../utils/kitchenChannels";
Expand Down Expand Up @@ -60,6 +61,10 @@ bot.registerButton("order:(\\d+):fill", async (interaction) => {
);
const orderFillingActionRow =
new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder()
.setCustomId(`order:${order.id}:drop`)
.setLabel("Unclaim Order")
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setLabel("Reject Order")
.setStyle(ButtonStyle.Danger)
Expand All @@ -78,6 +83,7 @@ bot.registerButton("order:(\\d+):fill", async (interaction) => {
content: `${emojiInline.materialEdit} <@!${interaction.user.id}> claimed order **#${order.id}**`,
allowedMentions: { parse: [] },
});
await interaction.deferUpdate();
const ordersChannel = (await messagesClient.client.channels.fetch(
env.NEW_ORDERS_CHANNEL_ID
)) as TextBasedChannel;
Expand All @@ -90,3 +96,72 @@ bot.registerButton("order:(\\d+):fill", async (interaction) => {
reason: `Order ${order.id} claimed by ${interaction.user.username}`,
});
});

//todo: refactor to share more logic with order creation
bot.registerButton("order:(\\d+):drop", async (interaction) => {
const orderId = interaction.customId.split(":")[1];
const order = await prisma.order.findUnique({
where: {
id: parseInt(orderId),
},
});
if (!order)
return interaction.reply({ content: "Order not found", ephemeral: true });
if (order.chefId !== interaction.user.id)
return interaction.reply({
content: "Nice try, but this isn't your order!",
ephemeral: true,
});
if (order.status !== orderStatus.FILLING)
return interaction.reply({
content: "Can't unclaim order- status is not FILLING",
ephemeral: true,
});
await prisma.order.update({
where: {
id: parseInt(orderId),
},
data: {
status: orderStatus.ORDERED,
chefId: null,
chefUsername: null,
},
});
updateProcessingOrders(orderStatus.ORDERED, order.id);
if (order.statusMessageId)
updateOrderStatusMessage(
order.guildId,
order.channelId,
order.statusMessageId,
`Order ${order.id} has been sent to the kitchen!`
);
await sendKitchenMessage(KitchenChannel.logs, {
content: `${emojiInline.materialDelete} <@!${interaction.user.id}> dropped order **#${order.id}**.`,
allowedMentions: { parse: [] },
});
interaction.deferUpdate();
await clearKitchenMessages(order.id);
const kitchenActionRow = new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder()
.setCustomId(`order:${order.id}:fill`)
.setLabel("Fill Order")
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setLabel("Reject Order")
.setStyle(ButtonStyle.Danger)
.setCustomId(`order:${order.id}:reject`),
]);
const kitchenEmbed = new EmbedBuilder()
.setTitle(`Order from **${interaction.user.username}**`)
.setDescription(order.order)
.setFooter({ text: `Order ID: ${order.id}` });
await sendKitchenMessage(
KitchenChannel.orders,
{
embeds: [kitchenEmbed],
components: [kitchenActionRow],
content: `<@&${env.ORDER_PING_ROLE_ID}>`,
},
order.id
);
});
2 changes: 2 additions & 0 deletions src/utils/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
materialSync: "materialSync:1211509117794131968",
materialDone: "materialDone:1212215187109711932",
materialMail: "materialMail:1305607728286138429",
materialDelete: "materialDelete:1307172324243410944",
};

export const emojiInline = {
Expand All @@ -22,4 +23,5 @@ export const emojiInline = {
materialSync: "<:materialSync:121150911779413196>",
materialDone: "<:materialDone:1212215187109711932>",
materialMail: "<:materialMail:1305607728286138429>",
materialDelete: "<:materialDelete:1307172324243410944>",
};

0 comments on commit c02b3c0

Please sign in to comment.