forked from Fascinated/Bat
fix user leaving guild npe
This commit is contained in:
@ -50,6 +50,12 @@ 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()) {
|
||||
@ -83,7 +89,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,6 +7,7 @@ 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;
|
||||
@ -81,4 +82,10 @@ 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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user