updated /nucleus suggest to be nice, fixed help, added needs saving to footer for automod settings.
diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts
index 3b0cd62..e27ee69 100644
--- a/src/events/interactionCreate.ts
+++ b/src/events/interactionCreate.ts
@@ -4,8 +4,7 @@
import close from "../actions/tickets/delete.js";
import createTranscript from "../premium/createTranscript.js";
-import type { ButtonInteraction, Interaction } from "discord.js";
-import type Discord from "discord.js";
+import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, Interaction, InteractionEditReplyOptions, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } from "discord.js";
import type { NucleusClient } from "../utils/client.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
@@ -14,6 +13,7 @@
import { callback as muteCallback, check as muteCheck } from "../commands/mod/mute.js";
import { callback as nicknameCallback, check as nicknameCheck } from "../commands/mod/nick.js";
import { callback as warnCallback, check as warnCheck } from "../commands/mod/warn.js";
+import client from "../utils/client.js";
export const event = "interactionCreate";
@@ -27,6 +27,10 @@
async function interactionCreate(interaction: Interaction) {
if (interaction.isButton()) {
+ if (interaction.customId.endsWith(":Suggestion")) {
+ const value = interaction.customId.startsWith("accept") || interaction.customId.startsWith("implement") ? true : false
+ return await modifySuggestion(interaction, value);
+ }
switch (interaction.customId) {
case "rolemenu": {
return await roleMenu(interaction);
@@ -43,12 +47,6 @@
case "createtranscript": {
return await createTranscript(interaction);
}
- case "suggestionAccept": {
- return await modifySuggestion(interaction, true);
- }
- case "suggestionDeny": {
- return await modifySuggestion(interaction, false);
- }
}
// Mod actions
if (interaction.customId.startsWith("mod:")) {
@@ -57,27 +55,27 @@
const member = await interaction.guild?.members.fetch(memberId!);
switch (action) {
case "kick": {
- const check = await kickCheck(interaction, false, member);
+ const check = kickCheck(interaction, false, member);
if (check !== true) return await errorMessage(interaction, check!);
return await kickCallback(interaction, member);
}
case "ban": {
- const check = await banCheck(interaction, false, member);
+ const check = banCheck(interaction, false, member);
if (check !== true) return await errorMessage(interaction, check!);
return await banCallback(interaction, member);
}
case "mute": {
- const check = await muteCheck(interaction, false, member);
+ const check = muteCheck(interaction, false, member);
if (check !== true) return await errorMessage(interaction, check!);
return await muteCallback(interaction, member);
}
case "nickname": {
- const check = await nicknameCheck(interaction, false, member);
+ const check = nicknameCheck(interaction, false, member);
if (check !== true) return await errorMessage(interaction, check || "Something went wrong");
return await nicknameCallback(interaction, member);
}
case "warn": {
- const check = await warnCheck(interaction, false, member);
+ const check = warnCheck(interaction, false, member);
if (check !== true) return await errorMessage(interaction, check!);
return await warnCallback(interaction, member);
}
@@ -86,24 +84,120 @@
}
}
-async function modifySuggestion(interaction: Discord.MessageComponentInteraction, accept: boolean) {
- const message = await interaction.message;
+const getReason = async (buttonInteraction: ButtonInteraction, prompt: string) => {
+ const modal = new ModalBuilder()
+ .addComponents(
+ new ActionRowBuilder<TextInputBuilder>().addComponents(
+ new TextInputBuilder()
+ .setStyle(TextInputStyle.Paragraph)
+ .setLabel(prompt)
+ .setCustomId("typed")
+ )
+ )
+ .setTitle("Reason")
+ .setCustomId("modal");
+ await buttonInteraction.showModal(modal);
+ let out: ModalSubmitInteraction;
+ try {
+ out = await buttonInteraction.awaitModalSubmit({
+ filter: (i) => i.customId === "modal" && i.user.id === buttonInteraction.user.id,
+ time: 300000
+ });
+ } catch {
+ return null;
+ }
+ await out.deferUpdate();
+ return out.fields.getTextInputValue("typed");
+}
+
+async function modifySuggestion(interaction: ButtonInteraction, accept: boolean) {
+ const message = interaction.message;
await message.fetch();
if (message.embeds.length === 0) return;
- const embed = message.embeds[0];
+ const embed = message.embeds[0]!;
+ const issueNum = embed.footer!.text
+ if(!issueNum) return;
+ const issue = {
+ owner: "ClicksMinutePer",
+ repo: "Nucleus",
+ issue_number: parseInt(issueNum)
+ }
+ let name = "Unknown";
+ const components: InteractionEditReplyOptions["components"] = [];
+ switch(interaction.customId) {
+ case "accept:Suggestion": {
+ name = "Accepted";
+ await interaction.deferUpdate();
+ await client.GitHub.rest.issues.createComment({...issue, body: "Suggestion accepted by " + interaction.user.tag});
+ components.push(new ActionRowBuilder<ButtonBuilder>().addComponents(
+ new ButtonBuilder().setCustomId("close:Suggestion").setLabel("Close").setStyle(ButtonStyle.Secondary),
+ new ButtonBuilder().setCustomId("implemented:Suggestion").setLabel("Implemented").setStyle(ButtonStyle.Secondary)
+ ))
+ break;
+ }
+ case "deny:Suggestion": {
+ name = "Denied";
+ const reason = await getReason(interaction, "Reason for denial");
+ await client.GitHub.rest.issues.createComment({...issue, body: "Suggestion denied by " + interaction.user.tag + " for reason:\n>" + reason});
+ await client.GitHub.rest.issues.update({...issue, state: "closed", state_reason: "not_planned"});
+ // await client.GitHub.rest.issues.lock({...issue, lock_reason: "resolved"})
+ components.push(new ActionRowBuilder<ButtonBuilder>().addComponents(
+ new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger)
+ ))
+ break;
+ }
+ case "close:Suggestion": {
+ name = "Closed";
+ const reason = await getReason(interaction, "Reason for closing");
+ await client.GitHub.rest.issues.createComment({...issue, body: "Suggestion closed by " + interaction.user.tag + " for reason:\n>" + reason});
+ await client.GitHub.rest.issues.update({...issue, state: "closed"});
+ // await client.GitHub.rest.issues.lock({...issue})
+ components.push(new ActionRowBuilder<ButtonBuilder>().addComponents(
+ new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger)
+ ))
+ break;
+ }
+ case "implement:Suggestion": {
+ name = "Implemented";
+ await interaction.deferUpdate();
+ await client.GitHub.rest.issues.createComment({...issue, body: "Suggestion implemented"});
+ await client.GitHub.rest.issues.update({...issue, state: "closed", state_reason: "completed"});
+ await client.GitHub.rest.issues.lock({...issue, lock_reason: "resolved"})
+ break;
+ }
+ case "lock:Suggestion": {
+ name = "Locked";
+ await interaction.deferUpdate();
+ await client.GitHub.rest.issues.lock({...issue});
+ break;
+ }
+ case "spam:Suggestion": {
+ name = "Marked as Spam";
+ await interaction.deferUpdate();
+ await client.GitHub.rest.issues.update({...issue, state: "closed", state_reason: "not_planned"});
+ await client.GitHub.rest.issues.lock({...issue, lock_reason: "spam"})
+ break;
+ }
+ }
+
const newcolor = accept ? "Success" : "Danger";
- const footer = {
- text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`,
- iconURL: interaction.user.displayAvatarURL()
- };
+ const newEmoji = accept ? "ICONS.ADD" : "ICONS.OPP.ADD";
const newEmbed = new EmojiEmbed()
- .setTitle(embed!.title!)
+ .setEmoji(newEmoji)
+ .setTitle(embed!.title!.replace(/.+> /, ""))
.setDescription(embed!.description!)
- .setFooter(footer)
- .setStatus(newcolor);
+ .setFields({
+ name: name + " by",
+ value: interaction.user.tag,
+ })
+ .setStatus(newcolor)
+ .setFooter(embed!.footer);
- await interaction.update({ embeds: [newEmbed], components: [] });
+ await interaction.editReply({
+ embeds: [newEmbed],
+ components: components
+ });
}
export async function callback(_client: NucleusClient, interaction: Interaction) {