Skip to content

Commit

Permalink
feat: add removal feature
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jul 24, 2023
1 parent 15fb03e commit 6b4ec2b
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 6 deletions.
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);
}
}
5 changes: 3 additions & 2 deletions SuggestionBot/Commands/SuggestionCommand.SetStatus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DSharpPlus.Entities;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using Humanizer;
using SuggestionBot.AutocompleteProviders;
Expand All @@ -21,7 +21,8 @@ public async Task SetStatusAsync(InteractionContext context,
{
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 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
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
}
12 changes: 12 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.

7 changes: 7 additions & 0 deletions SuggestionBot/Resources/PrivateMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
</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.
Expand Down
13 changes: 12 additions & 1 deletion SuggestionBot/Services/MailmanService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DSharpPlus;
using DSharpPlus;
using DSharpPlus.Entities;
using Humanizer;
using SmartFormat;
Expand Down Expand Up @@ -74,6 +74,11 @@ public async Task SendSuggestionAsync(Suggestion suggestion)
embed.AddField("Staff Remarks", suggestion.Remarks);
}

if (suggestion.Status != SuggestionStatus.Removed)
{
embed.AddField("View Suggestion", suggestionLink);
}

await member.SendMessageAsync(embed).ConfigureAwait(false);
}

Expand All @@ -86,6 +91,12 @@ private bool TryBuildEmbed(Suggestion suggestion, DiscordEmbedBuilder embed, Dis

switch (suggestion.Status)
{
case SuggestionStatus.Removed:
embed.WithColor(configuration.RemovedColor);
embed.WithTitle("Suggestion Removed");
embed.WithDescription(PrivateMessages.RemovedDescription.FormatSmart(new { user = author, guild }));
break;

case SuggestionStatus.Rejected:
embed.WithColor(configuration.RejectedColor);
embed.WithTitle("Suggestion Rejected");
Expand Down
20 changes: 18 additions & 2 deletions SuggestionBot/Services/SuggestionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public DiscordEmbed CreatePrivateEmbed(Suggestion suggestion)
embed.AddField("Submitted", Formatter.Timestamp(suggestion.Timestamp), true);
embed.AddField("View Suggestion", GetSuggestionLink(suggestion), true);

if (suggestion.ThreadId != 0)
if (suggestion.ThreadId != 0 && suggestion.Status != SuggestionStatus.Removed)
{
embed.AddField("View Discussion", MentionUtility.MentionChannel(suggestion.ThreadId), true);
}
Expand Down Expand Up @@ -503,14 +503,18 @@ public bool SetStatus(Suggestion suggestion,
SuggestionStatus.Rejected => configuration.RejectedColor,
SuggestionStatus.Implemented => configuration.ImplementedColor,
SuggestionStatus.Accepted => configuration.AcceptedColor,
SuggestionStatus.Removed => configuration.RemovedColor,
_ => DiscordColor.CornflowerBlue
});
embed.WithTitle("Suggestion Status Updated");
embed.WithDescription($"The status of suggestion {suggestion.Id} has been updated to **{humanizedStatus}**.");
embed.AddField("Old Status", oldHumanizedStatus, true);
embed.AddField("New Status", humanizedStatus, true);
embed.AddField("Staff Member", staffMember.Mention, true);
embed.AddField("View Suggestion", GetSuggestionLink(suggestion), true);
if (status != SuggestionStatus.Removed)
{
embed.AddField("View Suggestion", GetSuggestionLink(suggestion), true);
}

if (!string.IsNullOrWhiteSpace(remarks))
{
Expand Down Expand Up @@ -652,6 +656,18 @@ public async Task UpdateSuggestionAsync(Suggestion suggestion)
return;
}

if (suggestion.Status == SuggestionStatus.Removed)
{
DiscordThreadChannel? thread = GetThread(suggestion);
if (thread is not null)
{
await thread.DeleteAsync().ConfigureAwait(false);
}

await message.DeleteAsync();
return;
}

DiscordEmbed embed = CreatePublicEmbed(suggestion);
await message.ModifyAsync(m => m.Embed = embed).ConfigureAwait(false);

Expand Down

0 comments on commit 6b4ec2b

Please sign in to comment.