From a38cbb3a3ebfa3cb6f5f0e84255ffaedfcf690a0 Mon Sep 17 00:00:00 2001 From: TheCodedProf Date: Sat, 11 Mar 2023 17:22:25 -0500 Subject: [PATCH 1/3] worked on stats, database, ban --- src/commands/mod/ban.ts | 5 +- src/commands/nucleus/stats.ts | 374 +++++++++++++++++++------------ src/config/emojis.json | 402 ---------------------------------- src/utils/database.ts | 5 + src/utils/getEmojiByName.ts | 19 +- 5 files changed, 263 insertions(+), 542 deletions(-) delete mode 100644 src/config/emojis.json diff --git a/src/commands/mod/ban.ts b/src/commands/mod/ban.ts index 41d1252..78f936c 100644 --- a/src/commands/mod/ban.ts +++ b/src/commands/mod/ban.ts @@ -191,7 +191,10 @@ const check = (interaction: CommandInteraction | ButtonInteraction, partial: boo if (!interaction.guild) return; const member = interaction.member as GuildMember; // Check if the user has ban_members permission - if (!member.permissions.has("BanMembers")) return "You do not have the *Ban Members* permission"; + if (!member.permissions.has("BanMembers")) { + // if(!partial) client.logger.warn("Missing permissions", "Ban", "User does not have Ban Members permission"); + return "You do not have the *Ban Members* permission"; + } if (partial) return true; const me = interaction.guild.members.me!; let apply: GuildMember; diff --git a/src/commands/nucleus/stats.ts b/src/commands/nucleus/stats.ts index 9690258..413cedf 100644 --- a/src/commands/nucleus/stats.ts +++ b/src/commands/nucleus/stats.ts @@ -8,6 +8,7 @@ import { CommandInteraction, ComponentType, Guild, + GuildTextBasedChannel, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, @@ -91,7 +92,8 @@ const callback = async (interaction: CommandInteraction): Promise => { ], components: [ new ActionRowBuilder().addComponents( - new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary) + new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary), + new ButtonBuilder().setCustomId("announce").setLabel("Announce to all Guilds").setStyle(ButtonStyle.Danger) ) ] }); @@ -120,152 +122,252 @@ const callback = async (interaction: CommandInteraction): Promise => { // console.log(interaction) if (!("awaitMessageComponent" in channel)) return; let GuildID = interaction.guildId; - if (!GuildID) { - try { - i1 = await channel!.awaitMessageComponent({ - filter: (i) => i.customId === "admin" && i.user.id === interaction.user.id && i.message.id === m.id, - time: 300000 - }); - } catch (e) { - console.log(e); - return; - } - await i1.showModal(modal); - let out: ModalSubmitInteraction; - try { - out = await i1.awaitModalSubmit({ - filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id, - time: 300000 - }); - } catch { - return; - } - await out.deferUpdate(); - GuildID = out.fields.getTextInputValue("guildID"); - } else if (!client.guilds.cache.has(GuildID)) { - await interaction.editReply({ - embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")], - components: [] - }); - } - - await interaction.editReply({ - embeds: [], - components: [ - new ActionRowBuilder().addComponents( - new ButtonBuilder().setCustomId("stats").setLabel("Stats").setStyle(ButtonStyle.Primary), - new ButtonBuilder().setCustomId("data").setLabel("Guild data").setStyle(ButtonStyle.Secondary), - new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success), - new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger), - new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger) - ) - ] - }); - let i; try { - i = await m.awaitMessageComponent({ - filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id, + i1 = await m.awaitMessageComponent({ + filter: (i) => i.user.id === interaction.user.id, time: 300000 }); - } catch { + } catch (e) { + console.log(e); return; } - const guild = (await client.guilds.fetch(GuildID)) as Guild | null; - if (!guild) { - await i.deferUpdate(); - await interaction.editReply({ - embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")], - components: [] - }); - return; - } - if (i.customId === "stats") { - await i.deferUpdate(); - await interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("Stats") - .setDescription( - `**Name:** ${guild.name}\n` + - `**ID:** \`${guild.id}\`\n` + - `**Owner:** ${client.users.cache.get(guild.ownerId)!.tag}\n` + - `**Member Count:** ${guild.memberCount}\n` + - `**Created:** \n` + - `**Added Nucleus:** \n` + - `**Nucleus' Perms:** https://discordapi.com/permissions.html#${guild.members.me!.permissions.valueOf()}\n` - ) - .setStatus("Success") - .setEmoji("SETTINGS.STATS.GREEN") - ] - }); - } else if (i.customId === "leave") { - if (!(await confirm(interaction))) { + switch(i1.customId) { + case "admin": { + if (!GuildID) { + await i1.showModal(modal); + let out: ModalSubmitInteraction; + try { + out = await i1.awaitModalSubmit({ + filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id, + time: 300000 + }); + } catch { + return; + } + await out.deferUpdate(); + GuildID = out.fields.getTextInputValue("guildID"); + } else if (!client.guilds.cache.has(GuildID)) { + await interaction.editReply({ + embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")], + components: [] + }); + } + await interaction.editReply({ - embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")], - components: [] + embeds: [], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder().setCustomId("stats").setLabel("Stats").setStyle(ButtonStyle.Primary), + new ButtonBuilder().setCustomId("data").setLabel("Guild data").setStyle(ButtonStyle.Secondary), + new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success), + new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger), + new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger) + ) + ] }); - return; + let i; + try { + i = await m.awaitMessageComponent({ + filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id, + time: 300000 + }); + } catch { + return; + } + const guild = (await client.guilds.fetch(GuildID)) as Guild | null; + if (!guild) { + await i.deferUpdate(); + await interaction.editReply({ + embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")], + components: [] + }); + return; + } + if (i.customId === "stats") { + await i.deferUpdate(); + await interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Stats") + .setDescription( + `**Name:** ${guild.name}\n` + + `**ID:** \`${guild.id}\`\n` + + `**Owner:** ${client.users.cache.get(guild.ownerId)!.tag}\n` + + `**Member Count:** ${guild.memberCount}\n` + + `**Created:** \n` + + `**Added Nucleus:** \n` + + `**Nucleus' Perms:** https://discordapi.com/permissions.html#${guild.members.me!.permissions.valueOf()}\n` + ) + .setStatus("Success") + .setEmoji("SETTINGS.STATS.GREEN") + ] + }); + } else if (i.customId === "leave") { + if (!(await confirm(interaction))) { + await interaction.editReply({ + embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")], + components: [] + }); + return; + } + await guild.leave(); + await interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Left") + .setDescription(`Left ${guild.name}`) + .setStatus("Success") + .setEmoji("SETTINGS.STATS.GREEN") + ], + components: [] + }); + } else if (i.customId === "data") { + await i.deferUpdate(); + // Get all the data and convert to a string + const data = await client.database.guilds.read(guild.id); + const stringified = JSON.stringify(data, null, 2); + const buffer = Buffer.from(stringified); + const attachment = new AttachmentBuilder(buffer).setName("data.json"); + await interaction.editReply({ + embeds: [ + new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success") + ], + components: [], + files: [attachment] + }); + } else if (i.customId === "purge") { + if (!(await confirm(interaction))) { + await interaction.editReply({ + embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")], + components: [] + }); + return; + } + await client.database.guilds.delete(GuildID); + await client.database.history.delete(GuildID); + await client.database.notes.delete(GuildID); + await client.database.transcripts.deleteAll(GuildID); + await interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Purge") + .setDescription(`Deleted data for ${guild.name}`) + .setStatus("Success") + .setEmoji("SETTINGS.STATS.GREEN") + ], + components: [] + }); + } else if (i.customId === "cache") { + await i.deferUpdate(); + await client.memory.forceUpdate(guild.id); + await interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Cache") + .setDescription(`Reset cache for ${guild.name}`) + .setStatus("Success") + .setEmoji("SETTINGS.STATS.GREEN") + ], + components: [] + }); + } + break; } - await guild.leave(); - await interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("Left") - .setDescription(`Left ${guild.name}`) - .setStatus("Success") - .setEmoji("SETTINGS.STATS.GREEN") - ], - components: [] - }); - } else if (i.customId === "data") { - await i.deferUpdate(); - // Get all the data and convert to a string - const data = await client.database.guilds.read(guild.id); - const stringified = JSON.stringify(data, null, 2); - const buffer = Buffer.from(stringified); - const attachment = new AttachmentBuilder(buffer).setName("data.json"); - await interaction.editReply({ - embeds: [ - new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success") - ], - components: [], - files: [attachment] - }); - } else if (i.customId === "purge") { - if (!(await confirm(interaction))) { + case "announce": { + const channelsToNotify = await client.database.guilds.staffChannels() + const modal2 = new ModalBuilder() + .addComponents( + new ActionRowBuilder().addComponents( + new TextInputBuilder() + .setStyle(TextInputStyle.Paragraph) + .setLabel("Announcement") + .setCustomId("announcement") + .setPlaceholder("Announcement...") + ) + ) + .setTitle("Announcement") + .setCustomId("announce"); + await i1.showModal(modal2); + let out: ModalSubmitInteraction; + try { + out = await i1.awaitModalSubmit({ + filter: (i) => i.customId === "announce" && i.user.id === interaction.user.id, + time: 300000 + }); + } catch { + return; + } + await out.deferUpdate(); + const announcement = out.fields.getTextInputValue("announcement"); await interaction.editReply({ - embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")], - components: [] + embeds: [ + new EmojiEmbed() + .setTitle("Announcement") + .setDescription(`Announcement will be sent to ${channelsToNotify.length} channels.\n\n${announcement}`) + .setStatus("Success") + .setEmoji("SETTINGS.STATS.GREEN") + ], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder().setCustomId("confirm").setLabel("Confirm").setStyle(ButtonStyle.Success), + new ButtonBuilder().setCustomId("cancel").setLabel("Cancel").setStyle(ButtonStyle.Danger) + ) + ] }); - return; + + let i; + try { + i = await m.awaitMessageComponent({ + filter: (i) => i.user.id === interaction.user.id, + time: 300000 + }); + } catch { + return; + } + if (i.customId === "confirm") { + await i.deferUpdate(); + await interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Announcement") + .setDescription(`Sending to ${channelsToNotify.length} channels. Preview:\n\n${announcement}`) + .setStatus("Success") + .setEmoji("SETTINGS.STATS.GREEN") + ], + components: [] + }); + const announcementEmbed = new EmojiEmbed() + .setTitle("Developer Announcement") + .setDescription(announcement) + .setStatus("Danger") + .setEmoji("NUCLEUS.LOGO") + .setFooter({text: `Sent by ${interaction.user.username}`, iconURL: interaction.user.displayAvatarURL()}) + for (const channel of channelsToNotify) { + const ch = await client.channels.fetch(channel) as GuildTextBasedChannel | null; + if (!ch) continue; + await ch.send({ + embeds: [announcementEmbed] + }); + } + await interaction.editReply({ + embeds: [ + new EmojiEmbed() + .setTitle("Announcement") + .setDescription(`Sent to ${channelsToNotify.length} channels. Preview:\n\n${announcement}`) + .setStatus("Success") + .setEmoji("SETTINGS.STATS.GREEN") + ], + components: [] + }) + } else if (i.customId === "cancel") { + await i.deferUpdate(); + await interaction.editReply({ + embeds: [new EmojiEmbed().setTitle("Announcement Cancelled").setStatus("Danger")], + components: [] + }); + } + break; } - await client.database.guilds.delete(GuildID); - await client.database.history.delete(GuildID); - await client.database.notes.delete(GuildID); - await client.database.transcripts.deleteAll(GuildID); - await interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("Purge") - .setDescription(`Deleted data for ${guild.name}`) - .setStatus("Success") - .setEmoji("SETTINGS.STATS.GREEN") - ], - components: [] - }); - } else if (i.customId === "cache") { - await i.deferUpdate(); - await client.memory.forceUpdate(guild.id); - await interaction.editReply({ - embeds: [ - new EmojiEmbed() - .setTitle("Cache") - .setDescription(`Reset cache for ${guild.name}`) - .setStatus("Success") - .setEmoji("SETTINGS.STATS.GREEN") - ], - components: [] - }); } } }; diff --git a/src/config/emojis.json b/src/config/emojis.json deleted file mode 100644 index 585934d..0000000 --- a/src/config/emojis.json +++ /dev/null @@ -1,402 +0,0 @@ -{ - "NUCLEUS": { - "LOGO": "953040840945721385", - "PREMIUMACTIVATE": "a1067536222764925068", - "PREMIUM": "1067928702027042876", - "LOADING": "a946346549271732234", - "INFO": { - "HELP": "751751467014029322", - "ABOUT": "751762088346517504", - "COMMANDS": "751762088229339136", - "SUPPORT": "751762087780286495" - }, - "COMMANDS": { - "RAID": "777143043711172608", - "LOCK": "776848800995868682", - "IGNORE": "777520659270074389" - } - }, - "ICONS": { - "ADD": "826823514904330251", - "REMOVE": "826823515268186152", - "EDIT": "989911820267577366", - "HISTORY": "989911933069168690", - "FILTER": "990242059451514902", - "ATTACHMENT": "997570687193587812", - "LOGGING": "999613304446144562", - "SAVE": "1065722246322200586", - "REORDER": "1069323453909454890", - "PUBLISH": "1081691380004421743", - "NOTIFY": { - "ON": "1000726394579464232", - "OFF": "1078058136092541008" - }, - "OPP": { - "ADD": "837355918831124500", - "REMOVE": "837355918420869162" - }, - "CHANNEL": { - "GUILD_TEXT": "990209996182679632", - "GUILD_TEXT_NSFW": "990216363526221824", - "GUILD_VOICE": "990213162697637969", - "GUILD_VOICE_NSFW": "990216017244463124", - "GUILD_STORE": "853668786925469706", - "GUILD_NEWS": "853668786493063169", - "GUILD_NEWS_NSFW": "990216028300673094", - "GUILD_STAGE_VOICE": "853668786842763294", - "THREAD_CHANNEL": "990210005108158514", - "THREAD_PIPE": "990213168183779348", - "RULES": "990213153080115250", - "FORUM": "1061706437526552716", - "CATEGORY": "1064943289708597348" - }, - "FLAGS": { - "RED": "1082719687219101800", - "YELLOW": "1082719684060794890", - "GREEN": "1082719681326108763", - "BLUE": "1082719679161843734", - "PURPLE": "1082719686292156628", - "GRAY": "1082719682492125337" - } - }, - "CONTROL": { - "TICK": "947441964234702849", - "REDTICK": "999612396727439370", - "CROSS": "947441948543815720", - "BLOCKCROSS": "952261738349330493", - "BLOCKTICK": "991805475777695855", - "LEFT": "947441951148486728", - "RIGHT": "947441957473488916", - "UP": "963409197293273108", - "DOWN": "963409199549796352", - "DOWNLOAD": "947959513032585236", - "TICKET": "973253514488860683", - "MENU": "976580327835320410", - "PILL": { - "TICK": "753314339082993832", - "CROSS": "753314339389309100" - } - }, - "STATUS": { - "ONLINE": "729064530084102166", - "IDLE": "729064531577536582", - "DND": "729064531057311886", - "STREAMING": "729764055082074153", - "OFFLINE": "729064531271221289" - }, - "CHANNEL": { - "TEXT": { - "CREATE": "729066924943737033", - "EDIT": "951957316117360640", - "DELETE": "729064529211686922" - }, - "VOICE": { - "CREATE": "729064530830950530", - "EDIT": "951957316071223336", - "DELETE": "729064530981683200" - }, - "CATEGORY": { - "CREATE": "787987508465238026", - "EDIT": "787987508565770300", - "DELETE": "787987508507967488" - }, - "PURGE": { - "RED": "729064530797133875", - "GREEN": "947443645391441940" - }, - "TITLEUPDATE": "729763053620691044", - "TOPICUPDATE": "729763053477953536", - "SLOWMODE": { - "ON": "973616021304913950", - "OFF": "777138171447869480" - }, - "NSFW": { - "ON": "729064531208175736", - "OFF": "729381430991388752" - } - }, - "MEMBER": { - "JOIN": "729066519337762878", - "LEAVE": "729064531170558575", - "BOT": { - "JOIN": "729064528666689587", - "LEAVE": "729064528998039633" - }, - "KICK": "729263536785850458", - "BAN": "729263536643112991", - "UNBAN": "729263536840114216" - }, - "INVITE": { - "CREATE": "729064529274601482", - "DELETE": "729064531103580230" - }, - "WEBHOOK": { - "CREATE": "752070251906203679", - "UPDATE": "752073772823216191", - "DELETE": "752070251948146768" - }, - "MESSAGE": { - "CREATE": "751762088229339136", - "EDIT": "729065958584614925", - "DELETE": "729064530432360461", - "PIN": "729064530755190894", - "REACTION": { - "ADD": "", - "REMOVE": "", - "CLEAR": "729064531468353606" - }, - "PING": { - "MASS": "729620608408879124", - "EVERYONE": "729064531073957909", - "ROLE": "729263536915742770" - } - }, - "PUNISH": { - "WARN": { - "RED": "947433493384806430", - "YELLOW": "729764054897524768", - "GREEN": "947433504076091424" - }, - "KICK": { - "RED": "729764053794422896", - "YELLOW": "947429333289562132", - "GREEN": "947428786692042764" - }, - "BAN": { - "RED": "729764053861400637", - "YELLOW": "729764053941223476", - "GREEN": "947421674364629022" - }, - "UNBAN": { - "RED": "972511610885255259", - "YELLOW": "972511620343414794", - "GREEN": "729263536840114216" - }, - "MUTE": { - "RED": "947555098974883910", - "YELLOW": "729764053865463840", - "GREEN": "947555107980066866" - }, - "SOFTBAN": "729764053941223476", - "VOICEMUTE": "729764054855450697", - "CLEARHISTORY": "729764062270980096", - "NICKNAME": { - "RED": "959762533101731980", - "YELLOW": "729064531019694090", - "GREEN": "959762533072392202" - } - }, - "BADGES": { - "NUCLEUSDEVELOPER": "957722888360853595", - "CLICKSDEVELOPER": "957722888314683462", - "BOT": "776375959108190239", - "BOOSTER": "775783766131605545", - "HypeSquadOnlineHouse1": "775783765930016789", - "HypeSquadOnlineHouse2": "775783766152577095", - "HypeSquadOnlineHouse3": "775783766303440937", - "Hypesquad": "775783766194126908", - "PremiumEarlySupporter": "775783766055452693", - "BugHunterLevel1": "775783766252847154", - "BugHunterLevel2": "775783766130950234", - "Partner": "775783766178005033", - "Staff": "775783766383788082", - "VerifiedDeveloper": "775783766425600060", - "Quarantined": "1059794708638994474", - "Spammer": "1059794708638994474", - "ActiveDeveloper": "1059795592966053918" - }, - "VOICE": { - "CONNECT": "784785219391193138", - "CHANGE": "784785219353968670", - "LEAVE": "784785219432480808", - "MUTE": "784785219613360149", - "UNMUTE": "784785219441524766", - "DEAFEN": "784785219424747550", - "UNDEAFEN": "784785219324346378", - "STREAM": { - "START": "853519659775819787", - "STOP": "853519660116213780" - }, - "VIDEO": { - "START": "853519659945295873", - "STOP": "853519660116738078" - } - }, - "SETTINGS": { - "STATS": { - "GREEN": "752214059159650396", - "RED": "1065677252630675556" - } - }, - "GUILD": { - "RED": "959779988264079361", - "YELLOW": "729763053352124529", - "GREEN": "959779988503154698", - "EMOJI": { - "CREATE": "953035168115982437", - "EDIT": "729066518549233795", - "DELETE": "953035210121953320" - }, - "SETTINGS": { - "GREEN": "752570111063228507", - "RED": "1068607393728049253" - }, - "ICONCHANGE": "729763053612302356", - "TICKET": { - "OPEN": "853245836331188264", - "CLOSE": "853580122506133505", - "ARCHIVED": "853580122636025856" - }, - "ROLES": { - "CREATE": "729064530763579413", - "DELETE": "729064530885476392", - "EDIT": "776109664793919489", - "MEMBERS": "752570111281594509", - "MESSAGES": "752570111373606942", - "VOICE": "752570111088525354" - } - }, - "MOD": { - "IMAGES": { - "SWEARING": "730438422627614810", - "INVISIBLE": "730438422690398238", - "TOOBIG": "730438422921084998", - "TOOSMALL": "730438422921216150" - }, - "SWEARING": "730438422816096377", - "SPAM": "730438422853845042" - }, - "NUMBERS": [ - { - "NORMAL": "753259024404840529", - "GREEN": "753312608378945648", - "RED": "753312608890650664" - }, - { - "NORMAL": "753259025990418515", - "GREEN": "753312608550912112", - "RED": "753312609075462246" - }, - { - "NORMAL": "753259024409034896", - "GREEN": "753312608513294366", - "RED": "753312608680935446" - }, - { - "NORMAL": "753259024358703205", - "GREEN": "753312608815284426", - "RED": "753312609377320966" - }, - { - "NORMAL": "753259024555835513", - "GREEN": "753312608735461457", - "RED": "753312609255686223" - }, - { - "NORMAL": "753259024744579283", - "GREEN": "753312608630604017", - "RED": "753312609138376777" - }, - { - "NORMAL": "753259024354639994", - "GREEN": "753312608656031806", - "RED": "753312609465270412" - }, - { - "NORMAL": "753259024530800661", - "GREEN": "753312608718815322", - "RED": "753312609104822313" - }, - { - "NORMAL": "753259024895574037", - "GREEN": "753312608790249646", - "RED": "753312609477984319" - }, - { - "NORMAL": "753259024681533553", - "GREEN": "753312608899170365", - "RED": "753312609557545089" - } - ], - "BOTS": { - "GPS": "878919163937185803", - "NUCLEUS": "878919163597439016", - "CLICKSFORMS": "878919163337388073", - "CASTAWAY": "878919164255944726", - "CMPING": "878919164125929502", - "HOOKY": "878919164121731082" - }, - "CFSERVICE": { - "VERIFIED": "881984571242053642", - "UNVERIFIED": "881984571258847232" - }, - "TICKETS": { - "SUPPORT": "952295894370369587", - "REPORT": "952295894437482537", - "QUESTION": "952295894403907645", - "ISSUE": "952295894412316672", - "SUGGESTION": "952295894399725588", - "OTHER": "952295894445883502" - }, - "TRACKS": { - "ICON": "963170616444334171", - "HORIZONTAL": { - "LEFT": { - "ACTIVE": "963121920038035506", - "INACTIVE": "963121944239153242" - }, - "MIDDLE": { - "ACTIVE": "963121925893263420", - "INACTIVE": "963121949796597870" - }, - "RIGHT": { - "ACTIVE": "963121933384302602", - "INACTIVE": "963121956125831168" - } - }, - "VERTICAL": { - "TOP": { - "ACTIVE": "963122664648630293", - "INACTIVE": "963122659862917140", - "GRAY": { - "ACTIVE": "963123505052934144", - "INACTIVE": "963123495221469194" - } - }, - "MIDDLE": { - "ACTIVE": "963122679332880384", - "INACTIVE": "963122673246937199", - "GRAY": { - "ACTIVE": "963123517702955018", - "INACTIVE": "963123511927390329" - } - }, - "BOTTOM": { - "ACTIVE": "963122691752218624", - "INACTIVE": "963122685691453552", - "GRAY": { - "ACTIVE": "963123529988059187", - "INACTIVE": "963123523742748742" - } - } - }, - "SINGLE": { - "ACTIVE": "963361162215424060", - "INACTIVE": "963361431758176316", - "GRAY": { - "ACTIVE": "963361204695334943", - "INACTIVE": "963361200828198952" - } - } - }, - "COLORS": { - "RED": "875822912802803754", - "ORANGE": "875822913104785418", - "YELLOW": "875822913079611402", - "GREEN": "875822913213841418", - "BLUE": "875822912777637889", - "PURPLE": "875822913213841419", - "PINK": "875822913088020541", - "GRAY": "875822913117368340" - } -} diff --git a/src/utils/database.ts b/src/utils/database.ts index 51b2bca..c9b6a8d 100644 --- a/src/utils/database.ts +++ b/src/utils/database.ts @@ -142,6 +142,11 @@ export class Guilds { // console.log("Guild delete") await this.guilds.deleteOne({ id: guild }); } + + async staffChannels(): Promise { + const entries = await this.guilds.find({ "logging.staff.channel": {$exists: true}}, { projection: { "logging.staff.channel": 1, _id: 0 } }).toArray(); + return entries.map(e => e.logging.staff.channel!); + } } interface TranscriptEmbed { diff --git a/src/utils/getEmojiByName.ts b/src/utils/getEmojiByName.ts index 9bbf61f..19b88b4 100644 --- a/src/utils/getEmojiByName.ts +++ b/src/utils/getEmojiByName.ts @@ -1,12 +1,25 @@ -import emojis from "../config/emojis.json" assert { type: "json" }; +import emojis from "../config/emojis.js" import _ from "lodash"; interface EmojisIndex { [key: string]: string | EmojisIndex | EmojisIndex[]; } -function getEmojiByName(name: string | null, format?: string): string { - if (!name) return ""; +const EMOJIPATHS: string[] = []; + +function getEmojiPaths(obj: EmojisIndex, path: string[] = []) { + for (const key in obj) { + if (typeof obj[key] === "string") { + EMOJIPATHS.push([...path, key].join(".")); + } else { + getEmojiPaths(obj[key] as EmojisIndex, [...path, key]); + } + } +} +getEmojiPaths(emojis); + + +function getEmojiByName(name: typeof EMOJIPATHS[number], format?: string): string { const parts = name.split("."); let id: string | EmojisIndex | EmojisIndex[] | undefined = emojis; for (const part of parts) { From 27a0511ef9dfe79c3a4c8bd567893e68cca2b57a Mon Sep 17 00:00:00 2001 From: TheCodedProf Date: Sat, 11 Mar 2023 17:26:17 -0500 Subject: [PATCH 2/3] fixed gitignore --- .gitignore | 2 +- src/config/emojis.ts | 402 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 403 insertions(+), 1 deletion(-) create mode 100644 src/config/emojis.ts diff --git a/.gitignore b/.gitignore index d73f2ea..9eaba59 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ src/config/* !src/config/*.d.ts !src/config/format.ts !src/config/default.ts -!src/config/emojis.json +!src/config/emojis.ts src/utils/migration/data src/config/main.ts .vscode/ diff --git a/src/config/emojis.ts b/src/config/emojis.ts new file mode 100644 index 0000000..b7ed91a --- /dev/null +++ b/src/config/emojis.ts @@ -0,0 +1,402 @@ +export default { + NUCLEUS: { + LOGO: "953040840945721385", + PREMIUMACTIVATE: "a1067536222764925068", + PREMIUM: "1067928702027042876", + LOADING: "a946346549271732234", + INFO: { + HELP: "751751467014029322", + ABOUT: "751762088346517504", + COMMANDS: "751762088229339136", + SUPPORT: "751762087780286495" + }, + COMMANDS: { + RAID: "777143043711172608", + LOCK: "776848800995868682", + IGNORE: "777520659270074389" + } + }, + ICONS: { + ADD: "826823514904330251", + REMOVE: "826823515268186152", + EDIT: "989911820267577366", + HISTORY: "989911933069168690", + FILTER: "990242059451514902", + ATTACHMENT: "997570687193587812", + LOGGING: "999613304446144562", + SAVE: "1065722246322200586", + REORDER: "1069323453909454890", + PUBLISH: "1081691380004421743", + NOTIFY: { + ON: "1000726394579464232", + OFF: "1078058136092541008" + }, + OPP: { + ADD: "837355918831124500", + REMOVE: "837355918420869162" + }, + CHANNEL: { + GUILD_TEXT: "990209996182679632", + GUILD_TEXT_NSFW: "990216363526221824", + GUILD_VOICE: "990213162697637969", + GUILD_VOICE_NSFW: "990216017244463124", + GUILD_STORE: "853668786925469706", + GUILD_NEWS: "853668786493063169", + GUILD_NEWS_NSFW: "990216028300673094", + GUILD_STAGE_VOICE: "853668786842763294", + THREAD_CHANNEL: "990210005108158514", + THREAD_PIPE: "990213168183779348", + RULES: "990213153080115250", + FORUM: "1061706437526552716", + CATEGORY: "1064943289708597348" + }, + FLAGS: { + RED: "1082719687219101800", + YELLOW: "1082719684060794890", + GREEN: "1082719681326108763", + BLUE: "1082719679161843734", + PURPLE: "1082719686292156628", + GRAY: "1082719682492125337" + } + }, + CONTROL: { + TICK: "947441964234702849", + REDTICK: "999612396727439370", + CROSS: "947441948543815720", + BLOCKCROSS: "952261738349330493", + BLOCKTICK: "991805475777695855", + LEFT: "947441951148486728", + RIGHT: "947441957473488916", + UP: "963409197293273108", + DOWN: "963409199549796352", + DOWNLOAD: "947959513032585236", + TICKET: "973253514488860683", + MENU: "976580327835320410", + PILL: { + TICK: "753314339082993832", + CROSS: "753314339389309100" + } + }, + STATUS: { + ONLINE: "729064530084102166", + IDLE: "729064531577536582", + DND: "729064531057311886", + STREAMING: "729764055082074153", + OFFLINE: "729064531271221289" + }, + CHANNEL: { + TEXT: { + CREATE: "729066924943737033", + EDIT: "951957316117360640", + DELETE: "729064529211686922" + }, + VOICE: { + CREATE: "729064530830950530", + EDIT: "951957316071223336", + DELETE: "729064530981683200" + }, + CATEGORY: { + CREATE: "787987508465238026", + EDIT: "787987508565770300", + DELETE: "787987508507967488" + }, + PURGE: { + RED: "729064530797133875", + GREEN: "947443645391441940" + }, + TITLEUPDATE: "729763053620691044", + TOPICUPDATE: "729763053477953536", + SLOWMODE: { + ON: "973616021304913950", + OFF: "777138171447869480" + }, + NSFW: { + ON: "729064531208175736", + OFF: "729381430991388752" + } + }, + MEMBER: { + JOIN: "729066519337762878", + LEAVE: "729064531170558575", + BOT: { + JOIN: "729064528666689587", + LEAVE: "729064528998039633" + }, + KICK: "729263536785850458", + BAN: "729263536643112991", + UNBAN: "729263536840114216" + }, + INVITE: { + CREATE: "729064529274601482", + DELETE: "729064531103580230" + }, + WEBHOOK: { + CREATE: "752070251906203679", + UPDATE: "752073772823216191", + DELETE: "752070251948146768" + }, + MESSAGE: { + CREATE: "751762088229339136", + EDIT: "729065958584614925", + DELETE: "729064530432360461", + PIN: "729064530755190894", + REACTION: { + ADD: "", + REMOVE: "", + CLEAR: "729064531468353606" + }, + PING: { + MASS: "729620608408879124", + EVERYONE: "729064531073957909", + ROLE: "729263536915742770" + } + }, + PUNISH: { + WARN: { + RED: "947433493384806430", + YELLOW: "729764054897524768", + GREEN: "947433504076091424" + }, + KICK: { + RED: "729764053794422896", + YELLOW: "947429333289562132", + GREEN: "947428786692042764" + }, + BAN: { + RED: "729764053861400637", + YELLOW: "729764053941223476", + GREEN: "947421674364629022" + }, + UNBAN: { + RED: "972511610885255259", + YELLOW: "972511620343414794", + GREEN: "729263536840114216" + }, + MUTE: { + RED: "947555098974883910", + YELLOW: "729764053865463840", + GREEN: "947555107980066866" + }, + SOFTBAN: "729764053941223476", + VOICEMUTE: "729764054855450697", + CLEARHISTORY: "729764062270980096", + NICKNAME: { + RED: "959762533101731980", + YELLOW: "729064531019694090", + GREEN: "959762533072392202" + } + }, + BADGES: { + NUCLEUSDEVELOPER: "957722888360853595", + CLICKSDEVELOPER: "957722888314683462", + BOT: "776375959108190239", + BOOSTER: "775783766131605545", + HypeSquadOnlineHouse1: "775783765930016789", + HypeSquadOnlineHouse2: "775783766152577095", + HypeSquadOnlineHouse3: "775783766303440937", + Hypesquad: "775783766194126908", + PremiumEarlySupporter: "775783766055452693", + BugHunterLevel1: "775783766252847154", + BugHunterLevel2: "775783766130950234", + Partner: "775783766178005033", + Staff: "775783766383788082", + VerifiedDeveloper: "775783766425600060", + Quarantined: "1059794708638994474", + Spammer: "1059794708638994474", + ActiveDeveloper: "1059795592966053918" + }, + VOICE: { + CONNECT: "784785219391193138", + CHANGE: "784785219353968670", + LEAVE: "784785219432480808", + MUTE: "784785219613360149", + UNMUTE: "784785219441524766", + DEAFEN: "784785219424747550", + UNDEAFEN: "784785219324346378", + STREAM: { + START: "853519659775819787", + STOP: "853519660116213780" + }, + VIDEO: { + START: "853519659945295873", + STOP: "853519660116738078" + } + }, + SETTINGS: { + STATS: { + GREEN: "752214059159650396", + RED: "1065677252630675556" + } + }, + GUILD: { + RED: "959779988264079361", + YELLOW: "729763053352124529", + GREEN: "959779988503154698", + EMOJI: { + CREATE: "953035168115982437", + EDIT: "729066518549233795", + DELETE: "953035210121953320" + }, + SETTINGS: { + GREEN: "752570111063228507", + RED: "1068607393728049253" + }, + ICONCHANGE: "729763053612302356", + TICKET: { + OPEN: "853245836331188264", + CLOSE: "853580122506133505", + ARCHIVED: "853580122636025856" + }, + ROLES: { + CREATE: "729064530763579413", + DELETE: "729064530885476392", + EDIT: "776109664793919489", + MEMBERS: "752570111281594509", + MESSAGES: "752570111373606942", + VOICE: "752570111088525354" + } + }, + MOD: { + IMAGES: { + SWEARING: "730438422627614810", + INVISIBLE: "730438422690398238", + TOOBIG: "730438422921084998", + TOOSMALL: "730438422921216150" + }, + SWEARING: "730438422816096377", + SPAM: "730438422853845042" + }, + NUMBERS: [ + { + NORMAL: "753259024404840529", + GREEN: "753312608378945648", + RED: "753312608890650664" + }, + { + NORMAL: "753259025990418515", + GREEN: "753312608550912112", + RED: "753312609075462246" + }, + { + NORMAL: "753259024409034896", + GREEN: "753312608513294366", + RED: "753312608680935446" + }, + { + NORMAL: "753259024358703205", + GREEN: "753312608815284426", + RED: "753312609377320966" + }, + { + NORMAL: "753259024555835513", + GREEN: "753312608735461457", + RED: "753312609255686223" + }, + { + NORMAL: "753259024744579283", + GREEN: "753312608630604017", + RED: "753312609138376777" + }, + { + NORMAL: "753259024354639994", + GREEN: "753312608656031806", + RED: "753312609465270412" + }, + { + NORMAL: "753259024530800661", + GREEN: "753312608718815322", + RED: "753312609104822313" + }, + { + NORMAL: "753259024895574037", + GREEN: "753312608790249646", + RED: "753312609477984319" + }, + { + NORMAL: "753259024681533553", + GREEN: "753312608899170365", + RED: "753312609557545089" + } + ], + BOTS: { + GPS: "878919163937185803", + NUCLEUS: "878919163597439016", + CLICKSFORMS: "878919163337388073", + CASTAWAY: "878919164255944726", + CMPING: "878919164125929502", + HOOKY: "878919164121731082" + }, + CFSERVICE: { + VERIFIED: "881984571242053642", + UNVERIFIED: "881984571258847232" + }, + TICKETS: { + SUPPORT: "952295894370369587", + REPORT: "952295894437482537", + QUESTION: "952295894403907645", + ISSUE: "952295894412316672", + SUGGESTION: "952295894399725588", + OTHER: "952295894445883502" + }, + TRACKS: { + ICON: "963170616444334171", + HORIZONTAL: { + LEFT: { + ACTIVE: "963121920038035506", + INACTIVE: "963121944239153242" + }, + MIDDLE: { + ACTIVE: "963121925893263420", + INACTIVE: "963121949796597870" + }, + RIGHT: { + ACTIVE: "963121933384302602", + INACTIVE: "963121956125831168" + } + }, + VERTICAL: { + TOP: { + ACTIVE: "963122664648630293", + INACTIVE: "963122659862917140", + GRAY: { + ACTIVE: "963123505052934144", + INACTIVE: "963123495221469194" + } + }, + MIDDLE: { + ACTIVE: "963122679332880384", + INACTIVE: "963122673246937199", + GRAY: { + ACTIVE: "963123517702955018", + INACTIVE: "963123511927390329" + } + }, + BOTTOM: { + ACTIVE: "963122691752218624", + INACTIVE: "963122685691453552", + GRAY: { + ACTIVE: "963123529988059187", + INACTIVE: "963123523742748742" + } + } + }, + SINGLE: { + ACTIVE: "963361162215424060", + INACTIVE: "963361431758176316", + GRAY: { + ACTIVE: "963361204695334943", + INACTIVE: "963361200828198952" + } + } + }, + COLORS: { + RED: "875822912802803754", + ORANGE: "875822913104785418", + YELLOW: "875822913079611402", + GREEN: "875822913213841418", + BLUE: "875822912777637889", + PURPLE: "875822913213841419", + PINK: "875822913088020541", + GRAY: "875822913117368340" + } +} From 528de570df48ae5cbb03feb26b6eeac595d341c0 Mon Sep 17 00:00:00 2001 From: TheCodedProf Date: Sat, 11 Mar 2023 17:28:29 -0500 Subject: [PATCH 3/3] prettiered --- src/commands/nucleus/stats.ts | 63 ++++++++++++++++++++++++++--------- src/utils/database.ts | 9 +++-- src/utils/getEmojiByName.ts | 5 ++- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/commands/nucleus/stats.ts b/src/commands/nucleus/stats.ts index 413cedf..1cbcee8 100644 --- a/src/commands/nucleus/stats.ts +++ b/src/commands/nucleus/stats.ts @@ -93,7 +93,10 @@ const callback = async (interaction: CommandInteraction): Promise => { components: [ new ActionRowBuilder().addComponents( new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary), - new ButtonBuilder().setCustomId("announce").setLabel("Announce to all Guilds").setStyle(ButtonStyle.Danger) + new ButtonBuilder() + .setCustomId("announce") + .setLabel("Announce to all Guilds") + .setStyle(ButtonStyle.Danger) ) ] }); @@ -131,7 +134,7 @@ const callback = async (interaction: CommandInteraction): Promise => { console.log(e); return; } - switch(i1.customId) { + switch (i1.customId) { case "admin": { if (!GuildID) { await i1.showModal(modal); @@ -148,7 +151,9 @@ const callback = async (interaction: CommandInteraction): Promise => { GuildID = out.fields.getTextInputValue("guildID"); } else if (!client.guilds.cache.has(GuildID)) { await interaction.editReply({ - embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")], + embeds: [ + new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger") + ], components: [] }); } @@ -158,10 +163,19 @@ const callback = async (interaction: CommandInteraction): Promise => { components: [ new ActionRowBuilder().addComponents( new ButtonBuilder().setCustomId("stats").setLabel("Stats").setStyle(ButtonStyle.Primary), - new ButtonBuilder().setCustomId("data").setLabel("Guild data").setStyle(ButtonStyle.Secondary), - new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success), + new ButtonBuilder() + .setCustomId("data") + .setLabel("Guild data") + .setStyle(ButtonStyle.Secondary), + new ButtonBuilder() + .setCustomId("cache") + .setLabel("Reset cache") + .setStyle(ButtonStyle.Success), new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger), - new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger) + new ButtonBuilder() + .setCustomId("purge") + .setLabel("Delete data") + .setStyle(ButtonStyle.Danger) ) ] }); @@ -178,7 +192,9 @@ const callback = async (interaction: CommandInteraction): Promise => { if (!guild) { await i.deferUpdate(); await interaction.editReply({ - embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")], + embeds: [ + new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger") + ], components: [] }); return; @@ -230,7 +246,10 @@ const callback = async (interaction: CommandInteraction): Promise => { const attachment = new AttachmentBuilder(buffer).setName("data.json"); await interaction.editReply({ embeds: [ - new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success") + new EmojiEmbed() + .setTitle("Data") + .setDescription(`Data for ${guild.name}`) + .setStatus("Success") ], components: [], files: [attachment] @@ -274,7 +293,7 @@ const callback = async (interaction: CommandInteraction): Promise => { break; } case "announce": { - const channelsToNotify = await client.database.guilds.staffChannels() + const channelsToNotify = await client.database.guilds.staffChannels(); const modal2 = new ModalBuilder() .addComponents( new ActionRowBuilder().addComponents( @@ -303,13 +322,18 @@ const callback = async (interaction: CommandInteraction): Promise => { embeds: [ new EmojiEmbed() .setTitle("Announcement") - .setDescription(`Announcement will be sent to ${channelsToNotify.length} channels.\n\n${announcement}`) + .setDescription( + `Announcement will be sent to ${channelsToNotify.length} channels.\n\n${announcement}` + ) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") ], components: [ new ActionRowBuilder().addComponents( - new ButtonBuilder().setCustomId("confirm").setLabel("Confirm").setStyle(ButtonStyle.Success), + new ButtonBuilder() + .setCustomId("confirm") + .setLabel("Confirm") + .setStyle(ButtonStyle.Success), new ButtonBuilder().setCustomId("cancel").setLabel("Cancel").setStyle(ButtonStyle.Danger) ) ] @@ -330,7 +354,9 @@ const callback = async (interaction: CommandInteraction): Promise => { embeds: [ new EmojiEmbed() .setTitle("Announcement") - .setDescription(`Sending to ${channelsToNotify.length} channels. Preview:\n\n${announcement}`) + .setDescription( + `Sending to ${channelsToNotify.length} channels. Preview:\n\n${announcement}` + ) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") ], @@ -341,9 +367,12 @@ const callback = async (interaction: CommandInteraction): Promise => { .setDescription(announcement) .setStatus("Danger") .setEmoji("NUCLEUS.LOGO") - .setFooter({text: `Sent by ${interaction.user.username}`, iconURL: interaction.user.displayAvatarURL()}) + .setFooter({ + text: `Sent by ${interaction.user.username}`, + iconURL: interaction.user.displayAvatarURL() + }); for (const channel of channelsToNotify) { - const ch = await client.channels.fetch(channel) as GuildTextBasedChannel | null; + const ch = (await client.channels.fetch(channel)) as GuildTextBasedChannel | null; if (!ch) continue; await ch.send({ embeds: [announcementEmbed] @@ -353,12 +382,14 @@ const callback = async (interaction: CommandInteraction): Promise => { embeds: [ new EmojiEmbed() .setTitle("Announcement") - .setDescription(`Sent to ${channelsToNotify.length} channels. Preview:\n\n${announcement}`) + .setDescription( + `Sent to ${channelsToNotify.length} channels. Preview:\n\n${announcement}` + ) .setStatus("Success") .setEmoji("SETTINGS.STATS.GREEN") ], components: [] - }) + }); } else if (i.customId === "cancel") { await i.deferUpdate(); await interaction.editReply({ diff --git a/src/utils/database.ts b/src/utils/database.ts index c9b6a8d..5386f7f 100644 --- a/src/utils/database.ts +++ b/src/utils/database.ts @@ -144,8 +144,13 @@ export class Guilds { } async staffChannels(): Promise { - const entries = await this.guilds.find({ "logging.staff.channel": {$exists: true}}, { projection: { "logging.staff.channel": 1, _id: 0 } }).toArray(); - return entries.map(e => e.logging.staff.channel!); + const entries = await this.guilds + .find( + { "logging.staff.channel": { $exists: true } }, + { projection: { "logging.staff.channel": 1, _id: 0 } } + ) + .toArray(); + return entries.map((e) => e.logging.staff.channel!); } } diff --git a/src/utils/getEmojiByName.ts b/src/utils/getEmojiByName.ts index 19b88b4..ebcb257 100644 --- a/src/utils/getEmojiByName.ts +++ b/src/utils/getEmojiByName.ts @@ -1,4 +1,4 @@ -import emojis from "../config/emojis.js" +import emojis from "../config/emojis.js"; import _ from "lodash"; interface EmojisIndex { @@ -18,8 +18,7 @@ function getEmojiPaths(obj: EmojisIndex, path: string[] = []) { } getEmojiPaths(emojis); - -function getEmojiByName(name: typeof EMOJIPATHS[number], format?: string): string { +function getEmojiByName(name: (typeof EMOJIPATHS)[number], format?: string): string { const parts = name.split("."); let id: string | EmojisIndex | EmojisIndex[] | undefined = emojis; for (const part of parts) {