From 151498af20a0b2b989fea71c605d51aab497891f Mon Sep 17 00:00:00 2001 From: Taken Date: Sat, 11 Mar 2023 20:16:50 +0100 Subject: [PATCH] 2nd commit --- commands/check.js | 44 ++++++++++++++---- commands/config.js | 62 +++++++++++++++++++++++++ commands/send.js | 3 +- events/buttons/guilapply.js | 21 +++++++++ index.js | 38 ++++++++++++++++ options.json | 3 ++ package-lock.json | 91 +++++++++++++++++++++++++++++++++++++ package.json | 1 + 8 files changed, 253 insertions(+), 10 deletions(-) create mode 100644 commands/config.js create mode 100644 events/buttons/guilapply.js create mode 100644 options.json diff --git a/commands/check.js b/commands/check.js index 54ebf3a..cb8e1fe 100644 --- a/commands/check.js +++ b/commands/check.js @@ -1,5 +1,6 @@ -const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); +const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js'); const { hypixelApiKey, dev } = require('../config.json'); +const { color } = require('../options.json'); module.exports = { name: 'check', @@ -22,11 +23,12 @@ module.exports = { const mojang = "https://api.mojang.com/users/profiles/minecraft/" const slothPixel = "https://api.slothpixel.me/api/players/"; const minotar = "https://minotar.net/helm/"; - const fetch = require('node-fetch'); + const fetch = require('axios'); + const embedColor = Number(color.replace("#", "0x")); const userCheck = await fetch(mojang + ign); const stats = await fetch(slothPixel + ign); - const head = await fetch(minotar + ign + "/100.png"); + const head = minotar + ign; if (interaction.user.id !== dev) { interaction.reply('This command is currently under development.') @@ -38,26 +40,50 @@ module.exports = { return } - if (!userCheck.status === 200) { + if (!userCheck.data.id) { interaction.reply('That player doesn\'t exist. [Mojang]') return } - if (!stats.status === 200) { + if (!stats.data.uuid) { interaction.reply('That player doesn\'t exist. [Hypixel]') return } + const level = stats.data.stats.SkyWars.level; + + await interaction.reply({ embeds: [{ - title: ign, - description: stats.stats.Bedwars.level, - color: 0x00ff00, + title: stats.data.username, + description: "**Stats:**", + color: embedColor, thumbnail: { url: head }, + footer: { + text: "Developed by @Taken#0002" + }, + fields: [ + { + name: "**Network Level**", + value: stats.data.level.toString(), + }, + { + name: "**Bedwars**", + value: "**Stars:** " + stats.data.stats.BedWars.level.toString() + "\n" + + "**FKDR:** " + stats.data.stats.BedWars.final_k_d.toString() + "\n" + + "**Wins:** " + stats.data.stats.BedWars.wins.toString() + }, + { + name: "**Skywars**", + value: "**Stars:** " + stats.data.stats.SkyWars.level.toFixed(2).toString() + "\n" + + "**KDR**: " + stats.data.stats.SkyWars.kill_death_ratio.toString() + "\n" + + "**Wins:** " + stats.data.stats.SkyWars.wins.toString() + } + ] }] - }); + }) } }; \ No newline at end of file diff --git a/commands/config.js b/commands/config.js new file mode 100644 index 0000000..4f01d92 --- /dev/null +++ b/commands/config.js @@ -0,0 +1,62 @@ +const { SlashCommandBuilder, PermissionFlagsBits, ButtonBuilder, ActionRowBuilder, ButtonStyle } = require('discord.js'); +const { color } = require('../options.json'); + +module.exports = { + name: 'config', + description: 'Configure the bot.', + type: 'slash', + + data: new SlashCommandBuilder() + .setName('config') + .setDescription('Configure the bot.') + .addSubcommand(subcommand => + subcommand + .setName('sendapplication') + .setDescription('Configure the send application command.') + .addChannelOption(option => + option + .setName('channel') + .setDescription('The channel to send the application to.') + .setRequired(true))) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) + .setDMPermission(false), + + async execute(interaction) { + + const subcommand = interaction.options.getSubcommand(); + const embedColor = Number(color.replace("#", "0x")); + + if (subcommand === 'sendapplication') { + + const channel = interaction.options.getChannel('channel'); + + await channel.send({ + embeds: [{ + title: 'Guild Application', + description: "You can apply for the guild by clicking the button below.", + color: embedColor, + footer: { + text: interaction.guild.name + " | Developed by @Taken#0002", + }, + thumbnail: { + url: interaction.guild.iconURL({ dynamic: true }) + } + }], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId('guildapply') + .setLabel('Apply') + .setStyle(ButtonStyle.Primary) + .setEmoji({ name: '✅' }) + ) + ] + }) + + await interaction.reply({ content: 'Message sent', ephemeral: true }) + + } + + } + +}; \ No newline at end of file diff --git a/commands/send.js b/commands/send.js index d91be5d..2dfd0ef 100644 --- a/commands/send.js +++ b/commands/send.js @@ -1,4 +1,5 @@ const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); +const { color } = require('../options.json'); module.exports = { name: 'send', @@ -38,7 +39,7 @@ module.exports = { { title: interaction.guild.name, description: message, - color: 0x00ff00, + color: color, thumbnail: { url: interaction.guild.iconURL({ dynamic: true }) }, diff --git a/events/buttons/guilapply.js b/events/buttons/guilapply.js new file mode 100644 index 0000000..a355a25 --- /dev/null +++ b/events/buttons/guilapply.js @@ -0,0 +1,21 @@ +const { color } = require('../../options.json'); + +module.exports = { + name: 'guildapply', + description: 'Guild application button.', + type: 'button', + + async execute(interaction) { + + const user = interaction.user; + const guild = interaction.guild; + const embedColor = Number(color.replace("#", "0x")); + + if (interaction.customId === 'guildapply') { + + await interaction.reply({ content: 'Please wait...', ephemeral: true }); + + } + + } +} \ No newline at end of file diff --git a/index.js b/index.js index 6bd6712..9ec3ad7 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ const client = new Client({ }); client.commands = new Collection(); +client.events = new Collection(); //! commands const cmdPath = path.join(__dirname, 'commands'); @@ -53,6 +54,43 @@ client.on(Events.InteractionCreate, async interaction => { } }); +//! button events +const btnPath = path.join(__dirname, 'events', 'buttons'); +const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith('.js')); + +for (const file of btnFiles) { + + const filePath = path.join(btnPath, file); + const btn = require(filePath); + + if ('name' in btn && 'execute' in btn && btn.type === 'button') { + client.events.set(btn.name, btn); + } else { + console.log(`[WARNING] The button at ${filePath} is missing a required "name", "execute" or "type" property.`); + } +} + +//! button event handler +client.on(Events.InteractionCreate, async event => { + if(!event.isButton()) return; + + const event2 = event.client.events.get(event.customId); + + if (!event2) { + console.error(`No event matching ${event.customId} was found.`); + return; + } + + try { + await event2.execute(event); + } catch (error) { + console.error(error); + await event.reply({ content: 'There was an error while executing this event!', ephemeral: true }) + } +}) + + + client.once(Events.Ready, c => { console.log(`Logged in as ${c.user.tag}!`); }); diff --git a/options.json b/options.json new file mode 100644 index 0000000..16ee32d --- /dev/null +++ b/options.json @@ -0,0 +1,3 @@ +{ + "color": "#eeaadb" +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0644cab..1c719c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "axios": "^1.3.4", "discord.js": "^14.7.1" } }, @@ -111,6 +112,21 @@ "@types/node": "*" } }, + "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.3.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz", + "integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -122,6 +138,25 @@ "node": ">=10.16.0" } }, + "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/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/discord-api-types": { "version": "0.37.35", "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.35.tgz", @@ -170,6 +205,38 @@ "url": "https://github.com/sindresorhus/file-type?sponsor=1" } }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "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/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -204,6 +271,25 @@ "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", "integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==" }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/peek-readable": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-5.0.0.tgz", @@ -216,6 +302,11 @@ "url": "https://github.com/sponsors/Borewit" } }, + "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/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", diff --git a/package.json b/package.json index 510abb6..b450961 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "author": "Taken", "license": "ISC", "dependencies": { + "axios": "^1.3.4", "discord.js": "^14.7.1" } }