-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
340 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.