[AB-241] fixing low cooldowns leading to NPE in command cooldown condition

adding more info to command not found exception
This commit is contained in:
Sheldan
2021-04-25 21:27:29 +02:00
parent 68e2dad2ae
commit f097342fed
3 changed files with 11 additions and 6 deletions

View File

@@ -118,7 +118,8 @@ public class CommandReceivedHandler extends ListenerAdapter {
tryToExecuteFoundCommand(event, foundCommand, unParsedParameter); tryToExecuteFoundCommand(event, foundCommand, unParsedParameter);
} catch (Exception e) { } catch (Exception e) {
reportException(event, null, e, "Exception when executing command."); reportException(event, null, e, String.format("Exception when executing command from message %d in message %d in guild %d."
,event.getMessage().getIdLong(), event.getChannel().getIdLong(), event.getGuild().getIdLong()));
} }
} }

View File

@@ -118,19 +118,26 @@ public class CommandCoolDownServiceBean implements CommandCoolDownService {
} }
} }
} }
return createCooldownCheckResult(serverId, commandName, serverCooldown, channelCooldown, memberCooldown);
}
public CoolDownCheckResult createCooldownCheckResult(Long serverId, String commandName, Duration serverCooldown, Duration channelCooldown, Duration memberCooldown) {
if(serverCooldown != null || channelCooldown != null || memberCooldown != null) { if(serverCooldown != null || channelCooldown != null || memberCooldown != null) {
Long serverSeconds = serverCooldown != null ? serverCooldown.getSeconds() : 0L; Long serverSeconds = serverCooldown != null ? serverCooldown.getSeconds() : 0L;
Long channelSeconds = channelCooldown != null ? channelCooldown.getSeconds() : 0L; Long channelSeconds = channelCooldown != null ? channelCooldown.getSeconds() : 0L;
Long memberSeconds = memberCooldown != null ? memberCooldown.getSeconds() : 0L; Long memberSeconds = memberCooldown != null ? memberCooldown.getSeconds() : 0L;
if(serverSeconds == 0 && channelSeconds == 0 && memberSeconds == 0) {
return CoolDownCheckResult.noCoolDown();
}
if(serverSeconds > channelSeconds && serverSeconds > memberSeconds) { if(serverSeconds > channelSeconds && serverSeconds > memberSeconds) {
log.info("Rejecting command {}, because of server cooldown in server {}. Can be executed in {} seconds.", commandName, serverId, serverSeconds); log.info("Rejecting command {}, because of server cooldown in server {}. Can be executed in {} seconds.", commandName, serverId, serverSeconds);
return CoolDownCheckResult.getServerCoolDown(serverCooldown); return CoolDownCheckResult.getServerCoolDown(serverCooldown);
} }
if(channelSeconds > serverSeconds && channelSeconds > memberSeconds) { if(channelSeconds > serverSeconds && channelSeconds > memberSeconds) {
log.info("Rejecting command {}, because of channel cooldown in server {}. Can be executed in {} seconds.", commandName, serverId, channelCooldown); log.info("Rejecting command {}, because of channel cooldown in server {}. Can be executed in {} seconds.", commandName, serverId, channelSeconds);
return CoolDownCheckResult.getChannelGroupCoolDown(channelCooldown); return CoolDownCheckResult.getChannelGroupCoolDown(channelCooldown);
} }
log.info("Rejecting command {}, because of member cooldown in server {}. Can be executed in {} seconds.", commandName, serverId, memberCooldown); log.info("Rejecting command {}, because of member cooldown in server {}. Can be executed in {} seconds.", commandName, serverId, memberSeconds);
return CoolDownCheckResult.getMemberCoolDown(memberCooldown); return CoolDownCheckResult.getMemberCoolDown(memberCooldown);
} }
return CoolDownCheckResult.noCoolDown(); return CoolDownCheckResult.noCoolDown();

View File

@@ -24,9 +24,6 @@ public class CommandCoolDownCondition implements CommandCondition {
if(result.getCanExecute()) { if(result.getCanExecute()) {
return ConditionResult.builder().result(true).build(); return ConditionResult.builder().result(true).build();
} else { } else {
if(result.getExecuteIn().compareTo(Duration.ofSeconds(1)) < 0) {
result.setExecuteIn(Duration.ofSeconds(1));
}
return ConditionResult.builder().result(false).conditionDetail(new CommandCoolDownDetail(result)).build(); return ConditionResult.builder().result(false).conditionDetail(new CommandCoolDownDetail(result)).build();
} }
} finally { } finally {