From a001f2dd4c91074b17571e4cda1221576693c5af Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 1 Jul 2024 01:41:40 +0100 Subject: [PATCH] add valid guild and user id check --- src/main/java/cc/fascinated/bat/service/GuildService.java | 4 ++++ src/main/java/cc/fascinated/bat/service/UserService.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/cc/fascinated/bat/service/GuildService.java b/src/main/java/cc/fascinated/bat/service/GuildService.java index 411e4c5..205cf8b 100644 --- a/src/main/java/cc/fascinated/bat/service/GuildService.java +++ b/src/main/java/cc/fascinated/bat/service/GuildService.java @@ -74,6 +74,10 @@ public class GuildService extends ListenerAdapter implements EventListener { if (guilds.containsKey(id)) { return guilds.get(id); } + if (DiscordService.JDA.getGuildById(id) == null) { + log.warn("Attempted to get guild with ID \"{}\" but it does not exist", id); + return null; + } // Guild is not cached Document document = MongoService.INSTANCE.getGuildsCollection().find(Filters.eq("_id", id)).first(); if (document != null) { diff --git a/src/main/java/cc/fascinated/bat/service/UserService.java b/src/main/java/cc/fascinated/bat/service/UserService.java index 2318bf8..7fa3720 100644 --- a/src/main/java/cc/fascinated/bat/service/UserService.java +++ b/src/main/java/cc/fascinated/bat/service/UserService.java @@ -54,6 +54,10 @@ public class UserService implements EventListener { if (users.containsKey(id)) { return users.get(id); } + if (DiscordService.JDA.getUserById(id) == null) { + log.warn("Attempted to get user with ID \"{}\" but it does not exist", id); + return null; + } // User is not cached Document document = MongoService.INSTANCE.getUsersCollection().find(Filters.eq("_id", id)).first(); if (document != null) {