pull/59/head
TheCodedProf 3 years ago
parent 35e7371361
commit ca29ebb481

@ -22,7 +22,10 @@ import { capitalize } from "../utils/generateKeyValueList.js";
import { getCommandByName, getCommandMentionByName } from "../utils/getCommandDataByName.js";
import getEmojiByName from "../utils/getEmojiByName.js";
const command = new SlashCommandBuilder().setName("help").setDescription("Shows help for commands").setDMPermission(true);
const command = new SlashCommandBuilder()
.setName("help")
.setDescription("Shows help for commands")
.setDMPermission(true);
const styles: Record<string, { emoji: string }> = {
help: { emoji: "NUCLEUS.LOGO" },
@ -127,9 +130,9 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
);
}
for (const option of options) {
optionString += ` - \`${option.name}\` (${ApplicationCommandOptionType[option.type].replace("Integer", "Number").replace("String", "Text")}) - ${
option.description
}\n`;
optionString += ` - \`${option.name}\` (${ApplicationCommandOptionType[option.type]
.replace("Integer", "Number")
.replace("String", "Text")}) - ${option.description}\n`;
}
const APICommand =
client.commands[
@ -140,7 +143,9 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
allowedToRun = await APICommand.check(interaction as Interaction, true);
}
embed.setDescription(
`${getEmojiByName(styles[currentPath[0]]!.emoji)} **${capitalize(currentData.name)}** | ${currentData.mention}\n\n` +
`${getEmojiByName(styles[currentPath[0]]!.emoji)} **${capitalize(currentData.name)}** | ${
currentData.mention
}\n\n` +
`${currentData.description}\n\n` +
(APICommand
? `${getEmojiByName(allowedToRun ? "CONTROL.TICK" : "CONTROL.CROSS")} You ${

@ -21,7 +21,6 @@ import config from "../../config/main.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder.setName("stats").setDescription("Gets the bot's stats");
const confirm = async (interaction: CommandInteraction) => {
const requiredTexts = [
"just do it",
@ -36,7 +35,7 @@ const confirm = async (interaction: CommandInteraction) => {
"what's a java script",
"it's a feature not a bug",
"that never happened during testing"
]
];
const chosen = requiredTexts[Math.floor(Math.random() * (requiredTexts.length - 1))]!;
const modal = new ModalBuilder()
@ -65,9 +64,8 @@ const confirm = async (interaction: CommandInteraction) => {
}
await out.deferUpdate();
const typed = out.fields.getTextInputValue("confirm");
return typed.toLowerCase() === chosen.toLowerCase()
}
return typed.toLowerCase() === chosen.toLowerCase();
};
const callback = async (interaction: CommandInteraction): Promise<void> => {
const description = `**Servers:** ${client.guilds.cache.size}\n` + `**Ping:** \`${client.ws.ping * 2}ms\``;
@ -159,7 +157,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
new ButtonBuilder().setCustomId("data").setLabel("Guild data").setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success),
new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger)
)
]
});
@ -201,13 +199,9 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
]
});
} else if (i.customId === "leave") {
if (!await confirm(interaction)) {
if (!(await confirm(interaction))) {
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("No changes were made")
.setStatus("Danger")
],
embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")],
components: []
});
return;
@ -238,13 +232,9 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
files: [attachment]
});
} else if (i.customId === "purge") {
if (!await confirm(interaction)) {
if (!(await confirm(interaction))) {
await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("No changes were made")
.setStatus("Danger")
],
embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")],
components: []
});
return;

@ -1,29 +1,34 @@
import { LoadingEmbed } from "../../utils/defaults.js";
import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, ModalBuilder, TextInputBuilder, TextInputStyle } from "discord.js";
import Discord, {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
CommandInteraction,
ModalBuilder,
TextInputBuilder,
TextInputStyle
} from "discord.js";
import type { SlashCommandSubcommandBuilder } from "discord.js";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import client from "../../utils/client.js";
import config from "../../config/main.js"
import config from "../../config/main.js";
import _ from "lodash";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
.setName("suggest")
.setDescription("Sends a suggestion to the developers")
builder.setName("suggest").setDescription("Sends a suggestion to the developers");
const callback = async (interaction: CommandInteraction): Promise<void> => {
await interaction.guild?.members.fetch(interaction.member!.user.id);
await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
let closed = false;
let suggestionTitle: string | null = null
let suggestionTitle: string | null = null;
let suggestionDesc: string | null = null;
do {
const modal = new ModalBuilder()
.setTitle("Suggestion")
.setComponents(
new ActionRowBuilder<TextInputBuilder>()
.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setLabel("Suggestion Title")
.setRequired(false)
@ -32,8 +37,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
.setPlaceholder("Summarize your suggestion in 1 sentence...")
.setMaxLength(256)
),
new ActionRowBuilder<TextInputBuilder>()
.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setLabel("Suggestion Description")
.setCustomId("suggestionDesc")
@ -41,21 +45,29 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
.setRequired(true)
.setPlaceholder("Put the full details of your suggestion here...")
.setMinLength(50)
),
)
const o: {suggestionDesc?: string, suggestionTitle?: string} = {};
);
const o: { suggestionDesc?: string; suggestionTitle?: string } = {};
if (suggestionTitle) {
o.suggestionTitle = suggestionTitle;
modal.components[0]!.components[0]!.setValue(suggestionTitle);
}
if (suggestionDesc) {
o.suggestionDesc = suggestionDesc
o.suggestionDesc = suggestionDesc;
modal.components[1]!.components[0]!.setValue(suggestionDesc);
};
}
const confirmation = await new confirmationMessage(interaction)
.setEmoji("ICONS.ADD")
.setTitle("Suggest")
.setDescription(suggestionDesc ? (`Are you sure you want to send this suggestion?\n\n**Title ${suggestionTitle ? "" : "(*Placeholder*)"}:**\n> ${suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`}\n\n**Suggestion:**\n> ${suggestionDesc}`) : "Please enter your suggestion below.")
.setDescription(
suggestionDesc
? `Are you sure you want to send this suggestion?\n\n**Title ${
suggestionTitle ? "" : "(*Placeholder*)"
}:**\n> ${
suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`
}\n\n**Suggestion:**\n> ${suggestionDesc}`
: "Please enter your suggestion below."
)
.addModal("Edit Suggestion", "ICONS.EDIT", "editSuggestion", _.cloneDeep(o), modal)
.setColor("Success")
.setInverted(true)
@ -72,7 +84,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
}
if (confirmation.success) {
closed = true;
};
}
} while (!closed);
if (!suggestionDesc) return;
suggestionTitle = suggestionTitle ? suggestionTitle : `${suggestionDesc.substring(0, 70)}`;
@ -82,11 +94,14 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
owner: "ClicksMinutePer",
repo: "Nucleus",
title: suggestionTitle,
body: `Linked Suggestion in Private Developer Channel: [Message](${m.url})\n\n**Suggestion:**\n> ${
suggestionDesc.replaceAll("@", "@<!-- -->").replaceAll("/issues", "/issues<!-- -->").replaceAll("/pull", "/pull<!-- -->")
}\n\n`,
body: `Linked Suggestion in Private Developer Channel: [Message](${
m.url
})\n\n**Suggestion:**\n> ${suggestionDesc
.replaceAll("@", "@<!-- -->")
.replaceAll("/issues", "/issues<!-- -->")
.replaceAll("/pull", "/pull<!-- -->")}\n\n`,
labels: ["🤖 Auto", "📝 Suggestion"]
})
});
await m.edit({
embeds: [
new EmojiEmbed()
@ -101,15 +116,21 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
new ButtonBuilder().setCustomId("accept:Suggestion").setLabel("Accept").setStyle(ButtonStyle.Success),
new ButtonBuilder().setCustomId("deny:Suggestion").setLabel("Deny").setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId("close:Suggestion").setLabel("Close").setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setCustomId("implemented:Suggestion").setLabel("Implemented").setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setLabel(`Open Issue #${issue.data.number}`).setStyle(ButtonStyle.Link).setURL(`https://github.com/ClicksMinutePer/Nucleus/issues/${issue.data.number}`),
new ButtonBuilder()
.setCustomId("implemented:Suggestion")
.setLabel("Implemented")
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setLabel(`Open Issue #${issue.data.number}`)
.setStyle(ButtonStyle.Link)
.setURL(`https://github.com/ClicksMinutePer/Nucleus/issues/${issue.data.number}`)
),
new Discord.ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId("spam:Suggestion").setLabel("Mark as Spam").setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId("spam:Suggestion").setLabel("Mark as Spam").setStyle(ButtonStyle.Danger)
)
]
})
});
await interaction.editReply({
embeds: [
new EmojiEmbed()

@ -45,8 +45,8 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
.setDescription(
"Nucleus scans content sent by users for malware and NSFW content\n" +
'Malware is detected using [ClamAV](https://clamav.net/), and the standard ClamAV database."\n' +
'NSFW detection is provided by [NsfwJS](https://nsfwjs.com/), with a model provided by [GantMan](https://github.com/GantMan/nsfw_model/releases/tag/1.1.0)\n\n' +
'All data is processed on our servers and is not processed by a 3rd party.'
"NSFW detection is provided by [NsfwJS](https://nsfwjs.com/), with a model provided by [GantMan](https://github.com/GantMan/nsfw_model/releases/tag/1.1.0)\n\n" +
"All data is processed on our servers and is not processed by a 3rd party."
)
.setEmoji("NUCLEUS.LOGO")
.setStatus("Danger")

@ -718,7 +718,7 @@ const mentionMenu = async (
.setEmoji("GUILD.SETTINGS.GREEN")
.setFooter({
text: unsavedChanges ? "No changes made" : "Changes not saved"
});;
});
await interaction.editReply({ embeds: [embed], components: [menu, allowedMenu, buttons] });
@ -1047,11 +1047,14 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
let closed = false;
let current = _.cloneDeep(config);
do {
const button = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId("save").setLabel("Save").setStyle(ButtonStyle.Success).setDisabled(_.isEqual(config, current))
new ButtonBuilder()
.setCustomId("save")
.setLabel("Save")
.setStyle(ButtonStyle.Success)
.setDisabled(_.isEqual(config, current))
);
const selectMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()

@ -131,7 +131,7 @@ export default async function (walkthrough = false) {
}
if (walkthrough && !(json["mongoUrl"] ?? false)) json["mongoUrl"] = "mongodb://127.0.0.1:27017";
if (!((json["baseUrl"] as string | undefined) ?? "").endsWith("/")) (json["baseUrl"] as string) += "/";
const localhost = "127.0.0.1"
const localhost = "127.0.0.1";
json["mongoUrl"] = (json["mongoUrl"]! as string).replace("localhost", localhost);
json["baseUrl"] = (json["baseUrl"]! as string).replace("localhost", localhost);
json["mongoOptions"] = {
@ -145,7 +145,7 @@ export default async function (walkthrough = false) {
socket: json["clamAVSocket"] as string | undefined,
host: json["clamAVHost"] as string | undefined,
port: json["clamAVPort"] as number | undefined
}
};
fs.writeFileSync("./src/config/main.ts", "export default " + JSON.stringify(json, null, 4) + ";");

@ -4,7 +4,18 @@ import create from "../actions/tickets/create.js";
import close from "../actions/tickets/delete.js";
import createTranscript from "../premium/createTranscript.js";
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, Interaction, InteractionEditReplyOptions, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } 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";
@ -28,7 +39,10 @@ async function errorMessage(interaction: ButtonInteraction, message: string) {
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
const value =
interaction.customId.startsWith("accept") || interaction.customId.startsWith("implement")
? true
: false;
return await modifySuggestion(interaction, value);
}
switch (interaction.customId) {
@ -88,10 +102,7 @@ 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")
new TextInputBuilder().setStyle(TextInputStyle.Paragraph).setLabel(prompt).setCustomId("typed")
)
)
.setTitle("Reason")
@ -108,53 +119,74 @@ const getReason = async (buttonInteraction: ButtonInteraction, prompt: string) =
}
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 issueNum = embed.footer!.text
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)
))
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.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(
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.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(
components.push(
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId("lock:Suggestion").setLabel("Lock").setStyle(ButtonStyle.Danger)
))
)
);
break;
}
case "implement:Suggestion": {
@ -162,7 +194,7 @@ async function modifySuggestion(interaction: ButtonInteraction, accept: boolean)
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"})
await client.GitHub.rest.issues.lock({ ...issue, lock_reason: "resolved" });
break;
}
case "lock:Suggestion": {
@ -175,7 +207,7 @@ async function modifySuggestion(interaction: ButtonInteraction, accept: boolean)
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"})
await client.GitHub.rest.issues.lock({ ...issue, lock_reason: "spam" });
break;
}
}
@ -189,7 +221,7 @@ async function modifySuggestion(interaction: ButtonInteraction, accept: boolean)
.setDescription(embed!.description!)
.setFields({
name: name + " by",
value: interaction.user.tag,
value: interaction.user.tag
})
.setStatus(newcolor)
.setFooter(embed!.footer);

@ -106,7 +106,13 @@ class confirmationMessage {
this.reason = reason;
return this;
}
addModal(buttonText: string, emoji: string, customId: string, current: Record<string, string>, modal: Discord.ModalBuilder) {
addModal(
buttonText: string,
emoji: string,
customId: string,
current: Record<string, string>,
modal: Discord.ModalBuilder
) {
modal.setCustomId(customId);
this.modals.push({ buttonText, emoji, customId, modal, values: current });
return this;

Loading…
Cancel
Save