Skip to content

Commit

Permalink
Merge branch 'v1.7.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jul 27, 2023
2 parents 5f2ce3c + f0a3ef0 commit 2e97b06
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.7.0] - 2023-07-27

### Added

- Added multi-guild support. Suggestion primary key is now composite of ID and guild ID.

## [1.6.3] - 2023-07-27

### Added
Expand Down Expand Up @@ -123,6 +129,9 @@ implemented, accepted, or rejected.

- Initial release.

[1.7.0]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.7.0
[1.6.3]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.6.3
[1.6.2]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.6.2
[1.6.1]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.6.1
[1.6.0]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.6.0
[1.5.1]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.5.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class SuggestionConfiguration : IEntityTypeConfiguration<Suggest
/// <inheritdoc />
public void Configure(EntityTypeBuilder<Suggestion> builder)
{
builder.HasKey(e => e.Id);
builder.HasKey(e => new { e.GuildId, e.Id });

builder.Property(e => e.Id).IsRequired();
builder.Property(e => e.AuthorId).IsRequired();
Expand Down
23 changes: 23 additions & 0 deletions SuggestionBot/Services/SuggestionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public Suggestion CreateSuggestion(DiscordMember member, string content)

var suggestion = new Suggestion
{
Id = GetNextId(guildId),
AuthorId = member.Id,
Content = content,
GuildId = guildId
Expand Down Expand Up @@ -207,6 +208,28 @@ public DateTimeOffset GetLastSuggestionTime(DiscordMember member)
return userSuggestions.Length == 0 ? DateTimeOffset.MinValue : userSuggestions.Max(s => s.Timestamp);
}

/// <summary>
/// Gets the next available suggestion ID for the specified guild.
/// </summary>
/// <param name="guildId">The ID of the guild.</param>
/// <returns>The next available suggestion ID.</returns>
public long GetNextId(ulong guildId)
{
if (!_suggestions.TryGetValue(guildId, out List<Suggestion>? suggestions))
{
return 1;
}

long nextId = suggestions.Max(s => s.Id) + 1;

while (TryGetSuggestion(guildId, nextId, out _))
{
nextId++;
}

return nextId;
}

/// <summary>
/// Gets all suggestions made by the specified member.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion SuggestionBot/SuggestionBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<VersionPrefix>1.6.3</VersionPrefix>
<VersionPrefix>1.7.0</VersionPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down

0 comments on commit 2e97b06

Please sign in to comment.