Guest User

sd

a guest
Jan 19th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.78 KB | None | 0 0
  1. const { Events, EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
  2. const { trelloKey, trelloToken } = require('../config.json');
  3. const Trello = require("trello");
  4. const trello = new Trello(trelloKey, trelloToken);
  5.  
  6. module.exports = {
  7. name: Events.InteractionCreate,
  8. async execute(interaction) {
  9. if (interaction.isChatInputCommand()) {
  10.  
  11. const command = interaction.client.commands.get(interaction.commandName);
  12.  
  13. if (!command) {
  14. console.error(`No command matching ${interaction.commandName} was found.`);
  15. return;
  16. }
  17.  
  18. try {
  19. await command.execute(interaction);
  20. } catch (error) {
  21. console.error(error);
  22. if (interaction.replied || interaction.deferred) {
  23. await interaction.followUp({
  24. content: 'There was an error while executing this command!',
  25. ephemeral: true
  26. });
  27. } else {
  28. await interaction.followUp({
  29. content: 'There was an error while executing this command!',
  30. ephemeral: true
  31. });
  32. }
  33. }
  34. } else if (interaction.isButton()) {
  35. const disabledApprove = new ButtonBuilder()
  36. .setEmoji('✅')
  37. .setCustomId('disabledApprove')
  38. .setLabel('Approve')
  39. .setStyle(ButtonStyle.Success)
  40. .setDisabled(true);
  41.  
  42. const disabledDeny = new ButtonBuilder()
  43. .setEmoji('❎')
  44. .setCustomId('disabledDeny')
  45. .setLabel('Deny')
  46. .setStyle(ButtonStyle.Danger)
  47. .setDisabled(true);
  48.  
  49. const disabledRow = new ActionRowBuilder()
  50. .addComponents(disabledApprove, disabledDeny);
  51.  
  52. const allowedIDs = ["908762498331709480", "908763421833584671", "1196511226545574021", "1196486582765617253"];
  53.  
  54. if (interaction.customId === 'approve') {
  55. if (interaction.member.roles.cache.hasAny(...allowedIDs)) {
  56. const originalEmbed = interaction.message.embeds[0];
  57. const approvedEmbed = new EmbedBuilder()
  58. .setColor('#2ecc71') // Change the color to green
  59. .setTitle('Award Request Approved') // Change the title
  60. .setDescription('The award request has been approved.') // Change the description
  61. .setFields(originalEmbed.fields) // Copy the fields from the original embed
  62. .addFields(
  63. {name: "Update approved by", value: `<@${interaction.member.id}>`},
  64. )
  65.  
  66. if (interaction.member.roles.cache.hasAny(...allowedIDs)) {
  67. await interaction.message.edit({
  68. embeds: [approvedEmbed],
  69. components: [disabledRow]
  70. }).catch(console.error);
  71. let award = await interaction.message.embeds[0].fields[0].value;
  72. let recipient = await interaction.message.embeds[0].fields[2].value;
  73. let awarderID = interaction.member.id;
  74. let awarderNickname = (await interaction.guild.members.fetch(awarderID)).nickname;
  75. let reason = await interaction.message.embeds[0].fields[3].value;
  76. let updater = await interaction.message.embeds[0].fields[4].value;
  77. switch (award) {
  78. case "Medal of Honor":
  79. await trello.addCard(
  80. interaction.message.embeds[0].fields[2].value,
  81. `Recipient: ${recipient}
  82. Awarded by: ${awarderNickname}
  83. Reason: ${reason}
  84. Approved by: ${updater}
  85. This was added via an Amethyst Integration.
  86. `, "64359eb18b396e40d86a50be")
  87. break
  88. case "":
  89. default:
  90. console.log('nuh uh no award for you');
  91. }
  92. }
  93.  
  94. await interaction.reply({
  95. content: "Award successfully approved.",
  96. ephemeral: true
  97. })
  98. } else {
  99. await interaction.reply({
  100. content: 'You do not have permission to run this command. Contact <@1071373709157351464> if you think that this is a mistake.',
  101. ephemeral: true
  102. });
  103. }
  104. } else if (interaction.customId === 'deny') {
  105. if (interaction.member.roles.cache.hasAny(...allowedIDs)) {
  106. const modal = new ModalBuilder()
  107. .setCustomId('denyModal')
  108. .setTitle('Denial Information')
  109. const denialReason = new TextInputBuilder()
  110. .setCustomId('denialReason')
  111. .setLabel('Why was this award request denied?')
  112. .setStyle(TextInputStyle.Paragraph)
  113. .setRequired(true)
  114. const actionRow1 = new ActionRowBuilder().addComponents(denialReason);
  115. modal.addComponents(actionRow1);
  116. const filter = (interaction) => interaction.customId === 'denyModal';
  117. await interaction.showModal(modal);
  118. const blah = await interaction.awaitModalSubmit({filter, time: 120_000})
  119. await blah.reply({
  120. content: "Award successfully denied.",
  121. ephemeral: true
  122. })
  123. .catch(console.error);
  124. const denialReasonFr = blah.fields.getTextInputValue('denialReason')
  125.  
  126. const originalEmbed = interaction.message.embeds[0];
  127. const deniedEmbed = new EmbedBuilder()
  128. .setColor('#d30e0e') // Change the color to red
  129. .setTitle('Award Denied') // Change the title
  130. .setDescription('The award request has been denied.') // Change the description
  131. .setFields(originalEmbed.fields) // Copy the fields from the original embed
  132. .addFields(
  133. {name: "Award Denied by", value: `<@${interaction.member.id}>`},
  134. {name: "Reason for denial", value: `${denialReasonFr}`}
  135. )
  136. if (interaction.member.roles.cache.hasAny(...allowedIDs)) {
  137. await interaction.message.edit({
  138. embeds: [deniedEmbed],
  139. components: [disabledRow]
  140. }).catch(console.error);
  141. } else {
  142. await interaction.message.reply({
  143. content: 'You do not have permission to run this command. Contact <@1071373709157351464> if you think that this is a mistake.',
  144. ephemeral: true
  145. });
  146. }
  147. } else {
  148. await interaction.reply({
  149. content: 'You do not have permission to run this command. Contact <@1071373709157351464> if you think that this is a mistake.',
  150. ephemeral: true
  151. });
  152. }
  153. } else {
  154. await interaction.message.reply({
  155. content: 'You do not have permission to run this command. Contact <@1071373709157351464> if you think that this is a mistake.',
  156. ephemeral: true
  157. });
  158. }
  159. } else if (interaction.isStringSelectMenu()) {
  160. // hjandle
  161. } else if (interaction.isAutocomplete()) {
  162. const command = interaction.client.commands.get(interaction.commandName);
  163.  
  164. if (!command) {
  165. console.error(`No command matching ${interaction.commandName} was found.`);
  166. return;
  167. }
  168. try {
  169. await command.autocomplete(interaction);
  170. } catch (error) {
  171. console.error(error);
  172. }
  173. }
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment