blob: 1eceae2d6d598b7e9d103bb3f40b616e580dbe64 [file] [log] [blame]
TheCodedProfe92b9b52023-03-06 17:07:34 -05001import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChannelType, CommandInteraction, ComponentType, Guild, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } from "discord.js";
TheCodedProff86ba092023-01-27 17:10:07 -05002import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan4edb7762022-06-26 19:21:04 +01003import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
pineafan63fc5e22022-08-04 22:04:10 +01004import client from "../../utils/client.js";
TheCodedProfe92b9b52023-03-06 17:07:34 -05005import config from "../../config/main.js";
pineafan4f164f32022-02-26 22:07:12 +00006
7const command = (builder: SlashCommandSubcommandBuilder) =>
Skyler Grey75ea9172022-08-06 10:22:23 +01008 builder.setName("stats").setDescription("Gets the bot's stats");
pineafan4f164f32022-02-26 22:07:12 +00009
pineafanbd02b4a2022-08-05 22:01:38 +010010const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProfe92b9b52023-03-06 17:07:34 -050011 const description = `**Servers:** ${client.guilds.cache.size}\n` + `**Ping:** \`${client.ws.ping * 2}ms\``
12 const m = await interaction.reply({
Skyler Grey75ea9172022-08-06 10:22:23 +010013 embeds: [
14 new EmojiEmbed()
15 .setTitle("Stats")
TheCodedProfe92b9b52023-03-06 17:07:34 -050016 .setDescription(description)
Skyler Grey75ea9172022-08-06 10:22:23 +010017 .setStatus("Success")
TheCodedProf4a6d5712023-01-19 15:54:40 -050018 .setEmoji("SETTINGS.STATS.GREEN")
Skyler Grey75ea9172022-08-06 10:22:23 +010019 ],
TheCodedProfe92b9b52023-03-06 17:07:34 -050020 ephemeral: true,
21 fetchReply: true
pineafan377794f2022-04-18 19:01:01 +010022 });
TheCodedProfe92b9b52023-03-06 17:07:34 -050023 if (config.owners.includes(interaction.user.id)) {
24 interaction.editReply({
25 embeds: [
26 new EmojiEmbed()
27 .setTitle("Admin")
28 .setDescription(description)
29 .setStatus("Success")
30 .setEmoji("SETTINGS.STATS.GREEN")
pineafan6de4da52023-03-07 20:43:44 +000031 ], components: [new ActionRowBuilder<ButtonBuilder>().addComponents(
32 new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary),
33 new ButtonBuilder().setCustomId("mod:nickname:599498449733550102").setLabel("Testing").setStyle(ButtonStyle.Primary)
34 )]
TheCodedProfe92b9b52023-03-06 17:07:34 -050035 });
36
37 const modal = new ModalBuilder()
38 .addComponents(
39 new ActionRowBuilder<TextInputBuilder>()
40 .addComponents(
41 new TextInputBuilder()
42 .setStyle(TextInputStyle.Short)
43 .setLabel("Guild ID")
44 .setCustomId("guildID")
45 .setPlaceholder("Guild ID")
46 .setMinLength(16)
47 .setMaxLength(25)
48 )
49 )
50 .setTitle("Admin Panel")
51 .setCustomId("adminPanel")
52 let i1: ButtonInteraction;
53 const channel = await client.channels.fetch(interaction.channelId)
54 if(!channel || [ChannelType.GuildCategory, ChannelType.GroupDM, ChannelType.GuildStageVoice].includes(channel.type)) return;
55 // console.log(interaction)
56 if (!("awaitMessageComponent" in channel)) return;
57 try {
58 i1 = await channel!.awaitMessageComponent<ComponentType.Button>({
59 filter: (i) => i.customId === "admin" && i.user.id === interaction.user.id,
60 time: 300000
61 });
62 } catch (e) { console.log(e); return }
63 await i1.showModal(modal)
64 let out: ModalSubmitInteraction;
65 try {
66 out = await i1.awaitModalSubmit({
67 filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id,
68 time: 300000
69 })
70 } catch { return }
71 out.deferUpdate();
72 const GuildID = out.fields.getTextInputValue("guildID");
73 if (!client.guilds.cache.has(GuildID)) {
74 await interaction.editReply({
75 embeds: [
76 new EmojiEmbed()
77 .setTitle("Admin")
78 .setDescription("Not in server")
79 .setStatus("Danger")
80 ], components: []
81 });
82 };
83
84 await interaction.editReply({
85 embeds: [],
86 components: [
87 new ActionRowBuilder<ButtonBuilder>().addComponents(
88 new ButtonBuilder().setCustomId("stats").setLabel("Stats").setStyle(ButtonStyle.Primary),
89 new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger),
90 new ButtonBuilder().setCustomId("data").setLabel("Guild data").setStyle(ButtonStyle.Secondary),
91 new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger),
92 new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success)
93 )
94 ]});
95 let i;
96 try {
97 i = await m.awaitMessageComponent<ComponentType.Button>({
98 filter: (i) => i.user.id === interaction.user.id,
99 time: 300000
100 })
101 } catch { return }
102 i.deferUpdate();
103 const guild = await client.guilds.fetch(GuildID) as Guild | null;
104 if (!guild) {
105 await interaction.editReply({
106 embeds: [
107 new EmojiEmbed()
108 .setTitle("Admin")
109 .setDescription("Not in server")
110 .setStatus("Danger")
111 ], components: []
112 });
113 return;
114 }
115 if (i.customId === "stats") {
116 await interaction.editReply({
117 embeds: [
118 new EmojiEmbed()
119 .setTitle("Stats")
120 .setDescription(
121 `**Name:** ${guild.name}\n` +
122 `**ID:** \`${guild.id}\`\n` +
123 `**Owner:** ${client.users.cache.get(guild.ownerId)!.tag}\n` +
124 `**Member Count:** ${guild.memberCount}\n` +
125 `**Created:** <t:${guild.createdTimestamp}:F>\n` +
126 `**Added Nucleus:** <t:${guild.members.me!.joinedTimestamp}:R>\n` +
127 `**Nucleus' Perms:** https://discordapi.com/permissions.html#${guild.members.me!.permissions.valueOf()}\n`
128 )
129 .setStatus("Success")
130 .setEmoji("SETTINGS.STATS.GREEN")
131 ]
132 })
133 } else if (i.customId === "leave") {
134 await guild.leave();
135 await interaction.editReply({
136 embeds: [
137 new EmojiEmbed()
138 .setTitle("Left")
139 .setDescription(`Left ${guild.name}`)
140 .setStatus("Success")
141 .setEmoji("SETTINGS.STATS.GREEN")
142 ], components: []
143 })
144 } else if (i.customId === "data") {
145 // Get all the data and convert to a string
146 const data = await client.database.guilds.read(guild.id);
147 const stringified = JSON.stringify(data, null, 2);
148 const buffer = Buffer.from(stringified);
149 const attachment = new AttachmentBuilder(buffer).setName("data.json");
150 await interaction.editReply({
151 embeds: [
152 new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success")
153 ], components: [],
154 files: [attachment]
155 })
156 } else if (i.customId === "purge") {
157 await client.database.guilds.delete(GuildID);
158 await client.database.history.delete(GuildID);
159 await client.database.notes.delete(GuildID);
160 await client.database.transcripts.deleteAll(GuildID);
161 await interaction.editReply({
162 embeds: [
163 new EmojiEmbed()
164 .setTitle("Purge")
165 .setDescription(`Deleted data for ${guild.name}`)
166 .setStatus("Success")
167 .setEmoji("SETTINGS.STATS.GREEN")
168 ], components: []
169 })
170 } else if (i.customId === "cache") {
171 await client.memory.forceUpdate(guild.id);
172 await interaction.editReply({
173 embeds: [
174 new EmojiEmbed()
175 .setTitle("Cache")
176 .setDescription(`Reset cache for ${guild.name}`)
177 .setStatus("Success")
178 .setEmoji("SETTINGS.STATS.GREEN")
179 ], components: []
180 })
181 }
182 }
pineafan63fc5e22022-08-04 22:04:10 +0100183};
pineafan4f164f32022-02-26 22:07:12 +0000184
pineafan4f164f32022-02-26 22:07:12 +0000185export { command };
186export { callback };