From 727a4c9a6f381bb36b7a71bbaa4a1f3a48abe934 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 1 Jul 2024 19:41:13 +0100 Subject: [PATCH] set name when user joins guild --- src/main/java/cc/fascinated/bat/service/UserService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/cc/fascinated/bat/service/UserService.java b/src/main/java/cc/fascinated/bat/service/UserService.java index 2c400a2..f31b61f 100644 --- a/src/main/java/cc/fascinated/bat/service/UserService.java +++ b/src/main/java/cc/fascinated/bat/service/UserService.java @@ -2,11 +2,13 @@ package cc.fascinated.bat.service; import cc.fascinated.bat.common.TimerUtils; import cc.fascinated.bat.event.EventListener; +import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; import com.mongodb.client.model.Filters; import lombok.Getter; import lombok.NonNull; import lombok.extern.log4j.Log4j2; +import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent; import org.bson.Document; import org.springframework.beans.factory.annotation.Autowired; @@ -83,6 +85,11 @@ public class UserService implements EventListener { log.info("Saved all users."); } + @Override + public void onGuildMemberJoin(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildMemberJoinEvent event) { + user.setGlobalName(event.getUser().getName()); // Ensure the user's name is up-to-date + } + @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);