Skip to content

Commit

Permalink
fix: fix users who haven't used the command not being able to use it
Browse files Browse the repository at this point in the history
Rookie mistake. Max throws on empty set.
  • Loading branch information
oliverbooth committed Jul 21, 2023
1 parent c95d099 commit 918499a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions SuggestionBot/Services/SuggestionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public DateTimeOffset GetLastSuggestionTime(DiscordGuild guild, DiscordUser user
return DateTimeOffset.MinValue;
}

return suggestions.Where(s => s.GuildId == guild.Id && s.AuthorId == user.Id).Max(s => s.Timestamp);
Suggestion[] userSuggestions = suggestions.Where(s => s.GuildId == guild.Id && s.AuthorId == user.Id).ToArray();
return userSuggestions.Length == 0 ? DateTimeOffset.MinValue : userSuggestions.Max(s => s.Timestamp);
}

/// <summary>
Expand Down Expand Up @@ -217,7 +218,7 @@ public async Task UpdateSuggestionAsync(Suggestion suggestion)

if (!_discordClient.Guilds.TryGetValue(suggestion.GuildId, out DiscordGuild? guild)) return;
if (!_configurationService.TryGetGuildConfiguration(guild, out GuildConfiguration? configuration)) return;

DiscordChannel? channel = guild.GetChannel(configuration.SuggestionChannel);
if (channel is null) return;

Expand Down

0 comments on commit 918499a

Please sign in to comment.