blob: a7f9b3b69a811e5c71f2bbe94a1d7c121e765bf2 [file] [log] [blame]
pineafan1e462ab2023-03-07 21:34:06 +00001import {
2 ActionRowBuilder,
3 AttachmentBuilder,
4 ButtonBuilder,
5 ButtonInteraction,
6 ButtonStyle,
7 ChannelType,
8 CommandInteraction,
9 ComponentType,
10 Guild,
11 ModalBuilder,
12 ModalSubmitInteraction,
13 TextInputBuilder,
14 TextInputStyle
15} from "discord.js";
TheCodedProff86ba092023-01-27 17:10:07 -050016import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan4edb7762022-06-26 19:21:04 +010017import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
pineafan63fc5e22022-08-04 22:04:10 +010018import client from "../../utils/client.js";
TheCodedProfe92b9b52023-03-06 17:07:34 -050019import config from "../../config/main.js";
pineafan4f164f32022-02-26 22:07:12 +000020
21const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Grey75ea9172022-08-06 10:22:23 +010022 builder.setName("stats").setDescription("Gets the bot's stats");
pineafan4f164f32022-02-26 22:07:12 +000023
pineafanbd02b4a2022-08-05 22:01:38 +010024const callback = async (interaction: CommandInteraction): Promise<void> => {
pineafan1e462ab2023-03-07 21:34:06 +000025 const description = `**Servers:** ${client.guilds.cache.size}\n` + `**Ping:** \`${client.ws.ping * 2}ms\``;
TheCodedProfe92b9b52023-03-06 17:07:34 -050026 const m = await interaction.reply({
Skyler Grey75ea9172022-08-06 10:22:23 +010027 embeds: [
28 new EmojiEmbed()
29 .setTitle("Stats")
TheCodedProfe92b9b52023-03-06 17:07:34 -050030 .setDescription(description)
Skyler Grey75ea9172022-08-06 10:22:23 +010031 .setStatus("Success")
TheCodedProf4a6d5712023-01-19 15:54:40 -050032 .setEmoji("SETTINGS.STATS.GREEN")
Skyler Grey75ea9172022-08-06 10:22:23 +010033 ],
TheCodedProfe92b9b52023-03-06 17:07:34 -050034 ephemeral: true,
35 fetchReply: true
pineafan377794f2022-04-18 19:01:01 +010036 });
TheCodedProfe92b9b52023-03-06 17:07:34 -050037 if (config.owners.includes(interaction.user.id)) {
Skyler Greyf4f21c42023-03-08 14:36:29 +000038 await interaction.editReply({
TheCodedProfe92b9b52023-03-06 17:07:34 -050039 embeds: [
40 new EmojiEmbed()
41 .setTitle("Admin")
42 .setDescription(description)
43 .setStatus("Success")
44 .setEmoji("SETTINGS.STATS.GREEN")
pineafan1e462ab2023-03-07 21:34:06 +000045 ],
46 components: [
47 new ActionRowBuilder<ButtonBuilder>().addComponents(
48 new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary),
49 new ButtonBuilder()
50 .setCustomId("mod:nickname:599498449733550102")
51 .setLabel("Testing")
52 .setStyle(ButtonStyle.Primary)
53 )
54 ]
TheCodedProfe92b9b52023-03-06 17:07:34 -050055 });
56
57 const modal = new ModalBuilder()
58 .addComponents(
pineafan1e462ab2023-03-07 21:34:06 +000059 new ActionRowBuilder<TextInputBuilder>().addComponents(
60 new TextInputBuilder()
61 .setStyle(TextInputStyle.Short)
62 .setLabel("Guild ID")
63 .setCustomId("guildID")
64 .setPlaceholder("Guild ID")
65 .setMinLength(16)
66 .setMaxLength(25)
67 )
TheCodedProfe92b9b52023-03-06 17:07:34 -050068 )
69 .setTitle("Admin Panel")
pineafan1e462ab2023-03-07 21:34:06 +000070 .setCustomId("adminPanel");
TheCodedProfe92b9b52023-03-06 17:07:34 -050071 let i1: ButtonInteraction;
pineafan1e462ab2023-03-07 21:34:06 +000072 const channel = await client.channels.fetch(interaction.channelId);
73 if (
74 !channel ||
75 [ChannelType.GuildCategory, ChannelType.GroupDM, ChannelType.GuildStageVoice].includes(channel.type)
76 )
77 return;
TheCodedProfe92b9b52023-03-06 17:07:34 -050078 // console.log(interaction)
79 if (!("awaitMessageComponent" in channel)) return;
80 try {
81 i1 = await channel!.awaitMessageComponent<ComponentType.Button>({
82 filter: (i) => i.customId === "admin" && i.user.id === interaction.user.id,
83 time: 300000
84 });
pineafan1e462ab2023-03-07 21:34:06 +000085 } catch (e) {
86 console.log(e);
87 return;
88 }
89 await i1.showModal(modal);
TheCodedProfe92b9b52023-03-06 17:07:34 -050090 let out: ModalSubmitInteraction;
91 try {
92 out = await i1.awaitModalSubmit({
93 filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id,
94 time: 300000
pineafan1e462ab2023-03-07 21:34:06 +000095 });
96 } catch {
97 return;
98 }
Skyler Greyf4f21c42023-03-08 14:36:29 +000099 await out.deferUpdate();
TheCodedProfe92b9b52023-03-06 17:07:34 -0500100 const GuildID = out.fields.getTextInputValue("guildID");
101 if (!client.guilds.cache.has(GuildID)) {
102 await interaction.editReply({
pineafan1e462ab2023-03-07 21:34:06 +0000103 embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")],
104 components: []
TheCodedProfe92b9b52023-03-06 17:07:34 -0500105 });
pineafan1e462ab2023-03-07 21:34:06 +0000106 }
TheCodedProfe92b9b52023-03-06 17:07:34 -0500107
108 await interaction.editReply({
109 embeds: [],
110 components: [
111 new ActionRowBuilder<ButtonBuilder>().addComponents(
112 new ButtonBuilder().setCustomId("stats").setLabel("Stats").setStyle(ButtonStyle.Primary),
113 new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger),
114 new ButtonBuilder().setCustomId("data").setLabel("Guild data").setStyle(ButtonStyle.Secondary),
115 new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger),
116 new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success)
117 )
pineafan1e462ab2023-03-07 21:34:06 +0000118 ]
119 });
TheCodedProfe92b9b52023-03-06 17:07:34 -0500120 let i;
121 try {
122 i = await m.awaitMessageComponent<ComponentType.Button>({
123 filter: (i) => i.user.id === interaction.user.id,
124 time: 300000
pineafan1e462ab2023-03-07 21:34:06 +0000125 });
126 } catch {
127 return;
128 }
Skyler Greyf4f21c42023-03-08 14:36:29 +0000129 await i.deferUpdate();
pineafan1e462ab2023-03-07 21:34:06 +0000130 const guild = (await client.guilds.fetch(GuildID)) as Guild | null;
TheCodedProfe92b9b52023-03-06 17:07:34 -0500131 if (!guild) {
132 await interaction.editReply({
pineafan1e462ab2023-03-07 21:34:06 +0000133 embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")],
134 components: []
TheCodedProfe92b9b52023-03-06 17:07:34 -0500135 });
136 return;
137 }
138 if (i.customId === "stats") {
139 await interaction.editReply({
140 embeds: [
141 new EmojiEmbed()
142 .setTitle("Stats")
143 .setDescription(
144 `**Name:** ${guild.name}\n` +
pineafan1e462ab2023-03-07 21:34:06 +0000145 `**ID:** \`${guild.id}\`\n` +
146 `**Owner:** ${client.users.cache.get(guild.ownerId)!.tag}\n` +
147 `**Member Count:** ${guild.memberCount}\n` +
148 `**Created:** <t:${guild.createdTimestamp}:F>\n` +
149 `**Added Nucleus:** <t:${guild.members.me!.joinedTimestamp}:R>\n` +
150 `**Nucleus' Perms:** https://discordapi.com/permissions.html#${guild.members.me!.permissions.valueOf()}\n`
TheCodedProfe92b9b52023-03-06 17:07:34 -0500151 )
152 .setStatus("Success")
153 .setEmoji("SETTINGS.STATS.GREEN")
154 ]
pineafan1e462ab2023-03-07 21:34:06 +0000155 });
TheCodedProfe92b9b52023-03-06 17:07:34 -0500156 } else if (i.customId === "leave") {
157 await guild.leave();
158 await interaction.editReply({
159 embeds: [
160 new EmojiEmbed()
161 .setTitle("Left")
162 .setDescription(`Left ${guild.name}`)
163 .setStatus("Success")
164 .setEmoji("SETTINGS.STATS.GREEN")
pineafan1e462ab2023-03-07 21:34:06 +0000165 ],
166 components: []
167 });
TheCodedProfe92b9b52023-03-06 17:07:34 -0500168 } else if (i.customId === "data") {
169 // Get all the data and convert to a string
170 const data = await client.database.guilds.read(guild.id);
171 const stringified = JSON.stringify(data, null, 2);
172 const buffer = Buffer.from(stringified);
173 const attachment = new AttachmentBuilder(buffer).setName("data.json");
174 await interaction.editReply({
175 embeds: [
176 new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success")
pineafan1e462ab2023-03-07 21:34:06 +0000177 ],
178 components: [],
TheCodedProfe92b9b52023-03-06 17:07:34 -0500179 files: [attachment]
pineafan1e462ab2023-03-07 21:34:06 +0000180 });
TheCodedProfe92b9b52023-03-06 17:07:34 -0500181 } else if (i.customId === "purge") {
182 await client.database.guilds.delete(GuildID);
183 await client.database.history.delete(GuildID);
184 await client.database.notes.delete(GuildID);
185 await client.database.transcripts.deleteAll(GuildID);
186 await interaction.editReply({
187 embeds: [
188 new EmojiEmbed()
189 .setTitle("Purge")
190 .setDescription(`Deleted data for ${guild.name}`)
191 .setStatus("Success")
192 .setEmoji("SETTINGS.STATS.GREEN")
pineafan1e462ab2023-03-07 21:34:06 +0000193 ],
194 components: []
195 });
TheCodedProfe92b9b52023-03-06 17:07:34 -0500196 } else if (i.customId === "cache") {
197 await client.memory.forceUpdate(guild.id);
198 await interaction.editReply({
199 embeds: [
200 new EmojiEmbed()
201 .setTitle("Cache")
202 .setDescription(`Reset cache for ${guild.name}`)
203 .setStatus("Success")
204 .setEmoji("SETTINGS.STATS.GREEN")
pineafan1e462ab2023-03-07 21:34:06 +0000205 ],
206 components: []
207 });
TheCodedProfe92b9b52023-03-06 17:07:34 -0500208 }
209 }
pineafan63fc5e22022-08-04 22:04:10 +0100210};
pineafan4f164f32022-02-26 22:07:12 +0000211
pineafan4f164f32022-02-26 22:07:12 +0000212export { command };
213export { callback };