forked from Fascinated/Bat
don't make accounts for bots
This commit is contained in:
parent
a7a7bc784b
commit
5f75302f3a
@ -8,6 +8,7 @@ import com.mongodb.client.model.Filters;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.extern.log4j.Log4j2;
|
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.guild.member.GuildMemberJoinEvent;
|
||||||
import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent;
|
import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
@ -57,23 +58,28 @@ public class UserService implements EventListener {
|
|||||||
if (users.containsKey(id)) {
|
if (users.containsKey(id)) {
|
||||||
return users.get(id);
|
return users.get(id);
|
||||||
}
|
}
|
||||||
if (DiscordService.JDA.getUserById(id) == null) {
|
User user = DiscordService.JDA.getUserById(id);
|
||||||
log.warn("Attempted to get user with ID \"{}\" but it does not exist", 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;
|
return null;
|
||||||
}
|
}
|
||||||
// User is not cached
|
// User is not cached
|
||||||
Document document = MongoService.INSTANCE.getUsersCollection().find(Filters.eq("_id", id)).first();
|
Document document = MongoService.INSTANCE.getUsersCollection().find(Filters.eq("_id", id)).first();
|
||||||
if (document != null) {
|
if (document != null) {
|
||||||
BatUser user = new BatUser(id, document);
|
BatUser batUser = new BatUser(id, document);
|
||||||
users.put(id, user);
|
users.put(id, batUser);
|
||||||
log.info("Loaded user \"{}\" in {}ms", user.getName(),System.currentTimeMillis() - before);
|
log.info("Loaded user \"{}\" in {}ms", batUser.getName(),System.currentTimeMillis() - before);
|
||||||
return user;
|
return batUser;
|
||||||
}
|
}
|
||||||
// New user
|
// New user
|
||||||
BatUser user = new BatUser(id, new Document());
|
BatUser batUser = new BatUser(id, new Document());
|
||||||
users.put(id, user);
|
users.put(id, batUser);
|
||||||
log.info("Created user \"{}\" - \"{}\"", user.getName(), user.getId());
|
log.info("Created user \"{}\" - \"{}\"", user.getName(), user.getId());
|
||||||
return user;
|
return batUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user