blob: 3b81d42872f4961a875760c240ecd7ef429529b6 [file] [log] [blame]
pineafan6702cef2022-06-13 17:52:37 +01001import { ChannelType } from 'discord-api-types';
2import Discord, { CommandInteraction } from "discord.js";
3import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
pineafan4edb7762022-06-26 19:21:04 +01004import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
pineafan6702cef2022-06-13 17:52:37 +01005import { WrappedCheck } from "jshaiku";
6import confirmationMessage from '../../../utils/confirmationMessage.js';
7import keyValueList from '../../../utils/generateKeyValueList.js';
8import client from '../../../utils/client.js';
9
10const command = (builder: SlashCommandSubcommandBuilder) =>
11 builder
12 .setName("ignore")
13 .setDescription("Sets which users, channels and roles should be ignored")
14 .addStringOption(o => o.setName("action").setDescription("Add or remove from the list").addChoices([
15 ["Add", "add"], ["Remove", "remove"]
16 ]).setRequired(true))
17 .addChannelOption(o => o.setName("addchannel").setDescription("Add a channel that should be ignored").addChannelTypes([
18 ChannelType.GuildText, ChannelType.GuildVoice, ChannelType.GuildNews, ChannelType.GuildPublicThread, ChannelType.GuildPrivateThread, ChannelType.GuildNewsThread
19 ]))
20 .addUserOption(o => o.setName("adduser").setDescription("Add a user that should be ignored"))
21 .addRoleOption(o => o.setName("addrole").setDescription("Add a role that should be ignored"))
22
23const callback = async (interaction: CommandInteraction): Promise<any> => {
24 let channel = interaction.options.getChannel("addchannel")
25 let user = interaction.options.getUser("adduser")
26 let role = interaction.options.getRole("addrole")
pineafan4edb7762022-06-26 19:21:04 +010027 await interaction.reply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010028 .setTitle("Loading")
29 .setStatus("Danger")
30 .setEmoji("NUCLEUS.LOADING")
31 ], ephemeral: true, fetchReply: true});
32 if (channel || user || role) {
33 if (channel) {
34 try {
35 channel = interaction.guild.channels.cache.get(channel.id)
36 } catch {
pineafan4edb7762022-06-26 19:21:04 +010037 return await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010038 .setEmoji("CHANNEL.TEXT.DELETE")
39 .setTitle("Logs > Ignore")
40 .setDescription("The channel you provided is not a valid channel")
41 .setStatus("Danger")
42 ]})
43 }
44 channel = channel as Discord.TextChannel
45 if (channel.guild.id != interaction.guild.id) {
pineafan4edb7762022-06-26 19:21:04 +010046 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010047 .setTitle("Logs > Ignore")
48 .setDescription(`You must choose a channel in this server`)
49 .setStatus("Danger")
50 .setEmoji("CHANNEL.TEXT.DELETE")
51 ]});
52 }
53 }
54 if (user) {
55 try {
56 user = interaction.guild.members.cache.get(user.id).user
57 } catch {
pineafan4edb7762022-06-26 19:21:04 +010058 return await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010059 .setEmoji("USER.DELETE")
60 .setTitle("Logs > Ignore")
61 .setDescription("The user you provided is not a valid user")
62 .setStatus("Danger")
63 ]})
64 }
65 user = user as Discord.User
66 }
67 if (role) {
68 try {
69 role = interaction.guild.roles.cache.get(role.id)
70 } catch {
pineafan4edb7762022-06-26 19:21:04 +010071 return await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010072 .setEmoji("ROLE.DELETE")
73 .setTitle("Logs > Ignore")
74 .setDescription("The role you provided is not a valid role")
75 .setStatus("Danger")
76 ]})
77 }
78 role = role as Discord.Role
79 if (role.guild.id != interaction.guild.id) {
pineafan4edb7762022-06-26 19:21:04 +010080 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010081 .setTitle("Logs > Ignore")
82 .setDescription(`You must choose a role in this server`)
83 .setStatus("Danger")
84 .setEmoji("ROLE.DELETE")
85 ]});
86 }
87 }
88 let changes = {}
89 if (channel) changes["channel"] = channel.id
90 if (user) changes["user"] = user.id
91 if (role) changes["role"] = role.id
92 let confirmation = await new confirmationMessage(interaction)
93 .setEmoji("NUCLEUS.COMMANDS.IGNORE")
94 .setTitle("Logs > Ignore")
95 .setDescription(keyValueList(changes)
96 + `Are you sure you want to **${interaction.options.getString("action") == "add" ? "add" : "remove"}** these to the ignore list?`)
97 .setColor("Warning")
98 .send(true)
99 if (confirmation.success) {
pineafan4edb7762022-06-26 19:21:04 +0100100 let data = client.database.guilds.read(interaction.guild.id)
pineafan6702cef2022-06-13 17:52:37 +0100101 if (channel) data.logging.logs.ignore.channels.concat([channel.id])
102 if (user) data.logging.logs.ignore.users.concat([user.id])
103 if (role) data.logging.logs.ignore.roles.concat([role.id])
104 if (interaction.options.getString("action") == "add") {
pineafan4edb7762022-06-26 19:21:04 +0100105 await client.database.guilds.append(interaction.guild.id, data)
pineafanda6e5342022-07-03 10:03:16 +0100106 } else {
107 await client.database.guilds.remove(interaction.guild.id, data)
pineafan6702cef2022-06-13 17:52:37 +0100108 }
pineafanda6e5342022-07-03 10:03:16 +0100109 const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger
110 try {
111 let data = {
112 meta:{
113 type: 'logIgnoreUpdated',
114 displayName: 'Ignored Groups Changed',
115 calculateType: 'nucleusSettingsUpdated',
116 color: NucleusColors.yellow,
117 emoji: "CHANNEL.TEXT.EDIT",
118 timestamp: new Date().getTime()
119 },
120 list: {
121 memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
122 changedBy: entry(interaction.user.id, renderUser(interaction.user)),
123 channel: entry(channel.id, renderChannel(channel)),
124 },
125 hidden: {
126 guild: interaction.guild.id
127 }
128 }
129 log(data);
130 } catch {}
pineafan6702cef2022-06-13 17:52:37 +0100131 }
132 }
133}
134
135const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
136 let member = (interaction.member as Discord.GuildMember)
pineafanda6e5342022-07-03 10:03:16 +0100137 if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the Manage Server permission to use this command"
pineafan6702cef2022-06-13 17:52:37 +0100138 return true;
139}
140
141export { command };
142export { callback };
143export { check };