Skip to content

Commit ea011b5

Browse files
committed
refactor: rewrite roles
1 parent 8acb4b3 commit ea011b5

21 files changed

+677
-727
lines changed

.eslintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"globals": {
1313
"bot": true,
1414
"client": true,
15-
"guild": true,
16-
"imgurUrl": true
15+
"guild": true
1716
},
1817
"rules": {
1918
"curly": ["warn", "multi-line", "consistent"],

config.example.json

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,60 @@
9898
"token": "WEBSOCKET_TOKEN"
9999
},
100100
"verification": {
101-
"enabled": false,
102-
"verifiedRole": "VERIFIED_ROLE_ID",
103-
"unverifiedRole": "UNVERIFIED_ROLE_ID",
104-
"removeVerificationRole": true,
105-
"guildMemberRole": "GUILD_MEMBER_ROLE_ID",
106-
"autoUpdater": false,
107-
"autoUpdaterInterval": 24,
108-
"name": "{username}",
109-
"levelRoles": [
110-
{
111-
"type": "bedwarsStar",
112-
"requirement": 200,
113-
"roleId": "DISCORD_ROLE_ID"
114-
}
115-
],
116-
"ranks": [
117-
{
118-
"name": "IN_GAME_RANK_NAME",
119-
"roles": ["DISCORD_ROLE_ID"]
120-
}
121-
]
101+
"enabled": true,
102+
"nickname": "{username}",
103+
"roles": {
104+
"verified": {
105+
"enabled": false,
106+
"roleId": "1003353024720277504"
107+
},
108+
"guildMember": {
109+
"enabled": true,
110+
"roleId": "600313217603993617"
111+
},
112+
"custom": [
113+
{
114+
"roleId": "1324671329458458665",
115+
"requirements": [
116+
{
117+
"type": "bedwarsStar",
118+
"value": 100
119+
}
120+
]
121+
},
122+
{
123+
"roleId": "1324671329458458665",
124+
"requirements": [
125+
{
126+
"type": "guildRank",
127+
"value": "Novice"
128+
}
129+
]
130+
},
131+
{
132+
"roleId": "1324671329458458665",
133+
"requirements": [
134+
{
135+
"type": "guildRank",
136+
"value": "Test"
137+
}
138+
]
139+
},
140+
{
141+
"roleId": "1324671329458458665",
142+
"requirements": [
143+
{
144+
"type": "skyblockLevel",
145+
"value": 15
146+
}
147+
]
148+
}
149+
]
150+
},
151+
"autoRoleUpdater": {
152+
"enabled": true,
153+
"interval": 24
154+
}
122155
},
123156
"other": {
124157
"autoUpdater": true,

jsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"include": ["API/**/*", "types/**/*.d.ts", "src/minecraft/commands/*"],
1212
"globals": {
1313
"bot": "readonly",
14-
"client": "readonly"
14+
"client": "readonly",
15+
"guild": "readonly"
1516
}
1617
}

messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"offlineInvite": "{username} was offline invited to the guild!",
1515
"guildMuteMessage": "Guild Chat has been muted for {time}!",
1616
"guildUnmuteMessage": "Guild Chat has been unmuted!",
17-
"guildJoinMessage": "Welcome to the guild! Make sure to join our discord using /g discord! To view my commands run {prefix}help",
17+
"guildJoinMessage": "Welcome to the guild! Make sure to join our discord using /g discord!",
1818
"userMuteMessage": "{username} has been muted for {time}!",
1919
"userUnmuteMessage": "{username} has been unmuted!",
2020
"setrankFailMessage": "{username} not found.",

src/contracts/embedHandler.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class ErrorEmbed extends Embed {
3232

3333
this.setAuthor({ name: "An Error has occurred" });
3434
this.setColor(15548997);
35+
this.setFooter({
36+
text: `by @duckysolucky | /help [command] for more information`,
37+
iconURL: "https://imgur.com/tgwQJTX.png"
38+
});
3539

3640
this.setDescription(description);
3741
}
@@ -51,6 +55,10 @@ class SuccessEmbed extends Embed {
5155

5256
this.setAuthor({ name: "Success" });
5357
this.setColor(5763719);
58+
this.setFooter({
59+
text: `by @duckysolucky | /help [command] for more information`,
60+
iconURL: "https://imgur.com/tgwQJTX.png"
61+
});
5462

5563
this.setDescription(description);
5664
}

src/discord/CommandHandler.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ class CommandHandler {
1313

1414
for (const file of commandFiles) {
1515
const command = require(`./commands/${file}`);
16-
if (command.verificationCommand === true && config.verification.enabled === false) continue;
17-
if (command.channelsCommand === true && config.statsChannels.enabled === false) continue;
16+
if (command.verificationCommand === true && config.verification.enabled === false) {
17+
continue;
18+
}
19+
20+
if (command.channelsCommand === true && config.statsChannels.enabled === false) {
21+
continue;
22+
}
23+
1824
commands.push(command);
1925
}
2026

src/discord/DiscordManager.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class DiscordManager extends CommunicationBridge {
104104
console.error(`Channel ${chat} not found!`);
105105
return;
106106
}
107+
107108
if (username === bot.username && message.endsWith("Check Discord Bridge for image.")) {
108109
channel.send(imgurUrl);
109110
imgurUrl = "";
@@ -183,6 +184,10 @@ class DiscordManager extends CommunicationBridge {
183184
console.broadcast(message, "Event");
184185

185186
channel = await this.stateHandler.getChannel(channel);
187+
if (channel === undefined) {
188+
console.log(`Channel ${channel} not found!`);
189+
}
190+
186191
channel.send({
187192
embeds: [
188193
{
@@ -197,6 +202,11 @@ class DiscordManager extends CommunicationBridge {
197202
console.broadcast(message, "Event");
198203

199204
channel = await this.stateHandler.getChannel(channel);
205+
if (channel === undefined) {
206+
console.log(`Channel ${channel} not found!`);
207+
return;
208+
}
209+
200210
channel.send({
201211
embeds: [
202212
{
@@ -213,7 +223,13 @@ class DiscordManager extends CommunicationBridge {
213223

214224
async onPlayerToggle({ fullMessage, username, message, color, channel }) {
215225
console.broadcast(message, "Event");
226+
216227
channel = await this.stateHandler.getChannel(channel);
228+
if (channel === undefined) {
229+
console.log(`Channel ${channel} not found!`);
230+
return;
231+
}
232+
217233
switch (config.discord.other.messageMode.toLowerCase()) {
218234
case "bot":
219235
channel.send({

src/discord/commands/forceUpdateChannelsCommand.js

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const HypixelDiscordChatBridgeError = require("../../contracts/errorHandler.js");
2+
const updateRolesCommand = require("./updateCommand.js");
3+
const fs = require("fs");
24

35
module.exports = {
46
name: "force-update",
5-
description: "Update a user's roles",
7+
description: "Update user's or everyone's roles",
68
moderatorOnly: true,
79
verificationCommand: true,
810
requiresBot: true,
@@ -11,17 +13,44 @@ module.exports = {
1113
name: "user",
1214
description: "Discord User",
1315
type: 6,
14-
required: true
16+
required: false
17+
},
18+
{
19+
name: "everyone",
20+
description: "Update everyone's roles",
21+
type: 5,
22+
required: false
1523
}
1624
],
1725

1826
execute: async (interaction) => {
27+
const linkedData = fs.readFileSync("data/linked.json");
28+
if (!linkedData) {
29+
throw new HypixelDiscordChatBridgeError("The linked data file does not exist. Please contact an administrator.");
30+
}
31+
32+
const linked = JSON.parse(linkedData.toString("utf8"));
33+
if (!linked) {
34+
throw new HypixelDiscordChatBridgeError("The linked data file is malformed. Please contact an administrator.");
35+
}
36+
1937
const user = interaction.options.getUser("user");
20-
const updateRolesCommand = require("./updateCommand.js");
21-
if (updateRolesCommand === undefined) {
22-
throw new HypixelDiscordChatBridgeError("The update command does not exist. Please contact an administrator.");
38+
const everyone = interaction.options.getBoolean("everyone");
39+
if (!user && !everyone) {
40+
throw new HypixelDiscordChatBridgeError("You must specify a user or everyone.");
2341
}
2442

25-
await updateRolesCommand.execute(interaction, user);
43+
if (user && everyone) {
44+
throw new HypixelDiscordChatBridgeError("You cannot specify both user and everyone.");
45+
}
46+
47+
if (user) {
48+
await updateRolesCommand.execute(interaction, { discordId: user.id });
49+
}
50+
51+
const discordIds = Object.values(linked);
52+
for (const discordId of discordIds) {
53+
await updateRolesCommand.execute(interaction, { discordId });
54+
}
2655
}
2756
};

src/discord/commands/forceUpdateEveryone.js

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)