Bat/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java

50 lines
1.8 KiB
Java
Raw Normal View History

2024-06-26 12:19:11 +01:00
package cc.fascinated.bat.features.birthday;
2024-06-27 16:01:27 +01:00
import cc.fascinated.bat.command.Category;
2024-06-30 01:03:10 +01:00
import cc.fascinated.bat.event.EventListener;
2024-06-26 12:19:11 +01:00
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.birthday.command.BirthdayCommand;
import cc.fascinated.bat.features.birthday.profile.BirthdayProfile;
import cc.fascinated.bat.model.BatGuild;
2024-06-30 01:03:10 +01:00
import cc.fascinated.bat.model.BatUser;
2024-06-26 12:19:11 +01:00
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.GuildService;
import lombok.NonNull;
2024-06-30 01:03:10 +01:00
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
2024-06-26 12:19:11 +01:00
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component
2024-06-30 01:03:10 +01:00
public class BirthdayFeature extends Feature implements EventListener {
2024-06-26 12:19:11 +01:00
private final GuildService guildService;
public BirthdayFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) {
2024-06-27 16:24:08 +01:00
super("Birthday", Category.UTILITY);
2024-06-26 12:19:11 +01:00
this.guildService = guildService;
2024-06-27 16:01:27 +01:00
registerCommand(commandService, context.getBean(BirthdayCommand.class));
2024-06-26 12:19:11 +01:00
}
2024-06-30 01:03:10 +01:00
@Override
public void onGuildMemberLeave(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildMemberRemoveEvent event) {
BirthdayProfile profile = guild.getProfile(BirthdayProfile.class);
profile.removeBirthday(user.getId());
guildService.saveGuild(guild);
}
2024-06-26 12:19:11 +01:00
/**
* Check birthdays every day at midnight
*/
@Scheduled(cron = "0 1 0 * * *")
2024-06-26 12:19:11 +01:00
private void checkBirthdays() {
for (BatGuild guild : guildService.getAllGuilds()) {
BirthdayProfile profile = guild.getProfile(BirthdayProfile.class);
profile.checkBirthdays(guild);
}
}
}