Skip to content

Commit

Permalink
feat: add Accepted suggestion state
Browse files Browse the repository at this point in the history
This change also combines /suggestion implement and /suggestion reject to /suggestion setstatus
  • Loading branch information
oliverbooth committed Jul 23, 2023
1 parent 7f2af91 commit e86cc21
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 137 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ 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.4.0] - 2023-07-23

### Added

- Add new ACCEPTED suggestion status.

### Changed

- `/suggestion implement` and `/suggestion reject` combined to `/suggestion setstatus`.

## [1.3.2] - 2023-07-22

### Added
Expand Down
43 changes: 0 additions & 43 deletions SuggestionBot/Commands/SuggestionCommand.Reject.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using Humanizer;
using SuggestionBot.AutocompleteProviders;
using SuggestionBot.Data;

namespace SuggestionBot.Commands;

internal sealed partial class SuggestionCommand
{
[SlashCommand("implement", "Implements a suggestion.", false)]
public async Task ImplementAsync(InteractionContext context,
[Option("suggestion", "The suggestion to implement."), Autocomplete(typeof(SuggestionAutocompleteProvider))]
string query)
[SlashCommand("setstatus", "Sets a new status for a suggestion.", false)]
public async Task SetStatusAsync(InteractionContext context,
[Option("suggestion", "The suggestion whose status to change.")]
[Autocomplete(typeof(SuggestionAutocompleteProvider))]
string query,
[Option("status", "The new status of the suggestion.")]
SuggestionStatus status)
{
var response = new DiscordInteractionResponseBuilder();

Expand All @@ -23,17 +27,19 @@ public async Task ImplementAsync(InteractionContext context,
}

var embed = new DiscordEmbedBuilder();
if (_suggestionService.Implement(suggestion, context.Member))
string humanizedStatus = status.Humanize(LetterCasing.AllCaps);

if (_suggestionService.SetStatus(suggestion, status, context.Member))
{
embed.WithColor(DiscordColor.Orange);
embed.WithTitle("Suggestion Implemented");
embed.WithDescription($"The suggestion with the ID {suggestion.Id} has been marked as IMPLEMENTED.");
embed.WithTitle("Suggestion Status Changed");
embed.WithDescription($"The suggestion with the ID {suggestion.Id} has been marked as {humanizedStatus}.");
}
else
{
embed.WithColor(DiscordColor.Orange);
embed.WithTitle("Suggestion Unchanged");
embed.WithDescription($"The suggestion with the ID {suggestion.Id} was already implemented. " +
embed.WithDescription($"The suggestion with the ID {suggestion.Id} was already {humanizedStatus}. " +
"No changes were made.");
}

Expand Down
6 changes: 6 additions & 0 deletions SuggestionBot/Configuration/GuildConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
/// </summary>
public sealed class GuildConfiguration
{
/// <summary>
/// Gets or sets the embed color for accepted suggestions.
/// </summary>
/// <value>The embed color for accepted suggestions.</value>
public int AcceptedColor { get; set; } = 0x00FF00;

/// <summary>
/// Gets or sets the cooldown for posting suggestions.
/// </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 @@ -7,5 +7,6 @@ public enum SuggestionStatus
{
Suggested,
Rejected,
Implemented
Implemented,
Accepted
}
79 changes: 7 additions & 72 deletions SuggestionBot/Services/SuggestionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public DiscordEmbed CreatePrivateEmbed(Suggestion suggestion)
SuggestionStatus.Suggested => "🗳️",
SuggestionStatus.Rejected => "",
SuggestionStatus.Implemented => "",
SuggestionStatus.Accepted => "",
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
};

Expand All @@ -89,6 +90,7 @@ public DiscordEmbed CreatePrivateEmbed(Suggestion suggestion)
SuggestionStatus.Suggested => configuration.SuggestedColor,
SuggestionStatus.Rejected => configuration.RejectedColor,
SuggestionStatus.Implemented => configuration.ImplementedColor,
SuggestionStatus.Accepted => configuration.AcceptedColor,
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
});

Expand Down Expand Up @@ -136,6 +138,7 @@ public DiscordEmbed CreatePublicEmbed(Suggestion suggestion)
SuggestionStatus.Suggested => "🗳️",
SuggestionStatus.Rejected => "",
SuggestionStatus.Implemented => "",
SuggestionStatus.Accepted => "",
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
};

Expand All @@ -152,6 +155,7 @@ public DiscordEmbed CreatePublicEmbed(Suggestion suggestion)
SuggestionStatus.Suggested => configuration.SuggestedColor,
SuggestionStatus.Rejected => configuration.RejectedColor,
SuggestionStatus.Implemented => configuration.ImplementedColor,
SuggestionStatus.Accepted => configuration.AcceptedColor,
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
});

Expand Down Expand Up @@ -317,42 +321,6 @@ public Uri GetSuggestionLink(Suggestion suggestion)
return new Uri($"https://discord.com/channels/{guildId}/{configuration?.SuggestionChannel}/{messageId}");
}

/// <summary>
/// Marks a suggestion as implemented, and optionally updates the remarks for the implementation.
/// </summary>
/// <param name="suggestion">The suggestion to update.</param>
/// <param name="staffMember">The staff member who implemented the suggestion.</param>
/// <returns><see langword="true" /> if the status was updated; otherwise, <see langword="false" />.</returns>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="suggestion" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="staffMember" /> is <see langword="null" />.</para>
/// </exception>
public bool Implement(Suggestion suggestion, DiscordMember staffMember)
{
if (suggestion is null)
{
throw new ArgumentNullException(nameof(suggestion));
}

if (staffMember is null)
{
throw new ArgumentNullException(nameof(staffMember));
}

if (!SetStatus(suggestion, SuggestionStatus.Implemented, staffMember))
{
return false;
}

_logger.LogInformation("{StaffMember} marked suggestion {Id} as IMPLEMENTED", staffMember, suggestion.Id);

using SuggestionContext context = _contextFactory.CreateDbContext();
context.Suggestions.Update(suggestion);
context.SaveChanges();
return true;
}

/// <summary>
/// Posts a suggestion to the suggestion channel of the guild in which it was made.
/// </summary>
Expand Down Expand Up @@ -396,42 +364,6 @@ public bool Implement(Suggestion suggestion, DiscordMember staffMember)
return message;
}

/// <summary>
/// Marks a suggestion as rejected, and updates the reason for the rejection if one is provided.
/// </summary>
/// <param name="suggestion">The suggestion to update.</param>
/// <param name="staffMember">The staff member who rejected the suggestion.</param>
/// <returns><see langword="true" /> if the status was updated; otherwise, <see langword="false" />.</returns>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="suggestion" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="staffMember" /> is <see langword="null" />.</para>
/// </exception>
public bool Reject(Suggestion suggestion, DiscordMember staffMember)
{
if (suggestion is null)
{
throw new ArgumentNullException(nameof(suggestion));
}

if (staffMember is null)
{
throw new ArgumentNullException(nameof(staffMember));
}

if (!SetStatus(suggestion, SuggestionStatus.Rejected, staffMember))
{
return false;
}

_logger.LogInformation("{StaffMember} marked suggestion {Id} as REJECTED", staffMember, suggestion.Id);

using SuggestionContext context = _contextFactory.CreateDbContext();
context.Suggestions.Update(suggestion);
context.SaveChanges();
return true;
}

/// <summary>
/// Sets the message of a suggestion.
/// </summary>
Expand Down Expand Up @@ -503,6 +435,9 @@ public bool SetStatus(Suggestion suggestion, SuggestionStatus status, DiscordMem
context.Suggestions.Update(suggestion);
context.SaveChanges();

_logger.LogInformation("{StaffMember} marked suggestion {Id} as {Status}", staffMember, suggestion.Id,
humanizedStatus);

_ = UpdateSuggestionAsync(suggestion);
return true;
}
Expand Down
19 changes: 6 additions & 13 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,14 @@ Allow a user to send suggestions again.

## Implementing and Rejecting Suggestions

### `/suggestion implement`
### `/suggestion setstatus`

Mark a suggestion as implemented.
Change the status of a suggestion

| Parameter | Required | Type | Description |
|:-----------|:---------|:-------------------------|:-----------------------------|
| suggestion | ✅ Yes | Suggestion or Message ID | The suggestion to implement. |

### `/suggestion reject`

Mark a suggestion as rejected.

| Parameter | Required | Type | Description |
|:-----------|:---------|:-------------------------|:--------------------------|
| suggestion | ✅ Yes | Suggestion or Message ID | The suggestion to reject. |
| Parameter | Required | Type | Description |
|:-----------|:---------|:-------------------------|:---------------------------------------|
| suggestion | ✅ Yes | Suggestion or Message ID | The suggestion whose status to change. |
| status | ✅ Yes | SuggestionStatus | The new status of the suggestion. |

# Ephemeral responses

Expand Down

0 comments on commit e86cc21

Please sign in to comment.