blob: e0d27764529c6d6d7a569ac11a63391a0f6dbba9 [file] [log] [blame]
pineafan6702cef2022-06-13 17:52:37 +01001import { ChannelType } from 'discord-api-types';
2import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
pineafanda6e5342022-07-03 10:03:16 +01003import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
4import confirmationMessage from "../../utils/confirmationMessage.js";
5import getEmojiByName from "../../utils/getEmojiByName.js";
pineafan6702cef2022-06-13 17:52:37 +01006import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
7import { WrappedCheck } from "jshaiku";
pineafanda6e5342022-07-03 10:03:16 +01008import client from "../../utils/client.js";
pineafan6702cef2022-06-13 17:52:37 +01009
10const command = (builder: SlashCommandSubcommandBuilder) =>
11 builder
pineafanda6e5342022-07-03 10:03:16 +010012 .setName("staff")
13 .setDescription("Settings for the staff notifications channel")
pineafan6702cef2022-06-13 17:52:37 +010014 .addChannelOption(option => option.setName("channel").setDescription("The channel to set the staff notifications channel to").addChannelTypes([
15 ChannelType.GuildNews, ChannelType.GuildText
pineafanda6e5342022-07-03 10:03:16 +010016 ]).setRequired(false))
pineafan6702cef2022-06-13 17:52:37 +010017
18const callback = async (interaction: CommandInteraction): Promise<any> => {
19 let m;
pineafan4edb7762022-06-26 19:21:04 +010020 m = await interaction.reply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010021 .setTitle("Loading")
22 .setStatus("Danger")
23 .setEmoji("NUCLEUS.LOADING")
24 ], ephemeral: true, fetchReply: true});
25 if (interaction.options.getChannel("channel")) {
26 let channel
27 try {
28 channel = interaction.options.getChannel("channel")
29 } catch {
pineafan4edb7762022-06-26 19:21:04 +010030 return await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010031 .setEmoji("CHANNEL.TEXT.DELETE")
32 .setTitle("Staff Notifications Channel")
33 .setDescription("The channel you provided is not a valid channel")
34 .setStatus("Danger")
35 ]})
36 }
37 channel = channel as Discord.TextChannel
38 if (channel.guild.id != interaction.guild.id) {
pineafan4edb7762022-06-26 19:21:04 +010039 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010040 .setTitle("Staff Notifications Channel")
41 .setDescription(`You must choose a channel in this server`)
42 .setStatus("Danger")
43 .setEmoji("CHANNEL.TEXT.DELETE")
44 ]});
45 }
46 let confirmation = await new confirmationMessage(interaction)
47 .setEmoji("CHANNEL.TEXT.EDIT")
48 .setTitle("Staff Notifications Channel")
49 .setDescription(
50 `This will be the channel all notifications, updates, user reports etc. will be sent to.\n\n` +
51 `Are you sure you want to set the staff notifications channel to <#${channel.id}>?`
52 )
53 .setColor("Warning")
54 .setInverted(true)
55 .send(true)
56 if (confirmation.success) {
57 try {
pineafan4edb7762022-06-26 19:21:04 +010058 await client.database.guilds.write(interaction.guild.id, {"logging.staff.channel": channel.id})
pineafanda6e5342022-07-03 10:03:16 +010059 const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger
60 try {
61 let data = {
62 meta:{
63 type: 'logIgnoreUpdated',
64 displayName: 'Staff Notifications Channel Updated',
65 calculateType: 'nucleusSettingsUpdated',
66 color: NucleusColors.yellow,
67 emoji: "CHANNEL.TEXT.EDIT",
68 timestamp: new Date().getTime()
69 },
70 list: {
71 memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
72 changedBy: entry(interaction.user.id, renderUser(interaction.user)),
73 channel: entry(channel.id, renderChannel(channel)),
74 },
75 hidden: {
76 guild: interaction.guild.id
77 }
78 }
79 log(data);
80 } catch {}
pineafan6702cef2022-06-13 17:52:37 +010081 } catch (e) {
pineafan4edb7762022-06-26 19:21:04 +010082 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010083 .setTitle("Staff Notifications Channel")
84 .setDescription(`Something went wrong and the staff notifications channel could not be set`)
85 .setStatus("Danger")
86 .setEmoji("CHANNEL.TEXT.DELETE")
87 ], components: []});
88 }
89 } else {
pineafan4edb7762022-06-26 19:21:04 +010090 return interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +010091 .setTitle("Staff Notifications Channel")
92 .setDescription(`No changes were made`)
93 .setStatus("Success")
94 .setEmoji("CHANNEL.TEXT.CREATE")
95 ], components: []});
96 }
97 }
98 let clicks = 0;
pineafan4edb7762022-06-26 19:21:04 +010099 let data = await client.database.guilds.read(interaction.guild.id);
pineafan6702cef2022-06-13 17:52:37 +0100100 let channel = data.logging.staff.channel;
101 while (true) {
pineafan4edb7762022-06-26 19:21:04 +0100102 await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +0100103 .setTitle("Staff Notifications channel")
104 .setDescription(channel ? `Your staff notifications channel is currently set to <#${channel}>` : "This server does not have a staff notifications channel")
105 .setStatus("Success")
106 .setEmoji("CHANNEL.TEXT.CREATE")
107 ], components: [new MessageActionRow().addComponents([new MessageButton()
108 .setCustomId("clear")
109 .setLabel(clicks ? "Click again to confirm" : "Reset channel")
110 .setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id"))
111 .setStyle("DANGER")
112 .setDisabled(!channel)
113 ])]});
114 let i;
115 try {
pineafanc6158ab2022-06-17 16:34:07 +0100116 i = await m.awaitMessageComponent({time: 300000});
pineafan6702cef2022-06-13 17:52:37 +0100117 } catch(e) { break }
118 i.deferUpdate()
119 if (i.component.customId == "clear") {
120 clicks += 1;
121 if (clicks == 2) {
122 clicks = 0;
pineafan4edb7762022-06-26 19:21:04 +0100123 await client.database.guilds.write(interaction.guild.id, {}, ["logging.staff.channel"])
pineafan6702cef2022-06-13 17:52:37 +0100124 channel = undefined;
125 }
126 } else {
127 break
128 }
129 }
pineafan4edb7762022-06-26 19:21:04 +0100130 await interaction.editReply({embeds: [new EmojiEmbed()
pineafan6702cef2022-06-13 17:52:37 +0100131 .setTitle("Staff Notifications channel")
132 .setDescription(channel ? `Your staff notifications channel is currently set to <#${channel}>` : "This server does not have a staff notifications channel")
133 .setStatus("Success")
134 .setEmoji("CHANNEL.TEXT.CREATE")
135 .setFooter({text: "Message closed"})
136 ], components: [new MessageActionRow().addComponents([new MessageButton()
137 .setCustomId("clear")
138 .setLabel("Clear")
139 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
140 .setStyle("SECONDARY")
141 .setDisabled(true)
142 ])]});
143}
144
145const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
146 let member = (interaction.member as Discord.GuildMember)
pineafanda6e5342022-07-03 10:03:16 +0100147 if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the Manage Server permission to use this command"
pineafan6702cef2022-06-13 17:52:37 +0100148 return true;
149}
150
151export { command };
152export { callback };
153export { check };