Skip to content

Commit

Permalink
refactor: better use of Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
christolis committed May 17, 2024
1 parent 0502f83 commit e98eb35
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ public CakeDayService(Config config, Database database) {
}

private Optional<Role> getCakeDayRole(Guild guild) {
Role cakeDayRole = getCakeDayRoleFromGuild(guild).orElse(null);
Optional<Role> cakeDayRole = getCakeDayRoleFromGuild(guild);

if (cakeDayRole == null) {
if (cakeDayRole.isEmpty()) {
logger.warn("Cake day role with pattern {} not found for guild: {}",
config.rolePattern(), guild.getName());
return Optional.empty();
}

return Optional.of(cakeDayRole);
return cakeDayRole;
}

/**
Expand Down Expand Up @@ -132,13 +131,13 @@ private void addTodayMembersCakeDayRole(Guild guild) {
protected void addCakeDayRole(Member member) {
Guild guild = member.getGuild();
UserSnowflake snowflake = UserSnowflake.fromId(member.getId());
Role cakeDayRole = getCakeDayRole(guild).orElse(null);
Optional<Role> cakeDayRole = getCakeDayRole(guild);

if (cakeDayRole == null) {
if (cakeDayRole.isEmpty()) {
return;
}

guild.addRoleToMember(snowflake, cakeDayRole).complete();
guild.addRoleToMember(snowflake, cakeDayRole.get()).complete();
}

/**
Expand Down

0 comments on commit e98eb35

Please sign in to comment.