Skip to content

Commit

Permalink
Delegate primary/secondary/tertiary colors to core plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed May 5, 2022
1 parent efed860 commit 0db8be6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
21 changes: 0 additions & 21 deletions Hammer/Configuration/GuildConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,6 @@ internal sealed class GuildConfiguration
[JsonPropertyName("roles")]
public RoleConfiguration RoleConfiguration { get; set; } = new();

/// <summary>
/// Gets or sets the guild's primary color.
/// </summary>
/// <value>The guild's primary color, in 24-bit RGB format.</value>
[JsonPropertyName("primaryColor")]
public int PrimaryColor { get; set; } = 0x7837FF;

/// <summary>
/// Gets or sets the guild's secondary color.
/// </summary>
/// <value>The guild's secondary color, in 24-bit RGB format.</value>
[JsonPropertyName("secondaryColor")]
public int SecondaryColor { get; set; } = 0xE33C6C;

/// <summary>
/// Gets or sets the guild's tertiary color.
/// </summary>
/// <value>The guild's tertiary color, in 24-bit RGB format.</value>
[JsonPropertyName("tertiaryColor")]
public int TertiaryColor { get; set; } = 0xFFE056;

/// <summary>
/// Gets or sets the threshold before a message report is considered urgent.
/// </summary>
Expand Down
11 changes: 8 additions & 3 deletions Hammer/Services/InfractionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using SmartFormat;
using X10D.Text;
using TimestampFormat = DSharpPlus.TimestampFormat;
using CoreGuildConfiguration = BrackeysBot.Core.API.Configuration.GuildConfiguration;

namespace Hammer.Services;

Expand Down Expand Up @@ -216,11 +217,15 @@ public DiscordEmbedBuilder BuildInfractionHistoryEmbed(DiscordUser user, Discord
{
const int infractionsPerPage = 10;

IReadOnlyList<Infraction> infractions = GetInfractions(user, guild);
GuildConfiguration guildConfiguration = _configurationService.GetGuildConfiguration(guild);
DiscordEmbedBuilder embed = guild.CreateDefaultEmbed();
IReadOnlyList<Infraction> infractions = GetInfractions(user, guild);

if (_corePlugin.TryGetGuildConfiguration(guild, out CoreGuildConfiguration? guildConfiguration))
embed.WithColor(guildConfiguration.PrimaryColor);
else
embed.WithColor(DiscordColor.Orange);

embed.WithAuthor(user);
embed.WithColor(guildConfiguration.PrimaryColor);

string underlinedFieldName = Formatter.Underline("Infraction Record");
if (infractions.Count > 0)
Expand Down
7 changes: 5 additions & 2 deletions Hammer/Services/MessageReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Extensions.Hosting;
using NLog;
using SmartFormat;
using CoreGuildConfiguration = BrackeysBot.Core.API.Configuration.GuildConfiguration;

namespace Hammer.Services;

Expand Down Expand Up @@ -254,7 +255,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

private DiscordEmbed CreateStaffReportEmbed(DiscordMessage message, DiscordMember reporter)
{
GuildConfiguration guildConfiguration = _configurationService.GetGuildConfiguration(reporter.Guild);
DiscordColor color = DiscordColor.Orange;
if (_corePlugin.TryGetGuildConfiguration(reporter.Guild, out CoreGuildConfiguration? guildConfiguration))
color = guildConfiguration.PrimaryColor;

bool hasContent = !string.IsNullOrWhiteSpace(message.Content);
bool hasAttachments = message.Attachments.Count > 0;
Expand All @@ -263,7 +266,7 @@ private DiscordEmbed CreateStaffReportEmbed(DiscordMessage message, DiscordMembe
string? attachments = hasAttachments ? string.Join('\n', message.Attachments.Select(a => a.Url)) : null;

return reporter.Guild.CreateDefaultEmbed()
.WithColor(guildConfiguration.TertiaryColor)
.WithColor(color)
.WithTitle(EmbedTitles.MessageReported)
.WithDescription(EmbedMessages.MessageReported.FormatSmart(new {user = reporter, channel = message.Channel}))
.AddField(EmbedFieldNames.Channel, message.Channel.Mention, true)
Expand Down

0 comments on commit 0db8be6

Please sign in to comment.