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

Commit 6c8b697

Browse files
authored
Merge pull request #640 from BigBotNetwork/greg-dev
Prevent error in getByID function
2 parents 162efd0 + ca1dd18 commit 6c8b697

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>Hadder</groupId>
88
<artifactId>Hadder</artifactId>
9-
<version>2.0.0</version>
9+
<version>2.0.1</version>
1010
<name>Hadder</name>
1111
<inceptionYear>2019</inceptionYear>
1212
<description>Hadder is a multi-purpose Discord bot.</description>

src/main/java/one/bbn/hadder/db/Mongo.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public Object getByID(String collection_name, String where, String what, String
4343
BasicDBObject whereQuery = new BasicDBObject();
4444
whereQuery.put(where, what);
4545
FindIterable<Document> it = collection.find(whereQuery);
46-
return it.cursor().next().get(column);
46+
try {
47+
return it.cursor().next().get(column);
48+
} catch (NoSuchElementException ignore) {
49+
return null;
50+
}
4751
}
4852

4953
public JSONObject getObjectByID(String collection, String id) {
@@ -133,8 +137,7 @@ public void push(MongoUser user) {
133137
}
134138

135139
public boolean hasStarboardMessage(String message_id) {
136-
this.getByID("stars", "id", message_id, "guild");
137-
return true;
140+
return this.getByID("stars", "id", message_id, "guild") != null;
138141
}
139142

140143
public void insertStarboardMessage(String message_id, String guild_id, String starboard_message_id) {

0 commit comments

Comments
 (0)