Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #640 from BigBotNetwork/greg-dev
Browse files Browse the repository at this point in the history
Prevent error in getByID function
  • Loading branch information
greg6775 authored Mar 28, 2021
2 parents 162efd0 + ca1dd18 commit 6c8b697
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/one/bbn/hadder/db/Mongo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public Object getByID(String collection_name, String where, String what, String
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) {
Expand Down Expand Up @@ -133,8 +137,7 @@ public void push(MongoUser user) {
}

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) {
Expand Down

0 comments on commit 6c8b697

Please sign in to comment.