package cc.fascinated.bat.features.birthday; import cc.fascinated.bat.event.EventListener; import cc.fascinated.bat.features.Feature; import cc.fascinated.bat.features.FeatureProfile; import cc.fascinated.bat.features.birthday.command.BirthdayCommand; import cc.fascinated.bat.features.birthday.profile.BirthdayProfile; import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.service.CommandService; import cc.fascinated.bat.service.DiscordService; import cc.fascinated.bat.service.GuildService; import lombok.NonNull; import net.dv8tion.jda.api.entities.Guild; import org.springframework.context.ApplicationContext; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; /** * @author Fascinated (fascinated7) */ @Component public class BirthdayFeature extends Feature implements EventListener { private final GuildService guildService; public BirthdayFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) { super("Birthday", FeatureProfile.FeatureState.DISABLED, true); this.guildService = guildService; registerCommand(commandService, context.getBean(BirthdayCommand.class)); } /** * Check birthdays every day at midnight */ @Scheduled(cron = "0 1 0 * * *") private void checkBirthdays() { for (Guild guild : DiscordService.JDA.getGuilds()) { BatGuild batGuild = guildService.getGuild(guild.getId()); if (batGuild.getFeatureProfile().isFeatureDisabled(this)) { // Check if the feature is disabled continue; } BirthdayProfile profile = batGuild.getBirthdayProfile(); profile.checkBirthdays(batGuild); } } }