From 6226ca6414b45d8a7819f5e6a9ba0b890ff1f08e Mon Sep 17 00:00:00 2001 From: Jacob Date: Sun, 22 Sep 2024 00:03:23 +0800 Subject: [PATCH 1/2] Player Command --- src/minecraft/commands/PlayerCommand.js | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/minecraft/commands/PlayerCommand.js diff --git a/src/minecraft/commands/PlayerCommand.js b/src/minecraft/commands/PlayerCommand.js new file mode 100644 index 00000000..9e7f8a8a --- /dev/null +++ b/src/minecraft/commands/PlayerCommand.js @@ -0,0 +1,41 @@ +const minecraftCommand = require("../../contracts/minecraftCommand.js"); +const { formatNumber } = require("../../contracts/helperFunctions.js"); +const hypixel = require("../../contracts/API/HypixelRebornAPI.js"); + +class PlayerCommand extends minecraftCommand { + constructor(minecraft) { + super(minecraft); + + this.name = "player"; + this.aliases = []; + this.description = "Get Hypixel Player Stats"; + this.options = [ + { + name: "username", + description: "Minecraft username", + required: false, + }, + ]; + } + + async onCommand(username, message) { + try { + // CREDITS: by @Kathund (https://github.com/Kathund) + username = this.getArgs(message)[0] || username; + const { achievementPoints, nickname, rank, karma, level, guild } = await hypixel.getPlayer(username, { + guild: true, + }); + const guildName = guild ? guild.name : "None"; + + this.send( + `/gc ${rank !== "Default" ? `[${rank}] ` : ""}${nickname}'s level: ${level} | Karma: ${formatNumber(karma, 0)} Achievement Points: ${formatNumber(achievementPoints, 0)} Guild: ${guildName} `, + ); + } catch (error) { + console.log(error); + + this.send(`/gc [ERROR] ${error}`); + } + } +} + +module.exports = PlayerCommand; From d50f8b17a3423c5cd6ea7de077eaf9f980fa2b46 Mon Sep 17 00:00:00 2001 From: Jacob Date: Sun, 22 Sep 2024 10:39:04 +0800 Subject: [PATCH 2/2] Unverified Role --- config.example.json | 1 + src/discord/DiscordManager.js | 15 ++++++++------- src/discord/commands/updateCommand.js | 4 ++++ src/discord/events/guildMemberAdd.js | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/discord/events/guildMemberAdd.js diff --git a/config.example.json b/config.example.json index cf1d0b1d..531c5ab5 100644 --- a/config.example.json +++ b/config.example.json @@ -108,6 +108,7 @@ "verification": { "enabled": false, "verifiedRole": "VERIFIED_ROLE_ID", + "unverifiedRole": "UNVERIFIED_ROLE_ID", "removeVerificationRole": true, "guildMemberRole": "GUILD_MEMBER_ROLE_ID", "autoUpdater": true, diff --git a/src/discord/DiscordManager.js b/src/discord/DiscordManager.js index c246c787..c17b426e 100644 --- a/src/discord/DiscordManager.js +++ b/src/discord/DiscordManager.js @@ -7,7 +7,6 @@ const StateHandler = require("./handlers/StateHandler.js"); const CommandHandler = require("./CommandHandler.js"); const config = require("../../config.json"); const Logger = require(".././Logger.js"); -const path = require("node:path"); const fs = require("fs"); class DiscordManager extends CommunicationBridge { @@ -24,7 +23,12 @@ class DiscordManager extends CommunicationBridge { connect() { global.imgurUrl = ""; global.client = new Client({ - intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent], + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.MessageContent, + GatewayIntentBits.GuildMembers, + ], }); this.client = client; @@ -48,12 +52,9 @@ class DiscordManager extends CommunicationBridge { client.commands.set(command.name, command); } - const eventsPath = path.join(__dirname, "events"); - const eventFiles = fs.readdirSync(eventsPath).filter((file) => file.endsWith(".js")); - + const eventFiles = fs.readdirSync("src/discord/events").filter((file) => file.endsWith(".js")); for (const file of eventFiles) { - const filePath = path.join(eventsPath, file); - const event = require(filePath); + const event = require(`./events/${file}`); event.once ? client.once(event.name, (...args) => event.execute(...args)) : client.on(event.name, (...args) => event.execute(...args)); diff --git a/src/discord/commands/updateCommand.js b/src/discord/commands/updateCommand.js index 4745aeff..48176df2 100644 --- a/src/discord/commands/updateCommand.js +++ b/src/discord/commands/updateCommand.js @@ -52,6 +52,10 @@ module.exports = { } } + if (!interaction.member.roles.cache.has(config.verification.unverifiedRole)) { + await interaction.member.roles.add(config.verification.unverifiedRole, "Updated Roles"); + } + interaction.member.setNickname(null, "Updated Roles"); throw new HypixelDiscordChatBridgeError("You are not linked to a Minecraft account."); diff --git a/src/discord/events/guildMemberAdd.js b/src/discord/events/guildMemberAdd.js new file mode 100644 index 00000000..651876f7 --- /dev/null +++ b/src/discord/events/guildMemberAdd.js @@ -0,0 +1,18 @@ +// eslint-disable-next-line no-unused-vars +const { GuildMember } = require("discord.js"); +const config = require("../../../config.json"); + +module.exports = { + name: "guildMemberAdd", + /** + * @param {GuildMember} member + */ + async execute(member) { + try { + if (member.user.bot || config.verification.enabled === false) return; + await member.roles.add(config.verification.unverifiedRole, "Updated Roles"); + } catch (error) { + console.log(error); + } + }, +};