Bat/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java
Liam 0d9b6ed8f8
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 47s
oops, cleanup imports
2024-07-04 14:21:30 +01:00

46 lines
1.6 KiB
Java

package cc.fascinated.bat.features.birthday;
import cc.fascinated.bat.event.EventListener;
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;
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", 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 == null) {
continue;
}
BirthdayProfile profile = batGuild.getBirthdayProfile();
profile.checkBirthdays(batGuild);
}
}
}