Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unverified role #279

Merged
merged 4 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"verification": {
"enabled": false,
"verifiedRole": "VERIFIED_ROLE_ID",
"unverifiedRole": "UNVERIFIED_ROLE_ID",
"removeVerificationRole": true,
"guildMemberRole": "GUILD_MEMBER_ROLE_ID",
"autoUpdater": true,
Expand Down
15 changes: 8 additions & 7 deletions src/discord/DiscordManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions src/discord/commands/updateCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
18 changes: 18 additions & 0 deletions src/discord/events/guildMemberAdd.js
Original file line number Diff line number Diff line change
@@ -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);
}
},
};
Loading