All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m9s
50 lines
1.8 KiB
Java
50 lines
1.8 KiB
Java
package cc.fascinated.bat.features.birthday;
|
|
|
|
import cc.fascinated.bat.command.Category;
|
|
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.model.BatUser;
|
|
import cc.fascinated.bat.service.CommandService;
|
|
import cc.fascinated.bat.service.GuildService;
|
|
import lombok.NonNull;
|
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
|
|
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", Category.UTILITY);
|
|
this.guildService = guildService;
|
|
|
|
registerCommand(commandService, context.getBean(BirthdayCommand.class));
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
/**
|
|
* Check birthdays every day at midnight
|
|
*/
|
|
@Scheduled(cron = "0 1 0 * * *")
|
|
private void checkBirthdays() {
|
|
for (BatGuild guild : guildService.getAllGuilds()) {
|
|
BirthdayProfile profile = guild.getProfile(BirthdayProfile.class);
|
|
profile.checkBirthdays(guild);
|
|
}
|
|
}
|
|
}
|