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;
|
|
|
|
import cc.fascinated.bat.service.CommandService;
|
2024-07-01 15:16:06 +01:00
|
|
|
import cc.fascinated.bat.service.DiscordService;
|
2024-06-26 12:19:11 +01:00
|
|
|
import cc.fascinated.bat.service.GuildService;
|
|
|
|
import lombok.NonNull;
|
2024-07-01 15:16:06 +01:00
|
|
|
import net.dv8tion.jda.api.entities.Guild;
|
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-30 08:00:03 +01:00
|
|
|
super("Birthday", true, 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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check birthdays every day at midnight
|
|
|
|
*/
|
2024-06-30 00:35:52 +01:00
|
|
|
@Scheduled(cron = "0 1 0 * * *")
|
2024-06-26 12:19:11 +01:00
|
|
|
private void checkBirthdays() {
|
2024-07-01 15:16:06 +01:00
|
|
|
for (Guild guild : DiscordService.JDA.getGuilds()) {
|
|
|
|
BatGuild batGuild = guildService.getGuild(guild.getId());
|
|
|
|
if (batGuild == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
BirthdayProfile profile = batGuild.getBirthdayProfile();
|
|
|
|
profile.checkBirthdays(batGuild);
|
2024-06-26 12:19:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|