forked from Fascinated/Bat
don't remove birthdays for members that have left
This commit is contained in:
parent
be7f8a9057
commit
c1f9bfec6a
@ -31,12 +31,6 @@ public class BirthdayFeature extends Feature implements EventListener {
|
||||
registerCommand(commandService, context.getBean(BirthdayCommand.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildMemberLeave(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildMemberRemoveEvent event) {
|
||||
BirthdayProfile profile = guild.getBirthdayProfile();
|
||||
profile.removeBirthday(user.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check birthdays every day at midnight
|
||||
*/
|
||||
@ -49,7 +43,6 @@ public class BirthdayFeature extends Feature implements EventListener {
|
||||
}
|
||||
BirthdayProfile profile = batGuild.getBirthdayProfile();
|
||||
profile.checkBirthdays(batGuild);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,33 +96,10 @@ public class BirthdayProfile extends Serializable {
|
||||
if (birthdays == null) {
|
||||
birthdays = new HashMap<>();
|
||||
}
|
||||
|
||||
List<String> toRemove = new ArrayList<>();
|
||||
Guild discordGuild = guild.getDiscordGuild();
|
||||
for (Map.Entry<String, UserBirthday> entry : birthdays.entrySet()) {
|
||||
String userId = entry.getKey();
|
||||
Date birthday = entry.getValue().getBirthday();
|
||||
|
||||
if (userId == null || birthday == null) { // this should never happen
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if the user is still in the guild, if not remove them
|
||||
Member member = discordGuild.getMemberById(userId);
|
||||
if (member == null) {
|
||||
toRemove.add(userId);
|
||||
}
|
||||
}
|
||||
|
||||
for (String userId : toRemove) {
|
||||
birthdays.remove(userId);
|
||||
}
|
||||
|
||||
if (channelId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (discordGuild.getTextChannelById(channelId) == null) {
|
||||
if (guild.getDiscordGuild().getTextChannelById(channelId) == null) {
|
||||
channelId = null;
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user