Skip to content

Commit

Permalink
Merge branch 'v1.6.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jul 24, 2023
2 parents 732ae5d + 0b4c8ac commit 102a4b4
Show file tree
Hide file tree
Showing 16 changed files with 467 additions and 28 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.6.0] - 2023-07-24

### Added

- Added optional staff remarks to suggestion embeds.
- Staff can now remove suggestions.

### Changed

- `/suggestion view` now uses the same search logic as `/suggestion setstatus`.
- Suggestion updates are now sent to the author.

## [1.5.1] - 2023-07-24

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

- Initial release.

[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
[1.5.0]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.5.0
[1.4.0]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public Task<IEnumerable<DiscordAutoCompleteChoice>> Provider(AutocompleteContext
for (var index = 0; index < count; index++)
{
Suggestion suggestion = suggestions[index];
if (suggestion.Status == SuggestionStatus.Removed)
{
continue;
}

DiscordUser author = suggestionService.GetAuthor(suggestion);
string[] contentWords = suggestion.Content.Split();

Expand Down
46 changes: 46 additions & 0 deletions SuggestionBot/Commands/SuggestionCommand.Remove.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using SuggestionBot.AutocompleteProviders;
using SuggestionBot.Data;
using X10D.DSharpPlus;

namespace SuggestionBot.Commands;

internal sealed partial class SuggestionCommand
{
[SlashCommand("remove", "Remove a suggestion.", false)]
public async Task RemoveAsync(InteractionContext context,
[Option("suggestion", "The suggestion whose status to change.")]
[Autocomplete(typeof(SuggestionAutocompleteProvider))]
string query,
[Option("remarks", "Additional remarks about the suggestion.")]
string? remarks = null)
{
var response = new DiscordInteractionResponseBuilder();

if (!TryGetSuggestion(context.Guild, query, out Suggestion? suggestion))
{
response.AsEphemeral();
response.AddEmbed(CreateNotFoundEmbed(query));
await context.CreateResponseAsync(ResponseType, response).ConfigureAwait(false);
return;
}

var embed = new DiscordEmbedBuilder();
if (_suggestionService.SetStatus(suggestion, SuggestionStatus.Removed, context.Member, remarks))
{
embed.WithColor(DiscordColor.Red);
embed.WithTitle("Suggestion Removed");
embed.WithDescription($"The suggestion with the ID {suggestion.Id} has been REMOVED.");
if (!string.IsNullOrWhiteSpace(remarks))
{
embed.AddField("Staff Remarks", remarks);
}

await _mailmanService.SendSuggestionAsync(suggestion).ConfigureAwait(false);
}

response.AddEmbed(embed);
await context.CreateResponseAsync(ResponseType, response).ConfigureAwait(false);
}
}
15 changes: 12 additions & 3 deletions SuggestionBot/Commands/SuggestionCommand.SetStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ public async Task SetStatusAsync(InteractionContext context,
[Autocomplete(typeof(SuggestionAutocompleteProvider))]
string query,
[Option("status", "The new status of the suggestion.")]
SuggestionStatus status)
SuggestionStatus status,
[Option("remarks", "Additional remarks about the suggestion.")]
string? remarks = null)
{
var response = new DiscordInteractionResponseBuilder();

if (!TryGetSuggestion(context.Guild, query, out Suggestion? suggestion))
if (!TryGetSuggestion(context.Guild, query, out Suggestion? suggestion) ||
suggestion.Status == SuggestionStatus.Removed)
{
response.AsEphemeral();
response.AddEmbed(CreateNotFoundEmbed(query));
Expand All @@ -32,11 +35,17 @@ public async Task SetStatusAsync(InteractionContext context,

string humanizedStatus = status.Humanize(LetterCasing.AllCaps);

if (_suggestionService.SetStatus(suggestion, status, context.Member))
if (_suggestionService.SetStatus(suggestion, status, context.Member, remarks))
{
embed.WithColor(DiscordColor.Orange);
embed.WithTitle("Suggestion Status Changed");
embed.WithDescription($"The suggestion with the ID {suggestion.Id} has been marked as {humanizedStatus}.");
if (!string.IsNullOrWhiteSpace(remarks))
{
embed.AddField("Staff Remarks", remarks);
}

await _mailmanService.SendSuggestionAsync(suggestion).ConfigureAwait(false);
}
else
{
Expand Down
26 changes: 7 additions & 19 deletions SuggestionBot/Commands/SuggestionCommand.View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,17 @@ public async Task ViewAsync(InteractionContext context,
[Autocomplete(typeof(SuggestionAutocompleteProvider))]
string query)
{
Suggestion? suggestion = null;

ulong guildId = context.Guild.Id;
if (ulong.TryParse(query, out ulong messageId) &&
_suggestionService.TryGetSuggestion(guildId, messageId, out suggestion))
{
}
else if (long.TryParse(query, out long id) && _suggestionService.TryGetSuggestion(guildId, id, out suggestion))
{
}

var builder = new DiscordInteractionResponseBuilder();

if (suggestion is null)
var response = new DiscordInteractionResponseBuilder();
if (!TryGetSuggestion(context.Guild, query, out Suggestion? suggestion))
{
builder.WithContent($"The suggestion with ID {query} does not exist.");
builder.AsEphemeral();
await context.CreateResponseAsync(ResponseType, builder).ConfigureAwait(false);
response.AsEphemeral();
response.AddEmbed(CreateNotFoundEmbed(query));
await context.CreateResponseAsync(ResponseType, response).ConfigureAwait(false);
return;
}

DiscordEmbed embed = _suggestionService.CreatePrivateEmbed(suggestion);
builder.AddEmbed(embed);
await context.CreateResponseAsync(ResponseType, builder).ConfigureAwait(false);
response.AddEmbed(embed);
await context.CreateResponseAsync(ResponseType, response).ConfigureAwait(false);
}
}
7 changes: 6 additions & 1 deletion SuggestionBot/Commands/SuggestionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ internal sealed partial class SuggestionCommand : ApplicationCommandModule

private readonly SuggestionService _suggestionService;
private readonly UserBlockingService _userBlockingService;
private readonly MailmanService _mailmanService;

/// <summary>
/// Initializes a new instance of the <see cref="SuggestionCommand" /> class.
/// </summary>
/// <param name="suggestionService">The <see cref="SuggestionService" />.</param>
/// <param name="userBlockingService">The <see cref="UserBlockingService" />.</param>
public SuggestionCommand(SuggestionService suggestionService, UserBlockingService userBlockingService)
/// <param name="mailmanService">The <see cref="MailmanService" />.</param>
public SuggestionCommand(SuggestionService suggestionService,
UserBlockingService userBlockingService,
MailmanService mailmanService)
{
_suggestionService = suggestionService;
_userBlockingService = userBlockingService;
_mailmanService = mailmanService;
}

private static DiscordEmbed CreateNotFoundEmbed(string query)
Expand Down
6 changes: 6 additions & 0 deletions SuggestionBot/Configuration/GuildConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public sealed class GuildConfiguration
/// <value>The embed color for rejected suggestions.</value>
public int RejectedColor { get; set; } = 0xFF0000;

/// <summary>
/// Gets or sets the embed color for removed suggestions.
/// </summary>
/// <value>The embed color for removed suggestions.</value>
public int RemovedColor { get; set; } = 0xFF0000;

/// <summary>
/// Gets or sets the channel ID for posting suggestions.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public void Configure(EntityTypeBuilder<Suggestion> builder)
builder.Property(e => e.Timestamp).IsRequired();
builder.Property(e => e.ThreadId);
builder.Property(e => e.StaffMemberId);
builder.Property(e => e.Remarks);
}
}
6 changes: 6 additions & 0 deletions SuggestionBot/Data/Suggestion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public sealed class Suggestion
/// <value>The message ID.</value>
public ulong MessageId { get; set; }

/// <summary>
/// Gets or sets the additional remarks about the suggestion.
/// </summary>
/// <value>The remarks.</value>
public string? Remarks { get; set; }

/// <summary>
/// Gets or sets the ID of the staff member who implemented or rejected the suggestion.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion SuggestionBot/Data/SuggestionStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public enum SuggestionStatus
Suggested,
Rejected,
Implemented,
Accepted
Accepted,
Removed
}
1 change: 1 addition & 0 deletions SuggestionBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
builder.Services.AddSingleton<CooldownService>();
builder.Services.AddHostedSingleton<SuggestionService>();
builder.Services.AddHostedSingleton<UserBlockingService>();
builder.Services.AddSingleton<MailmanService>();
builder.Services.AddHostedSingleton<BotService>();

IHost app = builder.Build();
Expand Down
110 changes: 110 additions & 0 deletions SuggestionBot/Resources/PrivateMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions SuggestionBot/Resources/PrivateMessages.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>

<data name="RemovedDescription" xml:space="preserve">
<value>{user.Mention}, your suggestion in **{guild.Name}** has been removed by staff because it was inappropriate or violated our server rules.
Repeated abuse will result in you losing access to the channel.

If you have any further questions, please reach us by sending a DM to ModMail.</value>
</data>

<data name="RejectedDescription" xml:space="preserve">
<value>Hi {user.Mention}. Unfortunately, your suggestion in **{guild.Name}** has been rejected by staff at this time.
Keep in mind that while a suggestion may be popular, there is no guarantee that it will be accepted. Nevertheless, we thank you for your contribution and feedback.

If you have any further questions, please reach us by sending a DM to ModMail.</value>
</data>

<data name="AcceptedDescription" xml:space="preserve">
<value>Hi {user.Mention}. Your suggestion in **{guild.Name}** has been accepted by staff members.
Depending on the complexity of your suggestion, it may take time to implement it into the server. Please be patient during this process.

If you have any further questions, please reach us by sending a DM to ModMail.</value>
</data>

<data name="ImplementedDescription" xml:space="preserve">
<value>Hi {user.Mention}. Your suggestion in **{guild.Name}** has been implemented and is now live in the server!
Thank you for your contribution and feedback, and we hope you enjoy the new changes.

If you have any further questions, please reach us by sending a DM to ModMail.</value>
</data>
</root>
Loading

0 comments on commit 102a4b4

Please sign in to comment.