Skip to content

Commit

Permalink
Customizeable embed colors
Browse files Browse the repository at this point in the history
  • Loading branch information
SquirrelKiev committed Aug 30, 2024
1 parent e46f5af commit a9a7892
Show file tree
Hide file tree
Showing 39 changed files with 836 additions and 255 deletions.
11 changes: 8 additions & 3 deletions DibariBot/Core/BotConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public class BotConfig
[YamlMember(Description = "An optional API key for Seq. Empty string is interpreted as no API key.")]
public string SeqApiKey { get; set; } = "";

[YamlMember(Description = "The default config for the bot.")]
public string DefaultPrefix { get; set; } = "m.";

[YamlMember(Description = "The logging level to use.")]
public LogEventLevel LogEventLevel { get; set; } = LogEventLevel.Information;

Expand Down Expand Up @@ -116,6 +113,14 @@ public class BotConfig
}
];

[YamlMember(Description = "The color to use for all embeds (if not set by the Guild).\n" +
"Ideally this should be formatted as a hex number. Default for example is 0x5E69A3")]
public int DefaultEmbedColor { get; set; } = 0x5E69A3;

[YamlMember(Description = "The color to use for all embeds (if not set by the Guild). \n" +
"Ideally this should be formatted as a hex number. Default for example is 0xE74C3C")]
public int ErrorEmbedColor { get; set; } = 0xE74C3C;

public struct AboutField
{
public string Name { get; set; }
Expand Down
9 changes: 8 additions & 1 deletion DibariBot/Core/BotService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Reflection;
using DibariBot.Database;
using Discord.Commands;
using Discord.Interactions;
using Discord.WebSocket;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
Expand All @@ -11,7 +13,9 @@ public class BotService(
BotConfig config,
DbService dbService,
ILogger<BotService> logger,
CommandHandler commandHandler
CommandHandler commandHandler,
InteractionService interactionService,
CommandService commandService
) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
Expand All @@ -35,6 +39,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

client.Ready += Client_Ready;

interactionService.Log += Client_Log;
commandService.Log += Client_Log;

await client.LoginAsync(TokenType.Bot, config.BotToken);
await client.StartAsync();
}
Expand Down
10 changes: 4 additions & 6 deletions DibariBot/Core/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ protected async Task CommandExecuted(Optional<CommandInfo> cmdInfoOpt, ICommandC

#region Interaction Handling

protected static Task InteractionExecuted(ICommandInfo cmdInfo, IInteractionContext ctx, Discord.Interactions.IResult res)
protected async Task InteractionExecuted(ICommandInfo cmdInfo, IInteractionContext ctx, Discord.Interactions.IResult res)
{
if (res.IsSuccess)
return Task.CompletedTask;
return;

var messageBody = $"{res.Error}, {res.ErrorReason}";

Expand All @@ -137,14 +137,12 @@ protected static Task InteractionExecuted(ICommandInfo cmdInfo, IInteractionCont

if (ctx.Interaction.HasResponded)
{
ctx.Interaction.ModifyOriginalResponseAsync(new MessageContents(messageBody, embed: null, null));
await ctx.Interaction.ModifyOriginalResponseAsync(new MessageContents(messageBody, embed: null, null));
}
else
{
ctx.Interaction.RespondAsync(messageBody, ephemeral: true);
await ctx.Interaction.RespondAsync(messageBody, ephemeral: true);
}

return Task.CompletedTask;
}


Expand Down
1 change: 1 addition & 0 deletions DibariBot/Core/Config/BotConfigFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public bool GetConfig([NotNullWhen(true)] out BotConfig? botConfig)

var deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.IgnoreUnmatchedProperties()
.Build();

Directory.CreateDirectory(DataDir);
Expand Down
5 changes: 3 additions & 2 deletions DibariBot/Core/Database/Models/GuildConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace DibariBot.Database;

#nullable disable
public class GuildConfig
{
public const int MaxPrefixLength = 8;
public const string DefaultPrefix = "m?";
public const string DefaultPrefix = "m.";

[Key]
public ulong GuildId { get; set; }

[MaxLength(MaxPrefixLength)]
public string Prefix { get; set; } = DefaultPrefix;

public int? EmbedColor { get; set; }
}
23 changes: 0 additions & 23 deletions DibariBot/Core/Extensions/EmbedBuilderExtensions.cs

This file was deleted.

1 change: 1 addition & 0 deletions DibariBot/DibariBot.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=core/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=core_005Ccache/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=core_005Cconfig/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=core_005Cextensions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules_005Ccore/@EntryIndexedValue">True</s:Boolean>
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using DibariBot.Database;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DibariBot.Migrations.PostgresMigrations
{
/// <inheritdoc />
public partial class EmbedColorConfig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Prefix",
table: "GuildConfigs",
type: "character varying(8)",
maxLength: 8,
nullable: false,
defaultValue: GuildConfig.DefaultPrefix,
oldClrType: typeof(string),
oldType: "character varying(8)",
oldMaxLength: 8,
oldNullable: true);

migrationBuilder.AddColumn<int>(
name: "EmbedColor",
table: "GuildConfigs",
type: "integer",
nullable: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "EmbedColor",
table: "GuildConfigs");

migrationBuilder.AlterColumn<string>(
name: "Prefix",
table: "GuildConfigs",
type: "character varying(8)",
maxLength: 8,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(8)",
oldMaxLength: 8);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// <auto-generated />
using System;
using DibariBot.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand Down Expand Up @@ -27,7 +28,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.ValueGeneratedOnAdd()
.HasColumnType("numeric(20,0)");

b.Property<int?>("EmbedColor")
.HasColumnType("integer");

b.Property<string>("Prefix")
.IsRequired()
.HasMaxLength(8)
.HasColumnType("character varying(8)");

Expand Down
Loading

0 comments on commit a9a7892

Please sign in to comment.