Add default cases to switches
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2023-01-16 07:20:49 +01:00
parent 668375367a
commit 627f6deb97
3 changed files with 17 additions and 1 deletions

View File

@ -2,6 +2,8 @@ package wtf.beatrice.hidekobot.listeners;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wtf.beatrice.hidekobot.commands.base.CoinFlip; import wtf.beatrice.hidekobot.commands.base.CoinFlip;
import wtf.beatrice.hidekobot.commands.base.Trivia; import wtf.beatrice.hidekobot.commands.base.Trivia;
import wtf.beatrice.hidekobot.commands.base.UrbanDictionary; import wtf.beatrice.hidekobot.commands.base.UrbanDictionary;
@ -10,6 +12,8 @@ import wtf.beatrice.hidekobot.util.CommandUtil;
public class ButtonInteractionListener extends ListenerAdapter public class ButtonInteractionListener extends ListenerAdapter
{ {
private static final Logger LOGGER = LoggerFactory.getLogger(ButtonInteractionListener.class);
@Override @Override
public void onButtonInteraction(ButtonInteractionEvent event) public void onButtonInteraction(ButtonInteractionEvent event)
{ {
@ -31,6 +35,10 @@ public class ButtonInteractionListener extends ListenerAdapter
case "trivia_wrong_1", "trivia_wrong_2", "trivia_wrong_3" -> case "trivia_wrong_1", "trivia_wrong_2", "trivia_wrong_3" ->
Trivia.handleAnswer(event, Trivia.AnswerType.WRONG); Trivia.handleAnswer(event, Trivia.AnswerType.WRONG);
// error handling
default -> LOGGER.warn("Received unhandled {}", event.getClass().getSimpleName());
} }
} }

View File

@ -2,11 +2,15 @@ package wtf.beatrice.hidekobot.listeners;
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wtf.beatrice.hidekobot.commands.base.Trivia; import wtf.beatrice.hidekobot.commands.base.Trivia;
public class SelectMenuInteractionListener extends ListenerAdapter public class SelectMenuInteractionListener extends ListenerAdapter
{ {
private static final Logger LOGGER = LoggerFactory.getLogger(SelectMenuInteractionListener.class);
@Override @Override
public void onStringSelectInteraction(StringSelectInteractionEvent event) public void onStringSelectInteraction(StringSelectInteractionEvent event)
{ {
@ -14,6 +18,9 @@ public class SelectMenuInteractionListener extends ListenerAdapter
// trivia // trivia
case "trivia_categories" -> Trivia.handleMenuSelection(event); case "trivia_categories" -> Trivia.handleMenuSelection(event);
// error handling
default -> LOGGER.warn("Received unhandled {}", event.getClass().getSimpleName());
} }
} }
} }

View File

@ -148,7 +148,7 @@ public class FormatUtil
// we won't do any sanitization, because this is a private method, and // we won't do any sanitization, because this is a private method, and
// we are only accessing it with things that we know for sure are already sanitized. // we are only accessing it with things that we know for sure are already sanitized.
unitName = unitName.toLowerCase(); unitName = unitName.toLowerCase();
TemporalUnit timeUnit = null; TemporalUnit timeUnit;
/* /*
parsing table parsing table
@ -166,6 +166,7 @@ public class FormatUtil
case "m", "mi", "min", "minute", "minutes" -> timeUnit = ChronoUnit.MINUTES; case "m", "mi", "min", "minute", "minutes" -> timeUnit = ChronoUnit.MINUTES;
case "h", "ho", "hr", "hour", "hours" -> timeUnit = ChronoUnit.HOURS; case "h", "ho", "hr", "hour", "hours" -> timeUnit = ChronoUnit.HOURS;
case "d", "day", "days" -> timeUnit = ChronoUnit.DAYS; case "d", "day", "days" -> timeUnit = ChronoUnit.DAYS;
default -> timeUnit = null;
} }
return timeUnit; return timeUnit;