don't make accounts for bots
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 39s

This commit is contained in:
Lee 2024-07-03 22:59:05 +01:00
parent a7a7bc784b
commit 5f75302f3a

View File

@ -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