Skip to content

Commit

Permalink
Merge branch 'v1.6.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jul 24, 2023
2 parents 102a4b4 + 65c40cc commit 535210f
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 65 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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.1] - 2023-07-24

### Added

- Added additional suggestion states.

## [1.6.0] - 2023-07-24

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

- Initial release.

[1.6.1]: https://github.com/BrackeysBot/SuggestionBot/releases/tag/v1.6.1
[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
Expand Down
12 changes: 12 additions & 0 deletions SuggestionBot/Configuration/GuildConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public sealed class GuildConfiguration
/// <value><see langword="true" /> if a thread should be created; otherwise, <see langword="false" />.</value>
public bool CreateThreadForSuggestion { get; set; } = true;

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

/// <summary>
/// Gets or sets the embed color for implemented suggestions.
/// </summary>
Expand All @@ -41,6 +47,12 @@ public sealed class GuildConfiguration
/// <value>The log channel ID.</value>
public ulong LogChannel { get; set; }

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

/// <summary>
/// Gets or sets the embed color for rejected suggestions.
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion SuggestionBot/Data/SuggestionStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ public enum SuggestionStatus
Rejected,
Implemented,
Accepted,
Removed
Removed,
Duplicate,
AlreadyImplemented,
AlreadyPlanned
}
33 changes: 33 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.

18 changes: 18 additions & 0 deletions SuggestionBot/Resources/PrivateMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@
</value>
</resheader>

<data name="PlannedDescription" xml:space="preserve">
<value>{user.Mention}, your suggestion in **{guild.Name}** has been closed by staff because the changes you suggested have already been planned for the server.

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

<data name="AlreadyImplementedDescription" xml:space="preserve">
<value>{user.Mention}, your suggestion in **{guild.Name}** has been closed by staff because the changes you suggested are already present in the server.

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

<data name="DuplicateDescription" xml:space="preserve">
<value>{user.Mention}, your suggestion in **{guild.Name}** has been closed by staff because it was determined to be a duplicate of an existing suggestion which supersedes it or was previously closed.

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

<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.
Expand Down
18 changes: 18 additions & 0 deletions SuggestionBot/Services/MailmanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ private bool TryBuildEmbed(Suggestion suggestion, DiscordEmbedBuilder embed, Dis
embed.WithDescription(PrivateMessages.ImplementedDescription.FormatSmart(new { user = author, guild }));
break;

case SuggestionStatus.Duplicate:
embed.WithColor(configuration.DuplicateColor);
embed.WithTitle("Suggestion Closed (Duplicate)");
embed.WithDescription(PrivateMessages.DuplicateDescription.FormatSmart(new { user = author, guild }));
break;

case SuggestionStatus.AlreadyImplemented:
embed.WithColor(configuration.ImplementedColor);
embed.WithTitle("Suggestion Closed (Already Implemented)");
embed.WithDescription(PrivateMessages.DuplicateDescription.FormatSmart(new { user = author, guild }));
break;

case SuggestionStatus.AlreadyPlanned:
embed.WithColor(configuration.PlannedColor);
embed.WithTitle("Suggestion Closed (Already Planned)");
embed.WithDescription(PrivateMessages.PlannedDescription.FormatSmart(new { user = author, guild }));
break;

default:
return false;
}
Expand Down
107 changes: 44 additions & 63 deletions SuggestionBot/Services/SuggestionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,8 @@ public DiscordEmbed CreatePrivateEmbed(Suggestion suggestion)
return new DiscordEmbedBuilder();
}

if (!_configurationService.TryGetGuildConfiguration(guild, out GuildConfiguration? configuration))
{
configuration = new GuildConfiguration();
}

string emoji = suggestion.Status switch
{
SuggestionStatus.Suggested => "🗳️",
SuggestionStatus.Rejected => "",
SuggestionStatus.Implemented => "",
SuggestionStatus.Accepted => "",
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
};

DiscordUser author = GetAuthor(suggestion);
var embed = new DiscordEmbedBuilder();
string authorName = author.GetUsernameWithDiscriminator();
embed.WithAuthor($"Suggestion from {authorName}", iconUrl: author.GetAvatarUrl(ImageFormat.Png));
embed.WithThumbnail(guild.GetIconUrl(ImageFormat.Png));
embed.WithDescription(suggestion.Content);
embed.WithFooter($"Suggestion {suggestion.Id}");
embed.WithColor(suggestion.Status switch
{
SuggestionStatus.Suggested => configuration.SuggestedColor,
SuggestionStatus.Rejected => configuration.RejectedColor,
SuggestionStatus.Implemented => configuration.ImplementedColor,
SuggestionStatus.Accepted => configuration.AcceptedColor,
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
});

embed.AddField("Status", $"{emoji} **{suggestion.Status.Humanize(LetterCasing.AllCaps)}**", true);
DiscordEmbedBuilder embed = CreateDefaultEmbed(suggestion, guild);
embed.AddField("Author", author.Mention, true);
embed.AddField("Submitted", Formatter.Timestamp(suggestion.Timestamp), true);
embed.AddField("View Suggestion", GetSuggestionLink(suggestion), true);
Expand Down Expand Up @@ -138,39 +109,7 @@ public DiscordEmbed CreatePublicEmbed(Suggestion suggestion)
return new DiscordEmbedBuilder();
}

if (!_configurationService.TryGetGuildConfiguration(guild, out GuildConfiguration? configuration))
{
configuration = new GuildConfiguration();
}

string emoji = suggestion.Status switch
{
SuggestionStatus.Suggested => "🗳️",
SuggestionStatus.Rejected => "",
SuggestionStatus.Implemented => "",
SuggestionStatus.Accepted => "",
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
};

DiscordUser author = GetAuthor(suggestion);
var embed = new DiscordEmbedBuilder();
string authorName = author.GetUsernameWithDiscriminator();
embed.WithAuthor($"Suggestion from {authorName}", iconUrl: author.GetAvatarUrl(ImageFormat.Png));
embed.WithThumbnail(guild.GetIconUrl(ImageFormat.Png));
embed.WithDescription(suggestion.Content);
embed.WithFooter($"Suggestion {suggestion.Id}");
embed.WithTimestamp(suggestion.Timestamp);
embed.WithColor(suggestion.Status switch
{
SuggestionStatus.Suggested => configuration.SuggestedColor,
SuggestionStatus.Rejected => configuration.RejectedColor,
SuggestionStatus.Implemented => configuration.ImplementedColor,
SuggestionStatus.Accepted => configuration.AcceptedColor,
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
});

embed.AddField("Status", $"{emoji} **{suggestion.Status.Humanize(LetterCasing.AllCaps)}**", true);

DiscordEmbedBuilder embed = CreateDefaultEmbed(suggestion, guild);
if (!string.IsNullOrWhiteSpace(suggestion.Remarks))
{
embed.AddField("Staff Remarks", suggestion.Remarks);
Expand Down Expand Up @@ -695,6 +634,48 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)
return Task.CompletedTask;
}

private DiscordEmbedBuilder CreateDefaultEmbed(Suggestion suggestion, DiscordGuild guild)
{
if (!_configurationService.TryGetGuildConfiguration(guild, out GuildConfiguration? configuration))
{
configuration = new GuildConfiguration();
}

string emoji = suggestion.Status switch
{
SuggestionStatus.Suggested => "🗳️",
SuggestionStatus.Rejected => "",
SuggestionStatus.Implemented => "",
SuggestionStatus.Accepted => "",
SuggestionStatus.Duplicate => "🔁",
SuggestionStatus.AlreadyImplemented => "",
SuggestionStatus.AlreadyPlanned => "📅",
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
};

DiscordUser author = GetAuthor(suggestion);
var embed = new DiscordEmbedBuilder();
string authorName = author.GetUsernameWithDiscriminator();
embed.WithAuthor($"Suggestion from {authorName}", iconUrl: author.GetAvatarUrl(ImageFormat.Png));
embed.WithThumbnail(guild.GetIconUrl(ImageFormat.Png));
embed.WithDescription(suggestion.Content);
embed.WithFooter($"Suggestion {suggestion.Id}");
embed.WithTimestamp(suggestion.Timestamp);
embed.WithColor(suggestion.Status switch
{
SuggestionStatus.Suggested => configuration.SuggestedColor,
SuggestionStatus.Rejected => configuration.RejectedColor,
SuggestionStatus.Implemented or SuggestionStatus.AlreadyImplemented => configuration.ImplementedColor,
SuggestionStatus.Accepted => configuration.AcceptedColor,
SuggestionStatus.Duplicate => configuration.DuplicateColor,
SuggestionStatus.AlreadyPlanned => configuration.PlannedColor,
_ => throw new ArgumentOutOfRangeException(nameof(suggestion), suggestion.Status, null)
});

embed.AddField("Status", $"{emoji} **{suggestion.Status.Humanize(LetterCasing.AllCaps)}**", true);
return embed;
}

private Task OnGuildAvailable(DiscordClient sender, GuildCreateEventArgs args)
{
DiscordGuild guild = args.Guild;
Expand Down
2 changes: 1 addition & 1 deletion SuggestionBot/SuggestionBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<VersionPrefix>1.6.0</VersionPrefix>
<VersionPrefix>1.6.1</VersionPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down

0 comments on commit 535210f

Please sign in to comment.