Skip to content

Commit

Permalink
Merge branch 'v1.8.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jul 28, 2023
2 parents 2e97b06 + 2f45a8f commit 81c3e5a
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 21 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ 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.8.0] - 2023-07-28

### Added

- Added `/suggestion stats` command to view the suggestion statistics.
- Added `/suggestion top` command to view the top-rated open suggestions.
- Suggestion votes are now cached.

### Changed

- Threads are now deleted, not archived, when a suggestion is closed.

## [1.7.0] - 2023-07-27

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

- Initial release.

[1.8.0]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.8.0
[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
Expand Down
1 change: 0 additions & 1 deletion SuggestionBot/Commands/SuggestionCommand.Remove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using DSharpPlus.SlashCommands;
using SuggestionBot.AutocompleteProviders;
using SuggestionBot.Data;
using X10D.DSharpPlus;

namespace SuggestionBot.Commands;

Expand Down
43 changes: 43 additions & 0 deletions SuggestionBot/Commands/SuggestionCommand.Stats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using SuggestionBot.Data;
using static SuggestionBot.Data.SuggestionStatus;

namespace SuggestionBot.Commands;

using MentionUtility = X10D.DSharpPlus.MentionUtility;

internal sealed partial class SuggestionCommand
{
[SlashCommand("stats", "View suggestion statistics.", false)]
public async Task StatsAsync(InteractionContext context)
{
await context.DeferAsync().ConfigureAwait(false);
var response = new DiscordWebhookBuilder();

IReadOnlyList<Suggestion> suggestions = _suggestionService.GetSuggestions(context.Guild);
int totalSuggestions = suggestions.Count;
int openCounts = suggestions.Count(s => s.Status == Suggested);
int rejectedCount = suggestions.Count(s => s.Status == Rejected);
int implementedCount = suggestions.Count(s => s.Status is Implemented or AlreadyImplemented);
int removedCount = suggestions.Count(s => s.Status == Removed);
ulong highestContributor = suggestions
.GroupBy(s => s.AuthorId)
.OrderByDescending(g => g.Count())
.Select(g => g.Key)
.FirstOrDefault();

var embed = new DiscordEmbedBuilder();
embed.WithColor(DiscordColor.Blurple);
embed.WithTitle("Suggestion Statistics");
embed.AddField("Total", $"{totalSuggestions:N0}", true);
embed.AddField("Open", $"{openCounts:N0}", true);
embed.AddField("Rejected", $"{rejectedCount:N0}", true);
embed.AddField("Implemented", $"{implementedCount:N0}", true);
embed.AddField("Removed", $"{removedCount:N0}", true);
embed.AddField("Highest Contributor", MentionUtility.MentionUser(highestContributor), true);

response.AddEmbed(embed);
await context.EditResponseAsync(response).ConfigureAwait(false);
}
}
48 changes: 48 additions & 0 deletions SuggestionBot/Commands/SuggestionCommand.Top.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Text;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using SuggestionBot.Data;

namespace SuggestionBot.Commands;

using MentionUtility = X10D.DSharpPlus.MentionUtility;

internal sealed partial class SuggestionCommand
{
[SlashCommand("top", "Views the top rated suggestions.", false)]
public async Task TopAsync(InteractionContext context,
[Option("count", "The number of suggestions to return.")]
long count = 10)
{
await context.DeferAsync().ConfigureAwait(false);
var response = new DiscordWebhookBuilder();
var embed = new DiscordEmbedBuilder();

IReadOnlyList<Suggestion> topSuggestions = _suggestionService.GetTopSuggestions(context.Guild, (int)count);
if (topSuggestions.Count == 0)
{
embed.WithColor(DiscordColor.Red);
embed.WithTitle("Top Suggestions");
embed.WithDescription("⚠️ No open suggestions were found in this guild that match the criteria.");

response.AddEmbed(embed);
await context.EditResponseAsync(response).ConfigureAwait(false);
return;
}

var builder = new StringBuilder();
foreach (Suggestion suggestion in topSuggestions)
{
var messageLink = _suggestionService.GetSuggestionLink(suggestion).ToString();
string author = MentionUtility.MentionUser(suggestion.AuthorId);
builder.AppendLine($"• **{suggestion.Id} by {author}** ({suggestion.Score:+#;-#;0}) {messageLink}");
}

embed.WithColor(DiscordColor.Blurple);
embed.WithTitle("Top Suggestions");
embed.WithDescription($"__{topSuggestions.Count:N0} results__\n\n{builder}");

response.AddEmbed(embed);
await context.EditResponseAsync(response).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ public void Configure(EntityTypeBuilder<Suggestion> builder)
builder.Property(e => e.ThreadId);
builder.Property(e => e.StaffMemberId);
builder.Property(e => e.Remarks);
builder.Property(e => e.UpVotes);
builder.Property(e => e.DownVotes);
}
}
23 changes: 22 additions & 1 deletion SuggestionBot/Data/Suggestion.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SuggestionBot.Data;
using System.ComponentModel.DataAnnotations.Schema;

namespace SuggestionBot.Data;

/// <summary>
/// Represents a suggestion.
Expand All @@ -11,6 +13,12 @@ public sealed class Suggestion
/// <value>The author ID.</value>
public ulong AuthorId { get; set; }

/// <summary>
/// Gets or sets the number of down-votes the suggestion has.
/// </summary>
/// <value>The number of down-votes.</value>
public int DownVotes { get; set; }

/// <summary>
/// Gets or sets the content of the suggestion.
/// </summary>
Expand Down Expand Up @@ -40,6 +48,13 @@ public sealed class Suggestion
/// <value>The remarks.</value>
public string? Remarks { get; set; }

/// <summary>
/// Gets the score of the suggestion.
/// </summary>
/// <value>The score.</value>
[NotMapped]
public int Score => UpVotes - DownVotes;

/// <summary>
/// Gets or sets the ID of the staff member who implemented or rejected the suggestion.
/// </summary>
Expand All @@ -63,4 +78,10 @@ public sealed class Suggestion
/// </summary>
/// <value>The suggestion timestamp.</value>
public DateTimeOffset Timestamp { get; set; } = DateTimeOffset.UtcNow;

/// <summary>
/// Gets or sets the number of up-votes the suggestion has.
/// </summary>
/// <value>The number of up-votes.</value>
public int UpVotes { get; set; }
}
Loading

0 comments on commit 81c3e5a

Please sign in to comment.