Skip to content

Commit b681116

Browse files
Merge pull request #350 from Java-Discord/dynxsty/fix-common-exceptions
Fix some Exceptions
2 parents dd16c93 + 9682379 commit b681116

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

src/main/java/net/javadiscord/javabot/systems/help/commands/subcommands/HelpAccountSubcommand.java renamed to src/main/java/net/javadiscord/javabot/systems/help/commands/HelpAccountSubcommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.javadiscord.javabot.systems.help.commands.subcommands;
1+
package net.javadiscord.javabot.systems.help.commands;
22

33
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
44
import net.dv8tion.jda.api.EmbedBuilder;

src/main/java/net/javadiscord/javabot/systems/help/commands/HelpCommand.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
44
import net.dv8tion.jda.api.interactions.commands.build.Commands;
5-
import net.javadiscord.javabot.systems.help.commands.subcommands.HelpAccountSubcommand;
6-
import net.javadiscord.javabot.systems.help.commands.subcommands.HelpGuidelinesCommand;
7-
import net.javadiscord.javabot.systems.help.commands.subcommands.HelpPingCommand;
85

96
/**
107
* Represents the `/help` command. This holds commands related to the help system.
@@ -17,6 +14,6 @@ public HelpCommand() {
1714
setSlashCommandData(Commands.slash("help", "Commands related to the help system.")
1815
.setGuildOnly(true)
1916
);
20-
addSubcommands(new HelpAccountSubcommand(), new HelpPingCommand(), new HelpGuidelinesCommand());
17+
addSubcommands(new HelpAccountSubcommand(), new HelpPingSubcommand(), new HelpGuidelinesSubcommand());
2118
}
2219
}

src/main/java/net/javadiscord/javabot/systems/help/commands/subcommands/HelpGuidelinesCommand.java renamed to src/main/java/net/javadiscord/javabot/systems/help/commands/HelpGuidelinesSubcommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.javadiscord.javabot.systems.help.commands.subcommands;
1+
package net.javadiscord.javabot.systems.help.commands;
22

33
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
44
import net.dv8tion.jda.api.EmbedBuilder;
@@ -16,11 +16,11 @@
1616
/**
1717
* Shows the server's help-guidelines.
1818
*/
19-
public class HelpGuidelinesCommand extends SlashCommand.Subcommand {
19+
public class HelpGuidelinesSubcommand extends SlashCommand.Subcommand {
2020
/**
2121
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
2222
*/
23-
public HelpGuidelinesCommand() {
23+
public HelpGuidelinesSubcommand() {
2424
setSubcommandData(new SubcommandData("guidelines", "Show the server's help guidelines in a simple format."));
2525
}
2626

src/main/java/net/javadiscord/javabot/systems/help/commands/subcommands/HelpPingCommand.java renamed to src/main/java/net/javadiscord/javabot/systems/help/commands/HelpPingSubcommand.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.javadiscord.javabot.systems.help.commands.subcommands;
1+
package net.javadiscord.javabot.systems.help.commands;
22

33
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
44
import net.dv8tion.jda.api.EmbedBuilder;
@@ -22,7 +22,7 @@
2222
* Handler for the /help ping sub-command that allows users to occasionally ping
2323
* helpers.
2424
*/
25-
public class HelpPingCommand extends SlashCommand.Subcommand {
25+
public class HelpPingSubcommand extends SlashCommand.Subcommand {
2626
private static final String WRONG_CHANNEL_MSG = "This command can only be used in **reserved help channels**.";
2727
private static final long CACHE_CLEANUP_DELAY = 60L;
2828

@@ -31,7 +31,7 @@ public class HelpPingCommand extends SlashCommand.Subcommand {
3131
/**
3232
* Constructor that initializes and handles the cooldown map.
3333
*/
34-
public HelpPingCommand() {
34+
public HelpPingSubcommand() {
3535
setSubcommandData(new SubcommandData("ping", "Notify those with the help-ping role that your question is urgent."));
3636
lastPingTimes = new ConcurrentHashMap<>();
3737
Bot.getAsyncPool().scheduleWithFixedDelay(this::cleanTimeoutCache, CACHE_CLEANUP_DELAY, CACHE_CLEANUP_DELAY, TimeUnit.SECONDS);
@@ -87,33 +87,35 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
8787
/**
8888
* Determines if a user is forbidden from sending a help-ping command due
8989
* to their status in the server.
90+
*
9091
* @param reservation The channel reservation for the channel they're
9192
* trying to send the command in.
92-
* @param member The member.
93-
* @param config The guild config.
93+
* @param member The member.
94+
* @param config The guild config.
9495
* @return True if the user is forbidden from sending the command.
9596
*/
9697
private boolean isHelpPingForbiddenForMember(@NotNull ChannelReservation reservation, @NotNull Member member, @NotNull GuildConfig config) {
9798
Set<Role> allowedRoles = Set.of(config.getModerationConfig().getStaffRole(), config.getHelpConfig().getHelperRole());
9899
return !(
99100
reservation.getUserId() == member.getUser().getIdLong() ||
100-
member.getRoles().stream().anyMatch(allowedRoles::contains) ||
101-
member.isOwner()
101+
member.getRoles().stream().anyMatch(allowedRoles::contains) ||
102+
member.isOwner()
102103
);
103104
}
104105

105106
/**
106107
* Determines if the user's timeout has elapsed (or doesn't exist), which
107108
* implies that it's fine for the user to send the command.
109+
*
108110
* @param memberId The members' id.
109-
* @param config The guild config.
111+
* @param config The guild config.
110112
* @return True if the user's timeout has elapsed or doesn't exist, or
111113
* false if the user should NOT send the command because of their timeout.
112114
*/
113115
private boolean isHelpPingTimeoutElapsed(long memberId, GuildConfig config) {
114-
Long lastPing = lastPingTimes.get(memberId).first();
116+
Pair<Long, Guild> lastPing = lastPingTimes.get(memberId);
115117
return lastPing == null ||
116-
lastPing + config.getHelpConfig().getHelpPingTimeoutSeconds() * 1000L < System.currentTimeMillis();
118+
lastPing.first() + config.getHelpConfig().getHelpPingTimeoutSeconds() * 1000L < System.currentTimeMillis();
117119
}
118120

119121
/**

src/main/java/net/javadiscord/javabot/systems/notification/NotificationService.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import net.dv8tion.jda.api.entities.MessageChannel;
66
import net.dv8tion.jda.api.entities.User;
77
import net.dv8tion.jda.api.requests.restaction.MessageAction;
8-
import net.javadiscord.javabot.util.ExceptionLogger;
98
import org.jetbrains.annotations.Contract;
109
import org.jetbrains.annotations.NotNull;
1110

@@ -49,11 +48,9 @@ abstract static class MessageChannelNotification {
4948
* @param function The {@link Function} which is used in order to send the message.
5049
*/
5150
protected void send(MessageChannel channel, @NotNull Function<MessageChannel, MessageAction> function) {
52-
function.apply(channel).queue(s -> {
53-
}, err -> {
54-
ExceptionLogger.capture(err, getClass().getSimpleName());
55-
log.error("Could not send message to channel \" " + channel.getName() + "\": ", err);
56-
});
51+
function.apply(channel).queue(s -> {},
52+
err -> log.error("Could not send message to channel \" " + channel.getName() + "\": ", err)
53+
);
5754
}
5855
}
5956
}

0 commit comments

Comments
 (0)