forked from Fascinated/Bat
Compare commits
No commits in common. "4bf099d25e7be081dd2c570a6e041f471b5b2791" and "87bf0b9f67f5c99c35af5581ca5ff6da36330b2c" have entirely different histories.
4bf099d25e
...
87bf0b9f67
@ -38,10 +38,10 @@ public abstract class ProfileHolder {
|
||||
Serializable profile = getProfiles().get(clazz.getSimpleName());
|
||||
if (profile == null) {
|
||||
T newProfile = clazz.cast(clazz.getDeclaredConstructors()[0].newInstance());
|
||||
Document profiles = document.get("profiles", new org.bson.Document());
|
||||
Document profileDocument = (Document) profiles.get(clazz.getSimpleName());
|
||||
org.bson.Document profiles = document.get("profiles", new org.bson.Document());
|
||||
org.bson.Document profileDocument = profiles.isEmpty() ? new org.bson.Document() : profiles.get(clazz.getSimpleName(), new org.bson.Document());
|
||||
|
||||
newProfile.load(profileDocument == null ? new Document() : profileDocument, BatApplication.GSON);
|
||||
newProfile.load(profileDocument, BatApplication.GSON);
|
||||
getProfiles().put(clazz.getSimpleName(), newProfile);
|
||||
return newProfile;
|
||||
}
|
||||
|
@ -43,11 +43,6 @@ public class BatUser extends ProfileHolder {
|
||||
@Id
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* The global name of the user
|
||||
*/
|
||||
private String globalName;
|
||||
|
||||
/**
|
||||
* The time this user was created
|
||||
*/
|
||||
@ -58,18 +53,13 @@ public class BatUser extends ProfileHolder {
|
||||
this.document = document;
|
||||
boolean newAccount = this.document.isEmpty();
|
||||
this.createdAt = newAccount ? new Date() : document.getDate("createdAt");
|
||||
|
||||
User user = DiscordService.JDA.getUserById(id);
|
||||
if (user != null) {
|
||||
this.globalName = user.getGlobalName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the user
|
||||
*/
|
||||
public String getName() {
|
||||
return this.getGlobalName();
|
||||
return getDiscordUser().getEffectiveName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,7 +121,7 @@ public class PremiumProfile extends Serializable {
|
||||
Document document = new Document();
|
||||
document.put("activatedAt", this.activatedAt);
|
||||
document.put("expiresAt", this.expiresAt);
|
||||
document.put("type", this.type != null ? this.type.name() : null);
|
||||
document.put("type", this.type.name());
|
||||
return document;
|
||||
}
|
||||
|
||||
|
@ -50,12 +50,6 @@ public class GuildService extends ListenerAdapter implements EventListener {
|
||||
DiscordService.JDA.addEventListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the premium status of all guilds
|
||||
* <p>
|
||||
* This method is scheduled to run every day at midnight
|
||||
* </p>
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 * * *")
|
||||
private void validatePremiumStatus() {
|
||||
for (BatGuild guild : guilds.values()) {
|
||||
@ -89,7 +83,7 @@ public class GuildService extends ListenerAdapter implements EventListener {
|
||||
if (document != null) {
|
||||
BatGuild guild = new BatGuild(id, document);
|
||||
guilds.put(id, guild);
|
||||
log.info("Loaded guild \"{}\" in {}ms", guild.getName(), System.currentTimeMillis() - before);
|
||||
log.info("Loaded guild \"{}\" in {}ms", guild.getName(),System.currentTimeMillis() - before);
|
||||
return guild;
|
||||
}
|
||||
// New guild
|
||||
|
@ -7,7 +7,6 @@ import com.mongodb.client.model.Filters;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent;
|
||||
import org.bson.Document;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
@ -82,10 +81,4 @@ public class UserService implements EventListener {
|
||||
}
|
||||
log.info("Saved all users.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserUpdateGlobalName(@NonNull BatUser user, String oldName, String newName, @NonNull UserUpdateGlobalNameEvent event) {
|
||||
log.info("User \"{}\" changed their name from \"{}\" to \"{}\"", user.getName(), oldName, newName);
|
||||
user.setGlobalName(newName);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user