blob: 12af0857655c359112332f36a5a1564860ecca1c [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)
pineafan6702cef2022-06-13 17:52:37 +0100106 }
107 }
108 }
109}
110
111const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
112 let member = (interaction.member as Discord.GuildMember)
113 if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the `manage_server` permission to use this command"
114 return true;
115}
116
117export { command };
118export { callback };
119export { check };