From 5f513d740eebf20334dbd959b4038f7b9670770a Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 24 May 2024 17:45:57 +0100 Subject: [PATCH] Change sacrifice command embed colours to go green when successful from red (#237) # Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Update the sacrifice command so that the embed starts red, goes grey if cancelled, and goes green if successful - Fix event not checking if the user who ran the command is the same user who clicked the button - Remove duplicated card name in the embed, didn't need it in the footer as well as the main body #203, #230, #238 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that provde my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Co-authored-by: VylpesTester Reviewed-on: https://git.vylpes.xyz/External/card-drop/pulls/237 Reviewed-by: VylpesTester Co-authored-by: Ethan Lane Co-committed-by: Ethan Lane --- src/buttonEvents/Sacrifice.ts | 18 ++++++++++++++---- src/commands/sacrifice.ts | 4 ++-- src/constants/EmbedColours.ts | 6 ++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/buttonEvents/Sacrifice.ts b/src/buttonEvents/Sacrifice.ts index 6c4a1a6..a82ba81 100644 --- a/src/buttonEvents/Sacrifice.ts +++ b/src/buttonEvents/Sacrifice.ts @@ -24,6 +24,11 @@ export default class Sacrifice extends ButtonEvent { const userId = interaction.customId.split(" ")[2]; const cardNumber = interaction.customId.split(" ")[3]; + if (userId != interaction.user.id) { + await interaction.reply("Only the user who created this sacrifice can confirm it."); + return; + } + const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber); if (!cardInInventory) { @@ -67,8 +72,8 @@ export default class Sacrifice extends ButtonEvent { const embed = new EmbedBuilder() .setTitle("Card Sacrificed") .setDescription(description.join("\n")) - .setColor(EmbedColours.Ok) - .setFooter({ text: `${interaction.user.username} · ${cardData.card.name}` }); + .setColor(EmbedColours.Green) + .setFooter({ text: `${interaction.user.username}` }); const row = new ActionRowBuilder() .addComponents([ @@ -94,6 +99,11 @@ export default class Sacrifice extends ButtonEvent { const userId = interaction.customId.split(" ")[2]; const cardNumber = interaction.customId.split(" ")[3]; + if (userId != interaction.user.id) { + await interaction.reply("Only the user who created this sacrifice can cancel it."); + return; + } + const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber); if (!cardInInventory) { @@ -122,8 +132,8 @@ export default class Sacrifice extends ButtonEvent { const embed = new EmbedBuilder() .setTitle("Sacrifice Cancelled") .setDescription(description.join("\n")) - .setColor(EmbedColours.Error) - .setFooter({ text: `${interaction.user.username} · ${cardData.card.name}` }); + .setColor(EmbedColours.Grey) + .setFooter({ text: `${interaction.user.username}` }); const row = new ActionRowBuilder() .addComponents([ diff --git a/src/commands/sacrifice.ts b/src/commands/sacrifice.ts index c6dc7b3..4d1c51a 100644 --- a/src/commands/sacrifice.ts +++ b/src/commands/sacrifice.ts @@ -50,8 +50,8 @@ export default class Sacrifice extends Command { const embed = new EmbedBuilder() .setTitle("Sacrifice") .setDescription(description.join("\n")) - .setColor(EmbedColours.Grey) - .setFooter({ text: `${interaction.user.username} · ${cardData.card.name}` }); + .setColor(EmbedColours.Error) + .setFooter({ text: `${interaction.user.username}` }); const row = new ActionRowBuilder() .addComponents([ diff --git a/src/constants/EmbedColours.ts b/src/constants/EmbedColours.ts index 36777e3..f270eef 100644 --- a/src/constants/EmbedColours.ts +++ b/src/constants/EmbedColours.ts @@ -1,8 +1,14 @@ export default class EmbedColours { + // General public static readonly Ok = 0x3050ba; public static readonly Success = 0x50c878; public static readonly Error = 0xff0000; + + // Colours public static readonly Grey = 0xd3d3d3; + public static readonly Green = 0x228B22; + + // Card Types public static readonly BronzeCard = 0xcd7f32; public static readonly SilverCard = 0xc0c0c0; public static readonly GoldCard = 0xffd700;