TheCodedProf | e92b9b5 | 2023-03-06 17:07:34 -0500 | [diff] [blame] | 1 | import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChannelType, CommandInteraction, ComponentType, Guild, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } from "discord.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 2 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 3 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | import client from "../../utils/client.js"; |
TheCodedProf | e92b9b5 | 2023-03-06 17:07:34 -0500 | [diff] [blame] | 5 | import config from "../../config/main.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 6 | |
| 7 | const command = (builder: SlashCommandSubcommandBuilder) => |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 8 | builder.setName("stats").setDescription("Gets the bot's stats"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 9 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 10 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
TheCodedProf | e92b9b5 | 2023-03-06 17:07:34 -0500 | [diff] [blame] | 11 | const description = `**Servers:** ${client.guilds.cache.size}\n` + `**Ping:** \`${client.ws.ping * 2}ms\`` |
| 12 | const m = await interaction.reply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 13 | embeds: [ |
| 14 | new EmojiEmbed() |
| 15 | .setTitle("Stats") |
TheCodedProf | e92b9b5 | 2023-03-06 17:07:34 -0500 | [diff] [blame] | 16 | .setDescription(description) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 17 | .setStatus("Success") |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 18 | .setEmoji("SETTINGS.STATS.GREEN") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 19 | ], |
TheCodedProf | e92b9b5 | 2023-03-06 17:07:34 -0500 | [diff] [blame] | 20 | ephemeral: true, |
| 21 | fetchReply: true |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 22 | }); |
TheCodedProf | e92b9b5 | 2023-03-06 17:07:34 -0500 | [diff] [blame] | 23 | 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") |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame^] | 31 | ], 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 | )] |
TheCodedProf | e92b9b5 | 2023-03-06 17:07:34 -0500 | [diff] [blame] | 35 | }); |
| 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 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 183 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 184 | |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 185 | export { command }; |
| 186 | export { callback }; |