Skip to content

Commit 4a72819

Browse files
Prevent users from blacklisting non-text channels for starboard
1 parent dca3824 commit 4a72819

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/main/java/technobot/commands/starboard/StarboardCommand.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,31 @@ public void execute(SlashCommandInteractionEvent event) {
7474
}
7575
case "blacklist" -> {
7676
if (channelOption != null) {
77-
long channel = channelOption.getAsTextChannel().getIdLong();
78-
starboardHandler.blacklistChannel(channel);
79-
text = EmbedUtils.BLUE_TICK + " Starboard will now ignore reactions from <#" + channel + ">";
77+
try {
78+
long channel = channelOption.getAsTextChannel().getIdLong();
79+
starboardHandler.blacklistChannel(channel);
80+
text = EmbedUtils.BLUE_TICK + " Starboard will now ignore reactions from <#" + channel + ">";
81+
} catch (NullPointerException e) {
82+
text = "You can only blacklist a text channel!";
83+
event.getHook().sendMessageEmbeds(EmbedUtils.createError(text)).queue();
84+
return;
85+
}
8086
} else {
8187
starboardHandler.clearBlacklist();
8288
text = EmbedUtils.BLUE_TICK + " Reset the starboard blacklist!";
8389
}
8490
}
8591
case "unblacklist" -> {
8692
if (channelOption != null) {
87-
long channel = channelOption.getAsTextChannel().getIdLong();
88-
starboardHandler.unBlacklistChannel(channel);
89-
text = EmbedUtils.BLUE_X + " Removed <#" + channel + "> from the Starboard blacklist!";
93+
try {
94+
long channel = channelOption.getAsTextChannel().getIdLong();
95+
starboardHandler.unBlacklistChannel(channel);
96+
text = EmbedUtils.BLUE_X + " Removed <#" + channel + "> from the Starboard blacklist!";
97+
} catch (NullPointerException e) {
98+
text = "You can only unblacklist a text channel!";
99+
event.getHook().sendMessageEmbeds(EmbedUtils.createError(text)).queue();
100+
return;
101+
}
90102
} else {
91103
starboardHandler.clearBlacklist();
92104
text = EmbedUtils.BLUE_TICK + " Reset the starboard blacklist!";

0 commit comments

Comments
 (0)