Skip to content

Commit 313c323

Browse files
Fix permission errors with staff commands
1 parent 54b2fbd commit 313c323

11 files changed

Lines changed: 47 additions & 9 deletions

File tree

src/main/java/technobot/commands/staff/BanCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import technobot.commands.Category;
1515
import technobot.commands.Command;
1616
import technobot.data.GuildData;
17+
import technobot.util.UtilityMethods;
1718
import technobot.util.embeds.EmbedColor;
1819
import technobot.util.embeds.EmbedUtils;
1920

@@ -55,7 +56,7 @@ public void execute(SlashCommandInteractionEvent event) {
5556

5657
// Check that bot has necessary permissions
5758
Role botRole = event.getGuild().getBotRole();
58-
if (!botRole.hasPermission(this.permission) || member.isOwner()) {
59+
if (!UtilityMethods.hasPermission(botRole, this.permission) || member.isOwner()) {
5960
event.getHook().sendMessageEmbeds(EmbedUtils.createError("I couldn't ban that user. Please check my permissions and role position.")).queue();
6061
return;
6162
}

src/main/java/technobot/commands/staff/ClearCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import technobot.TechnoBot;
1010
import technobot.commands.Category;
1111
import technobot.commands.Command;
12+
import technobot.util.UtilityMethods;
1213
import technobot.util.embeds.EmbedUtils;
1314

1415
import java.util.concurrent.TimeUnit;
@@ -37,7 +38,7 @@ public void execute(SlashCommandInteractionEvent event) {
3738

3839
// Check that bot has necessary permissions
3940
Role botRole = event.getGuild().getBotRole();
40-
if (!botRole.hasPermission(this.permission)) {
41+
if (!UtilityMethods.hasPermission(botRole, this.permission)) {
4142
event.getHook().sendMessageEmbeds(EmbedUtils.createError("I couldn't delete those messages. Please check my role and channel permissions.")).queue();
4243
return;
4344
}

src/main/java/technobot/commands/staff/KickCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import technobot.TechnoBot;
1313
import technobot.commands.Category;
1414
import technobot.commands.Command;
15+
import technobot.util.UtilityMethods;
1516
import technobot.util.embeds.EmbedColor;
1617
import technobot.util.embeds.EmbedUtils;
1718

@@ -52,7 +53,7 @@ public void execute(SlashCommandInteractionEvent event) {
5253

5354
// Check that bot has necessary permissions
5455
Role botRole = event.getGuild().getBotRole();
55-
if (!botRole.hasPermission(this.permission) || target.isOwner()) {
56+
if (!UtilityMethods.hasPermission(botRole, this.permission) || target.isOwner()) {
5657
event.getHook().sendMessageEmbeds(EmbedUtils.createError("I couldn't kick that user. Please check my permissions and role position.")).queue();
5758
return;
5859
}

src/main/java/technobot/commands/staff/LockCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import technobot.TechnoBot;
1111
import technobot.commands.Category;
1212
import technobot.commands.Command;
13+
import technobot.util.UtilityMethods;
1314
import technobot.util.embeds.EmbedUtils;
1415

1516
/**
@@ -32,7 +33,7 @@ public LockCommand(TechnoBot bot) {
3233
public void execute(SlashCommandInteractionEvent event) {
3334
// Check that bot has necessary permissions
3435
Role botRole = event.getGuild().getBotRole();
35-
if (!botRole.hasPermission(this.permission)) {
36+
if (!UtilityMethods.hasPermission(botRole, this.permission)) {
3637
event.getHook().sendMessageEmbeds(EmbedUtils.createError("I couldn't lock that channel. Please check my role and channel permissions.")).queue();
3738
return;
3839
}

src/main/java/technobot/commands/staff/RoleCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import technobot.TechnoBot;
1010
import technobot.commands.Category;
1111
import technobot.commands.Command;
12+
import technobot.util.UtilityMethods;
1213
import technobot.util.embeds.EmbedUtils;
1314

1415
/**
@@ -43,7 +44,7 @@ public void execute(SlashCommandInteractionEvent event) {
4344

4445
// Check that bot has necessary permissions
4546
Role botRole = event.getGuild().getBotRole();
46-
if (!botRole.hasPermission(this.permission)) {
47+
if (!UtilityMethods.hasPermission(botRole, this.permission)) {
4748
event.replyEmbeds(EmbedUtils.createError("I couldn't change the roles for that user. Please check my permissions and role position.")).queue();
4849
return;
4950
}

src/main/java/technobot/commands/staff/SetNickCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import technobot.TechnoBot;
1212
import technobot.commands.Category;
1313
import technobot.commands.Command;
14+
import technobot.util.UtilityMethods;
1415
import technobot.util.embeds.EmbedUtils;
1516

1617
/**
@@ -40,7 +41,7 @@ public void execute(SlashCommandInteractionEvent event) {
4041

4142
// Check that bot has necessary permissions
4243
Role botRole = event.getGuild().getBotRole();
43-
if (!botRole.hasPermission(this.permission)) {
44+
if (!UtilityMethods.hasPermission(botRole, this.permission)) {
4445
event.getHook().sendMessageEmbeds(EmbedUtils.createError("I couldn't change that user's nickname. Please check my permissions and role position.")).queue();
4546
return;
4647
}

src/main/java/technobot/commands/staff/SlowmodeCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import technobot.TechnoBot;
1111
import technobot.commands.Category;
1212
import technobot.commands.Command;
13+
import technobot.util.UtilityMethods;
1314
import technobot.util.embeds.EmbedUtils;
1415

1516
import java.time.Duration;
@@ -35,7 +36,7 @@ public SlowmodeCommand(TechnoBot bot) {
3536
public void execute(SlashCommandInteractionEvent event) {
3637
// Check that bot has necessary permissions
3738
Role botRole = event.getGuild().getBotRole();
38-
if (!botRole.hasPermission(this.permission)) {
39+
if (!UtilityMethods.hasPermission(botRole, this.permission)) {
3940
event.replyEmbeds(EmbedUtils.createError("I couldn't set slowmode here. Please check my role and channel permissions.")).queue();
4041
return;
4142
}

src/main/java/technobot/commands/staff/UnbanCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import technobot.commands.Category;
1111
import technobot.commands.Command;
1212
import technobot.data.GuildData;
13+
import technobot.util.UtilityMethods;
1314
import technobot.util.embeds.EmbedColor;
1415
import technobot.util.embeds.EmbedUtils;
1516

@@ -35,7 +36,7 @@ public void execute(SlashCommandInteractionEvent event) {
3536

3637
// Check that bot has necessary permissions
3738
Role botRole = event.getGuild().getBotRole();
38-
if (!botRole.hasPermission(this.permission)) {
39+
if (!UtilityMethods.hasPermission(botRole, this.permission)) {
3940
event.getHook().sendMessageEmbeds(EmbedUtils.createError("I couldn't unban that user. Please check my permissions and role position.")).queue();
4041
return;
4142
}

src/main/java/technobot/commands/staff/UnlockCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import technobot.TechnoBot;
1111
import technobot.commands.Category;
1212
import technobot.commands.Command;
13+
import technobot.util.UtilityMethods;
1314
import technobot.util.embeds.EmbedUtils;
1415

1516
/**
@@ -32,7 +33,7 @@ public UnlockCommand(TechnoBot bot) {
3233
public void execute(SlashCommandInteractionEvent event) {
3334
// Check that bot has necessary permissions
3435
Role botRole = event.getGuild().getBotRole();
35-
if (!botRole.hasPermission(this.permission)) {
36+
if (!UtilityMethods.hasPermission(botRole, this.permission)) {
3637
event.getHook().sendMessageEmbeds(EmbedUtils.createError("I couldn't unlock that channel. Please check my role and channel permissions.")).queue();
3738
return;
3839
}

src/main/java/technobot/listeners/GuildListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import technobot.commands.CommandRegistry;
77
import technobot.data.GuildData;
88

9+
/**
10+
* Listens for guild event
11+
* Only really used for guild command registration at the moment.
12+
*
13+
* @author TechnoVision
14+
*/
915
public class GuildListener extends ListenerAdapter {
1016

1117
/**

0 commit comments

Comments
 (0)