From 3ff4f98abd5185f5af1cedd3dbb0aeef7e8b0766 Mon Sep 17 00:00:00 2001 From: William Harrison Date: Sun, 9 Jul 2023 09:19:33 +0800 Subject: [PATCH] feat: various updates - Move statistics back into `/bot` - Remove credits - Update `/bot` buttons - Remove `/vote`, moved to `/bot` - Update to-do list buttons - Make `/admin` ephemeral - Make get role commands ephemeral - Fix `guildDelete` event - Remove `axios` dependency - Remove `moment` dependency - Update context menu commands JSON - Rename to-do list button IDs --- package-lock.json | 62 ---------------------- package.json | 2 - src/buttons/info/credits.js | 20 ------- src/buttons/info/statistics.js | 48 ----------------- src/buttons/to-do-list/add.js | 2 +- src/buttons/to-do-list/get.js | 2 +- src/buttons/to-do-list/refresh.js | 2 +- src/buttons/to-do-list/remove.js | 2 +- src/commands/dev/admin.js | 26 ++++----- src/commands/info/bot.js | 58 +++++++++++++------- src/commands/info/developers.js | 2 +- src/commands/info/moderators.js | 2 +- src/commands/info/supporters.js | 2 +- src/commands/info/vote.js | 29 ---------- src/context-menu/message/Delete Message.js | 1 - src/context-menu/message/Message Info.js | 1 - src/context-menu/message/Report Message.js | 1 - src/context-menu/user/User Info.js | 1 - src/events/guild/guildDelete.js | 3 +- 19 files changed, 60 insertions(+), 206 deletions(-) delete mode 100644 src/buttons/info/credits.js delete mode 100644 src/buttons/info/statistics.js delete mode 100644 src/commands/info/vote.js diff --git a/package-lock.json b/package-lock.json index b91215e..6cd484b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,13 +10,11 @@ "license": "MIT", "dependencies": { "@sentry/node": "^7.53.1", - "axios": "^1.4.0", "body-parser": "^1.20.2", "cors": "^2.8.5", "discord.js": "^14.11.0", "dotenv": "^16.3.1", "express": "^4.18.2", - "moment": "^2.29.4", "mongoose": "^6.11.2", "node-fetch": "^2.6.9", "stop-discord-phishing": "^0.3.3" @@ -1405,21 +1403,6 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, - "node_modules/axios": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", - "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -1546,17 +1529,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -1617,14 +1589,6 @@ } } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -1899,19 +1863,6 @@ } } }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -2135,14 +2086,6 @@ "node": ">= 0.6" } }, - "node_modules/moment": { - "version": "2.29.4", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", - "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", - "engines": { - "node": "*" - } - }, "node_modules/mongodb": { "version": "4.16.0", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.16.0.tgz", @@ -2329,11 +2272,6 @@ "node": ">= 0.10" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - }, "node_modules/punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", diff --git a/package.json b/package.json index 70f2ce3..7ef1c33 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,11 @@ "license": "MIT", "dependencies": { "@sentry/node": "^7.53.1", - "axios": "^1.4.0", "body-parser": "^1.20.2", "cors": "^2.8.5", "discord.js": "^14.11.0", "dotenv": "^16.3.1", "express": "^4.18.2", - "moment": "^2.29.4", "mongoose": "^6.11.2", "node-fetch": "^2.6.9", "stop-discord-phishing": "^0.3.3" diff --git a/src/buttons/info/credits.js b/src/buttons/info/credits.js deleted file mode 100644 index fc0998b..0000000 --- a/src/buttons/info/credits.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = { - name: "credits", - startsWith: false, - requiredRoles: [], - async execute(interaction, client, Discord) { - try { - const credits = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) - .addFields ( - { name: "💻 Developer", value: "[@william.harrison](https://discord.com/users/853158265466257448)" }, - { name: "🪝 Webhook System", value: "[@andrewstech](https://discord.com/users/598245488977903688)" }, - { name: "💡 Bot Inspiration", value: "[@sx9dev](https://discord.com/users/882595027132493864)" } - ) - - await interaction.reply({ embeds: [credits], ephemeral: true }); - } catch(err) { - client.logButtonError(err, interaction, Discord); - } - } -} diff --git a/src/buttons/info/statistics.js b/src/buttons/info/statistics.js deleted file mode 100644 index e31d3af..0000000 --- a/src/buttons/info/statistics.js +++ /dev/null @@ -1,48 +0,0 @@ -const devSchema = require("../../models/devSchema"); -const messageSchema = require("../../models/messageSchema"); -const modSchema = require("../../models/modSchema"); -const verifiedSchema = require("../../models/verifiedSchema"); - -module.exports = { - name: "statistics", - startsWith: false, - requiredRoles: [], - async execute(interaction, client, Discord) { - try { - await interaction.deferReply({ ephemeral: true }); - - const developers = await devSchema.find(); - const moderators = await modSchema.find(); - const verifiedUsers = await verifiedSchema.find(); - const messages = await messageSchema.find(); - const images = await messageSchema.find({ attachment: { $ne: null } }); - - const guild = await client.guilds.fetch(client.config_default.guild); - const members = await guild.members.fetch(); - const boosters = members.filter(member => member.premiumSinceTimestamp); - - const stat_guilds = `🗄️ ${client.guilds.cache.size} Guild${client.guilds.cache.size === 1 ? "" : "s"}`; - const stat_users = `👤 ${client.users.cache.size} User${client.users.cache.size === 1 ? "" : "s"}`; - - const stat_developers = `💻 ${developers.length} Developer${developers.length === 1 ? "" : "s"}`; - const stat_moderators = `🔨 ${moderators.length} Moderator${moderators.length === 1 ? "" : "s"}`; - const stat_verified = `✅ ${verifiedUsers.length} Verified User${verifiedUsers.length === 1 ? "" : "s"}`; - const stat_supporters = `💖 ${boosters.size} Supporter${boosters.size === 1 ? "" : "s"}`; - - const stat_messages = `💬 ${messages.length} Message${messages.length === 1 ? "" : "s"}`; - const stat_images = `🖼️ ${images.length} Image${images.length === 1 ? "" : "s"}`; - - const statistics = new Discord.EmbedBuilder() - .setColor(client.config_embeds.default) - .addFields ( - { name: "🤖 Bot", value: `${stat_guilds}\n${stat_users}` }, - { name: "🎭 Roles", value: `${stat_developers}\n${stat_moderators}\n${stat_verified}\n${stat_supporters}` }, - { name: "🌐 Global Chat", value: `${stat_messages}\n${stat_images}` } - ) - - await interaction.editReply({ embeds: [statistics] }); - } catch(err) { - client.logButtonError(err, interaction, Discord); - } - } -} diff --git a/src/buttons/to-do-list/add.js b/src/buttons/to-do-list/add.js index 0849690..235e53e 100644 --- a/src/buttons/to-do-list/add.js +++ b/src/buttons/to-do-list/add.js @@ -3,7 +3,7 @@ const emoji = require("../../config.json").emojis; const todoSchema = require("../../models/todoSchema"); module.exports = { - name: "add-todo", + name: "add-task", startsWith: false, requiredRoles: ["dev"], async execute(interaction, client, Discord) { diff --git a/src/buttons/to-do-list/get.js b/src/buttons/to-do-list/get.js index 2c0b075..1949957 100644 --- a/src/buttons/to-do-list/get.js +++ b/src/buttons/to-do-list/get.js @@ -3,7 +3,7 @@ const emoji = require("../../config.json").emojis; const todoSchema = require("../../models/todoSchema"); module.exports = { - name: "get-todo", + name: "get-task", startsWith: false, requiredRoles: [], async execute(interaction, client, Discord) { diff --git a/src/buttons/to-do-list/refresh.js b/src/buttons/to-do-list/refresh.js index e964f0b..c635ca9 100644 --- a/src/buttons/to-do-list/refresh.js +++ b/src/buttons/to-do-list/refresh.js @@ -1,7 +1,7 @@ const todoSchema = require("../../models/todoSchema"); module.exports = { - name: "refresh-todo-list", + name: "refresh-task-list", startsWith: false, requiredRoles: [], async execute(interaction, client, Discord) { diff --git a/src/buttons/to-do-list/remove.js b/src/buttons/to-do-list/remove.js index 1b4f1d7..33f1c4d 100644 --- a/src/buttons/to-do-list/remove.js +++ b/src/buttons/to-do-list/remove.js @@ -3,7 +3,7 @@ const emoji = require("../../config.json").emojis; const todoSchema = require("../../models/todoSchema"); module.exports = { - name: "remove-todo", + name: "remove-task", startsWith: false, requiredRoles: ["dev"], async execute(interaction, client, Discord) { diff --git a/src/commands/dev/admin.js b/src/commands/dev/admin.js index 4c29159..ceb54ac 100644 --- a/src/commands/dev/admin.js +++ b/src/commands/dev/admin.js @@ -159,7 +159,7 @@ module.exports = { enabled: true, hidden: true, deferReply: true, - ephemeral: false, + ephemeral: true, async execute(interaction, client, Discord) { try { const logsChannel = client.channels.cache.get(client.config_channels.logs); @@ -272,7 +272,7 @@ module.exports = { const immuneUsers = new Discord.EmbedBuilder() .setColor(client.config_embeds.default) - .setTitle("🚫 Immune Users") + .setTitle("🔒 Immune Users") .setDescription(`<@${users.join(">, <@")}>`) await interaction.editReply({ embeds: [immuneUsers] }); @@ -437,27 +437,27 @@ module.exports = { const row1 = new Discord.ActionRowBuilder() .addComponents ( new Discord.ButtonBuilder() - .setStyle(Discord.ButtonStyle.Success) - .setCustomId("add-todo") - .setLabel("Add Task"), + .setStyle(Discord.ButtonStyle.Primary) + .setCustomId("get-task") + .setLabel("Get"), new Discord.ButtonBuilder() - .setStyle(Discord.ButtonStyle.Danger) - .setCustomId("remove-todo") - .setLabel("Remove Task"), + .setStyle(Discord.ButtonStyle.Success) + .setCustomId("add-task") + .setLabel("Add"), new Discord.ButtonBuilder() - .setStyle(Discord.ButtonStyle.Primary) - .setCustomId("get-todo") - .setLabel("Get Task") + .setStyle(Discord.ButtonStyle.Danger) + .setCustomId("remove-task") + .setLabel("Remove") ) const row2 = new Discord.ActionRowBuilder() .addComponents ( new Discord.ButtonBuilder() .setStyle(Discord.ButtonStyle.Secondary) - .setCustomId("refresh-todo-list") - .setEmoji("🔃") + .setCustomId("refresh-task-list") + .setLabel("Refresh") ) try { diff --git a/src/commands/info/bot.js b/src/commands/info/bot.js index bbf060d..5d94fb3 100644 --- a/src/commands/info/bot.js +++ b/src/commands/info/bot.js @@ -1,5 +1,9 @@ const bot = require("../../../package.json"); -const moment = require("moment"); + +const devSchema = require("../../models/devSchema"); +const messageSchema = require("../../models/messageSchema"); +const modSchema = require("../../models/modSchema"); +const verifiedSchema = require("../../models/verifiedSchema"); module.exports = { name: "bot", @@ -21,25 +25,39 @@ module.exports = { .setDescription(bot.description) .addFields ( { name: "📈 Version", value: bot.version, inline: true }, - { name: "🟢 Online Since", value: ` ()`, inline: true } + { name: "🟢 Online Since", value: ` ()`, inline: true } ) - const row_1 = new Discord.ActionRowBuilder() - .addComponents ( - new Discord.ButtonBuilder() - .setStyle(Discord.ButtonStyle.Secondary) - .setCustomId("statistics") - .setEmoji("📊") - .setLabel("Statistics"), + const developers = await devSchema.find(); + const moderators = await modSchema.find(); + const verifiedUsers = await verifiedSchema.find(); + const messages = await messageSchema.find(); + const images = await messageSchema.find({ attachment: { $ne: null } }); - new Discord.ButtonBuilder() - .setStyle(Discord.ButtonStyle.Secondary) - .setCustomId("credits") - .setEmoji("✨") - .setLabel("Credits") + const guild = await client.guilds.fetch(client.config_default.guild); + const members = await guild.members.fetch(); + const boosters = members.filter(member => member.premiumSinceTimestamp); + + const stat_guilds = `🗄️ ${client.guilds.cache.size} Guild${client.guilds.cache.size === 1 ? "" : "s"}`; + const stat_users = `👤 ${client.users.cache.size} User${client.users.cache.size === 1 ? "" : "s"}`; + + const stat_developers = `💻 ${developers.length} Developer${developers.length === 1 ? "" : "s"}`; + const stat_moderators = `🔨 ${moderators.length} Moderator${moderators.length === 1 ? "" : "s"}`; + const stat_verified = `✅ ${verifiedUsers.length} Verified User${verifiedUsers.length === 1 ? "" : "s"}`; + const stat_supporters = `💖 ${boosters.size} Supporter${boosters.size === 1 ? "" : "s"}`; + + const stat_messages = `💬 ${messages.length} Message${messages.length === 1 ? "" : "s"}`; + const stat_images = `🖼️ ${images.length} Image${images.length === 1 ? "" : "s"}`; + + const statistics = new Discord.EmbedBuilder() + .setColor(client.config_embeds.default) + .addFields ( + { name: "🤖 Bot", value: `${stat_guilds}\n${stat_users}`, inline: true }, + { name: "🎭 Roles", value: `${stat_developers}\n${stat_moderators}\n${stat_verified}\n${stat_supporters}`, inline: true }, + { name: "🌐 Global Chat", value: `${stat_messages}\n${stat_images}`, inline: true } ) - const row_2 = new Discord.ActionRowBuilder() + const buttons = new Discord.ActionRowBuilder() .addComponents ( new Discord.ButtonBuilder() .setStyle(Discord.ButtonStyle.Link) @@ -49,18 +67,18 @@ module.exports = { new Discord.ButtonBuilder() .setStyle(Discord.ButtonStyle.Link) - .setEmoji("🤝") + .setEmoji("🆘") .setLabel("Support") .setURL("https://discord.gg/globalchat"), new Discord.ButtonBuilder() .setStyle(Discord.ButtonStyle.Link) - .setEmoji("📜") - .setLabel("Terms") - .setURL("https://wdh.gg/gc-terms") + .setEmoji("🗳️") + .setLabel("Vote") + .setURL("https://wdh.gg/gc-vote") ) - await interaction.editReply({ embeds: [info], components: [row_1, row_2] }); + await interaction.editReply({ embeds: [info, statistics], components: [buttons] }); } catch(err) { client.logCommandError(err, interaction, Discord); } diff --git a/src/commands/info/developers.js b/src/commands/info/developers.js index 663aa53..6f57d6b 100644 --- a/src/commands/info/developers.js +++ b/src/commands/info/developers.js @@ -13,7 +13,7 @@ module.exports = { enabled: true, hidden: false, deferReply: true, - ephemeral: false, + ephemeral: true, async execute(interaction, client, Discord) { try { const devs = await devSchema.find(); diff --git a/src/commands/info/moderators.js b/src/commands/info/moderators.js index fb0a44d..ffd7179 100644 --- a/src/commands/info/moderators.js +++ b/src/commands/info/moderators.js @@ -13,7 +13,7 @@ module.exports = { enabled: true, hidden: false, deferReply: true, - ephemeral: false, + ephemeral: true, async execute(interaction, client, Discord) { try { const mods = await modSchema.find(); diff --git a/src/commands/info/supporters.js b/src/commands/info/supporters.js index 99c8204..f9dd153 100644 --- a/src/commands/info/supporters.js +++ b/src/commands/info/supporters.js @@ -11,7 +11,7 @@ module.exports = { enabled: true, hidden: false, deferReply: true, - ephemeral: false, + ephemeral: true, async execute(interaction, client, Discord) { try { const guild = await client.guilds.fetch(client.config_default.guild); diff --git a/src/commands/info/vote.js b/src/commands/info/vote.js deleted file mode 100644 index 1fa1451..0000000 --- a/src/commands/info/vote.js +++ /dev/null @@ -1,29 +0,0 @@ -module.exports = { - name: "vote", - description: "Sends the voting link.", - options: [], - default_member_permissions: null, - botPermissions: [], - requiredRoles: [], - cooldown: 5, - enabled: true, - hidden: false, - deferReply: true, - ephemeral: true, - async execute(interaction, client, Discord) { - try { - const button = new Discord.ActionRowBuilder() - .addComponents ( - new Discord.ButtonBuilder() - .setStyle(Discord.ButtonStyle.Link) - .setEmoji("🗳️") - .setLabel("Vote on Top.gg") - .setURL("https://wdh.gg/gc-vote") - ) - - await interaction.editReply({ components: [button] }); - } catch(err) { - client.logCommandError(err, interaction, Discord); - } - } -} diff --git a/src/context-menu/message/Delete Message.js b/src/context-menu/message/Delete Message.js index 7c0b386..127f148 100644 --- a/src/context-menu/message/Delete Message.js +++ b/src/context-menu/message/Delete Message.js @@ -12,7 +12,6 @@ module.exports = { requiredRoles: [], cooldown: 5, enabled: true, - hidden: false, async execute(interaction, client, Discord) { try { const message = interaction.targetMessage; diff --git a/src/context-menu/message/Message Info.js b/src/context-menu/message/Message Info.js index 3659e56..d176292 100644 --- a/src/context-menu/message/Message Info.js +++ b/src/context-menu/message/Message Info.js @@ -12,7 +12,6 @@ module.exports = { requiredRoles: [], cooldown: 3, enabled: true, - hidden: false, async execute(interaction, client, Discord) { try { const message = interaction.targetMessage; diff --git a/src/context-menu/message/Report Message.js b/src/context-menu/message/Report Message.js index b672725..6454f8c 100644 --- a/src/context-menu/message/Report Message.js +++ b/src/context-menu/message/Report Message.js @@ -10,7 +10,6 @@ module.exports = { requiredRoles: [], cooldown: 10, enabled: true, - hidden: false, async execute(interaction, client, Discord) { try { const message = interaction.targetMessage; diff --git a/src/context-menu/user/User Info.js b/src/context-menu/user/User Info.js index fe06327..981de2d 100644 --- a/src/context-menu/user/User Info.js +++ b/src/context-menu/user/User Info.js @@ -13,7 +13,6 @@ module.exports = { requiredRoles: ["mod"], cooldown: 3, enabled: true, - hidden: false, async execute(interaction, client, Discord) { try { const user = interaction.targetUser; diff --git a/src/events/guild/guildDelete.js b/src/events/guild/guildDelete.js index aa4a002..19cbb78 100644 --- a/src/events/guild/guildDelete.js +++ b/src/events/guild/guildDelete.js @@ -1,4 +1,5 @@ const checkWebhook = require("../../util/checkWebhook"); +const fetch = require("node-fetch"); const channelSchema = require("../../models/channelSchema"); @@ -10,7 +11,7 @@ module.exports = { const data = await channelSchema.findOne({ _id: guild.id }); const valid = await checkWebhook(data.webhook); - if(valid) await axios.delete(data.webhook); + if(valid) await fetch(data.webhook, { method: "DELETE" }); } await channelSchema.findOneAndDelete({ _id: guild.id });