Merge pull request #640 from BigBotNetwork/greg-dev

Prevent error in getByID function
This commit is contained in:
Skidder 2021-03-29 00:15:21 +02:00 committed by GitHub
commit 6c8b697455
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Hadder</groupId>
<artifactId>Hadder</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
<name>Hadder</name>
<inceptionYear>2019</inceptionYear>
<description>Hadder is a multi-purpose Discord bot.</description>

View file

@ -43,7 +43,11 @@ public class Mongo {
BasicDBObject whereQuery = new BasicDBObject();
whereQuery.put(where, what);
FindIterable<Document> it = collection.find(whereQuery);
return it.cursor().next().get(column);
try {
return it.cursor().next().get(column);
} catch (NoSuchElementException ignore) {
return null;
}
}
public JSONObject getObjectByID(String collection, String id) {
@ -133,8 +137,7 @@ public class Mongo {
}
public boolean hasStarboardMessage(String message_id) {
this.getByID("stars", "id", message_id, "guild");
return true;
return this.getByID("stars", "id", message_id, "guild") != null;
}
public void insertStarboardMessage(String message_id, String guild_id, String starboard_message_id) {