blob: 93978e64637b0c5a4a764a7bf81ccb851fb79cc6 [file] [log] [blame]
import { getCommandMentionByName } from "./../utils/getCommandDataByName.js";
import { LoadingEmbed } from "../utils/defaults.js";
import Discord, {
ActionRowBuilder,
ButtonBuilder,
MessageComponentInteraction,
Guild,
CommandInteraction,
GuildTextBasedChannel,
Message,
ButtonStyle,
ChannelType
} from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import getEmojiByName from "../utils/getEmojiByName.js";
import createPageIndicator from "../utils/createPageIndicator.js";
import { Embed } from "../utils/defaults.js";
export default async (guild: Guild | null, interaction?: CommandInteraction) => {
let m: Message;
if (guild) {
let c: GuildTextBasedChannel | null = guild.publicUpdatesChannel
? guild.publicUpdatesChannel
: guild.systemChannel;
c = c
? c
: (guild.channels.cache.find(
(ch) =>
[
ChannelType.GuildText,
ChannelType.GuildAnnouncement,
ChannelType.PublicThread,
ChannelType.PrivateThread,
ChannelType.AnnouncementThread
].includes(ch.type) &&
ch.permissionsFor(guild.roles.everyone).has("SendMessages") &&
ch.permissionsFor(guild.members.me!).has("EmbedLinks")
) as GuildTextBasedChannel | undefined) ?? null;
if (interaction) c = interaction.channel as GuildTextBasedChannel;
if (!c) {
return;
}
if (interaction) {
m = (await interaction.reply({
embeds: LoadingEmbed,
fetchReply: true,
ephemeral: true
})) as Message;
} else {
m = await c.send({ embeds: LoadingEmbed });
}
} else {
if (interaction) {
m = (await interaction.reply({
embeds: LoadingEmbed,
fetchReply: true,
ephemeral: true
})) as Message;
} else {
return;
}
}
let page = 0;
const pages = [
new Embed()
.setEmbed(
new EmojiEmbed()
.setTitle("Welcome to Nucleus")
.setDescription(
"Thanks for adding Nucleus to your server!\n\n" +
"The next few pages will show what features Nucleus has to offer, and how to enable them.\n\n" +
"If you need support, have questions or want features, you can let us know in [Clicks](https://discord.gg/bPaNnxe)!"
)
.setEmoji("NUCLEUS.LOGO")
.setStatus("Danger")
)
.setTitle("Welcome")
.setDescription("About Nucleus")
.setPageId(0),
new Embed()
.setEmbed(
new EmojiEmbed()
.setTitle("Logs")
.setDescription(
"Nucleus can log server events and keep you informed with what content is being posted to your server.\n" +
"We have 2 different types of logs, which each can be configured to send to a channel of your choice:\n" +
"**General:** These are events like kicks and channel changes etc.\n" +
`> These are standard logs and can be set with ${getCommandMentionByName(
"settings/logs/general"
)}\n` +
"**Warnings:** Warnings like NSFW avatars and spam etc. that may require action by a server staff member.\n" +
`> These may require special action by a moderator. You can set the channel with ${getCommandMentionByName(
"settings/logs/warnings"
)}\n` +
"**Attachments:** All images sent in the server - Used to keep a record of deleted images\n" +
`> Sent to a separate log channel to avoid spam. This can be set with ${getCommandMentionByName(
"settings/logs/attachments"
)}\n` +
`> ${getEmojiByName(
"NUCLEUS.PREMIUM"
)} Please note this feature is only available with ${getCommandMentionByName(
"nucleus/premium"
)}`
)
.setEmoji("ICONS.LOGGING")
.setStatus("Danger")
)
.setTitle("Logging")
.setDescription("Logging, staff warning logs etc.")
.setPageId(1),
new Embed()
.setEmbed(
new EmojiEmbed()
.setTitle("Moderation")
.setDescription(
"Nucleus has a number of commands that can be used to moderate your server.\n" +
`These commands are all found under ${getCommandMentionByName(
"mod"
)}, and they include:\n` +
`${getEmojiByName("PUNISH.WARN.YELLOW")} ${getCommandMentionByName(
"mod/warn"
)}: The user is warned (via DM) that they violated server rules. More options given if DMs are disabled.\n` +
`${getEmojiByName("PUNISH.CLEARHISTORY")} ${getCommandMentionByName(
"mod/purge"
)}: Deletes messages in a channel, giving options to only delete messages by a certain user.\n` +
`${getEmojiByName("PUNISH.MUTE.YELLOW")} ${getCommandMentionByName(
"mod/mute"
)}: Stops users sending messages or joining voice chats.\n` +
`${getEmojiByName("PUNISH.MUTE.GREEN")} ${getCommandMentionByName(
"mod/unmute"
)}: Allows user to send messages and join voice chats.\n` +
`${getEmojiByName("PUNISH.KICK.RED")} ${getCommandMentionByName(
"mod/kick"
)}: Removes a member from the server. They will be able to rejoin.\n` +
`${getEmojiByName("PUNISH.SOFTBAN")} ${getCommandMentionByName(
"mod/softban"
)}: Kicks the user, deleting their messages from every channel in a given time frame.\n` +
`${getEmojiByName("PUNISH.BAN.RED")} ${getCommandMentionByName(
"mod/ban"
)}: Removes the user from the server, deleting messages from every channel and stops them from rejoining.\n` +
`${getEmojiByName("PUNISH.BAN.GREEN")} ${getCommandMentionByName(
"mod/unban"
)}: Allows a member to rejoin the server after being banned.`
)
.setEmoji("PUNISH.BAN.RED")
.setStatus("Danger")
)
.setTitle("Moderation")
.setDescription("Basic moderation commands")
.setPageId(2),
new Embed()
.setEmbed(
new EmojiEmbed()
.setTitle("Verify")
.setDescription(
"Nucleus has a verification system that allows users to prove they aren't bots.\n" +
`This is done by running ${getCommandMentionByName(
"verify"
)} which sends a message only the user can see, giving them a link to a website to verify.\n` +
"After the user complete's the check, they are given a role, which can be set to unlock specific channels.\n" +
`You can set the role given with ${getCommandMentionByName("settings/verify")}`
)
.setEmoji("CONTROL.REDTICK")
.setStatus("Danger")
)
.setTitle("Verify")
.setDescription("Captcha verification system")
.setPageId(3),
new Embed()
.setEmbed(
new EmojiEmbed()
.setTitle("Content Scanning")
.setDescription(
"Nucleus has a content scanning system that automatically scans links and images sent by users.\n" +
"The staff team can be notified when an NSFW image is detected, or malicious links are sent.\n" +
`You can check and manage what to moderate in ${getCommandMentionByName(
"settings/automod"
)}`
)
.setEmoji("MOD.IMAGES.TOOSMALL")
.setStatus("Danger")
)
.setTitle("Content Scanning")
.setDescription("Content (NSFW, malware, scams) scanning")
.setPageId(4),
new Embed()
.setEmbed(
new EmojiEmbed()
.setTitle("Tickets")
.setDescription(
"Nucleus has a ticket system which allows users to create tickets and talk to the server staff or support team.\n" +
`Tickets can be created by users with ${getCommandMentionByName(
"ticket/create"
)}, or by clicking a button created by moderators.\n` +
`After being created, a new channel or thread is created, and the user and support team are pinged. \n` +
`The category or channel to create threads in can be set with ${getCommandMentionByName(
"settings/tickets"
)}\n` +
`When the ticket is resolved, anyone can run ${getCommandMentionByName(
"ticket/close"
)} (or click the button) to close it.\n` +
`Running ${getCommandMentionByName("ticket/close")} again will delete the ticket.`
)
.setEmoji("GUILD.TICKET.CLOSE")
.setStatus("Danger")
)
.setTitle("Tickets")
.setDescription("Ticket system")
.setPageId(5),
new Embed()
.setEmbed(
new EmojiEmbed()
.setTitle("Tags")
.setDescription(
"Nucleus allows you to create tags, which allow a message to be sent when a specific tag is typed.\n" +
`Tags can be created with ${getCommandMentionByName(
"tags/create"
)}, and can be edited with ${getCommandMentionByName("tags/edit")}\n` +
`Tags can be deleted with ${getCommandMentionByName(
"tags/delete"
)}, and can be listed with ${getCommandMentionByName("tags/list")}\n` +
`To use a tag, you can type ${getCommandMentionByName("tag")}, followed by the tag to send`
)
.setEmoji("PUNISH.NICKNAME.RED")
.setStatus("Danger")
)
.setTitle("Tags")
.setDescription("Tag system")
.setPageId(6),
new Embed()
.setEmbed(
new EmojiEmbed()
.setTitle("Premium")
.setDescription(
"Nucleus Premium allows you to use extra features in your server, which are useful but not essential.\n" +
"**No currently free commands will become premium features.**\n" +
"Premium features include creating ticket transcripts and attachment logs.\n\n" +
"Premium can be purchased in [our server](https://discord.gg/bPaNnxe) in the subscriptions page" // TODO: add a table graphic
)
.setEmoji("NUCLEUS.PREMIUM")
.setStatus("Danger")
)
.setTitle("Premium")
.setDescription("Premium features")
.setPageId(7)
];
const publicFilter = async (component: MessageComponentInteraction) => {
return (component.member as Discord.GuildMember).permissions.has("ManageGuild");
};
let selectPaneOpen = false;
let cancelled = false;
let timedOut = false;
while (!cancelled && !timedOut) {
let selectPane: ActionRowBuilder<Discord.StringSelectMenuBuilder | ButtonBuilder>[] = [];
if (selectPaneOpen) {
const options: Discord.StringSelectMenuOptionBuilder[] = [];
pages.forEach((embed) => {
options.push(
new Discord.StringSelectMenuOptionBuilder()
.setLabel(embed.title)
.setValue(embed.pageId.toString())
.setDescription(embed.description || "")
);
});
selectPane = [
new ActionRowBuilder<Discord.StringSelectMenuBuilder>().addComponents([
new Discord.StringSelectMenuBuilder()
.addOptions(options)
.setCustomId("page")
.setMaxValues(1)
.setPlaceholder("Choose a page...")
])
];
}
const components: ActionRowBuilder<ButtonBuilder | Discord.StringSelectMenuBuilder>[] = selectPane.concat([
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("left")
.setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
.setStyle(ButtonStyle.Secondary)
.setDisabled(page === 0),
new ButtonBuilder()
.setCustomId("select")
.setEmoji(getEmojiByName("CONTROL.MENU", "id"))
.setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
.setDisabled(false),
new ButtonBuilder()
.setCustomId("right")
.setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
.setStyle(ButtonStyle.Secondary)
.setDisabled(page === pages.length - 1)
)
]);
if (interaction) {
const em = new Discord.EmbedBuilder(pages[page]!.embed);
em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
await interaction.editReply({
embeds: [em],
components: components
});
} else {
const em = new Discord.EmbedBuilder(pages[page]!.embed);
em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
(await m.edit({
embeds: [em],
components: components
})) as Message;
}
let i;
try {
i = await m.awaitMessageComponent({
filter: interaction
? (i) => {
return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id;
}
: publicFilter,
time: 300000
});
} catch (e) {
timedOut = true;
continue;
}
await i.deferUpdate();
if (!("customId" in i.component)) {
continue;
} else if (i.component.customId === "left") {
if (page > 0) page--;
selectPaneOpen = false;
} else if (i.component.customId === "right") {
if (page < pages.length - 1) page++;
selectPaneOpen = false;
} else if (i.component.customId === "select") {
selectPaneOpen = !selectPaneOpen;
} else if (i.isStringSelectMenu() && i.component.customId === "page") {
page = parseInt(i.values[0]!);
selectPaneOpen = false;
} else {
cancelled = true;
}
}
if (timedOut) {
if (interaction) {
const em = new Discord.EmbedBuilder(pages[page]!.embed);
em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({
text: "Message timed out"
});
await interaction.editReply({
embeds: [em],
components: []
});
} else {
const em = new Discord.EmbedBuilder(pages[page]!.embed);
em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({
text: "Message timed out"
});
await m.edit({
embeds: [em],
components: []
});
}
} else {
if (interaction) {
const em = new Discord.EmbedBuilder(pages[page]!.embed);
em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
em.setFooter({ text: "Message closed" });
await interaction.editReply({
embeds: [em],
components: []
});
} else {
await m.delete();
}
}
};