From 5f75302f3afadb81b6a973eedb752268b54f05c7 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 3 Jul 2024 22:59:05 +0100 Subject: [PATCH] don't make accounts for bots --- .../fascinated/bat/service/UserService.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/service/UserService.java b/src/main/java/cc/fascinated/bat/service/UserService.java index 69331c6..9f21057 100644 --- a/src/main/java/cc/fascinated/bat/service/UserService.java +++ b/src/main/java/cc/fascinated/bat/service/UserService.java @@ -8,6 +8,7 @@ import com.mongodb.client.model.Filters; import lombok.Getter; import lombok.NonNull; import lombok.extern.log4j.Log4j2; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent; import org.bson.Document; @@ -57,23 +58,28 @@ 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); + User user = DiscordService.JDA.getUserById(id); + if (user == null) { + log.warn("Attempted to get user with ID \"{}\" but they do not exist", id); + return null; + } + if (user.isBot()) { + log.warn("Attempted to get user with ID \"{}\" but they are a bot", id); return null; } // User is not cached Document document = MongoService.INSTANCE.getUsersCollection().find(Filters.eq("_id", id)).first(); if (document != null) { - BatUser user = new BatUser(id, document); - users.put(id, user); - log.info("Loaded user \"{}\" in {}ms", user.getName(),System.currentTimeMillis() - before); - return user; + BatUser batUser = new BatUser(id, document); + users.put(id, batUser); + log.info("Loaded user \"{}\" in {}ms", batUser.getName(),System.currentTimeMillis() - before); + return batUser; } // New user - BatUser user = new BatUser(id, new Document()); - users.put(id, user); + BatUser batUser = new BatUser(id, new Document()); + users.put(id, batUser); log.info("Created user \"{}\" - \"{}\"", user.getName(), user.getId()); - return user; + return batUser; } @Override