Implement various null checks
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -61,9 +61,13 @@ public class Trivia
|
||||
|
||||
public static MessageResponse generateMainScreen()
|
||||
{
|
||||
// todo null checks
|
||||
JSONObject categoriesJson = Trivia.fetchJson(Trivia.getCategoriesLink());
|
||||
if(categoriesJson == null)
|
||||
return new MessageResponse("Error fetching trivia!", null); // todo nicer with emojis
|
||||
List<TriviaCategory> categories = Trivia.parseCategories(categoriesJson);
|
||||
if(categories.isEmpty())
|
||||
return new MessageResponse("Error parsing trivia categories!", null); // todo nicer with emojis
|
||||
|
||||
categories.sort(new TriviaCategoryComparator());
|
||||
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
|
@@ -166,6 +166,7 @@ public class UserPunishment
|
||||
Duration duration = null;
|
||||
|
||||
AuditableRestAction<Void> punishmentAction = null;
|
||||
boolean impossible = false;
|
||||
|
||||
try {
|
||||
switch (punishmentType) {
|
||||
@@ -197,6 +198,14 @@ public class UserPunishment
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException ignored) {
|
||||
impossible = true;
|
||||
}
|
||||
|
||||
if(punishmentAction == null)
|
||||
impossible = true;
|
||||
|
||||
if(impossible)
|
||||
{
|
||||
// todo nicer looking with emojis
|
||||
return new MessageResponse("Sorry, I couldn't " + punishmentTypeName + " " + mentioned.getAsMention() + "!",
|
||||
null);
|
||||
|
Reference in New Issue
Block a user