diff --git a/Data/Moderation.cs b/Data/Moderation.cs new file mode 100644 index 0000000..cfcff7c --- /dev/null +++ b/Data/Moderation.cs @@ -0,0 +1,27 @@ +namespace Myhm.Data; + +public class Moderation +{ + public int Id { get; set; } + public string UserId { get; set; } = default!; + public ModerationTypes Type { get; set; } + public string Reason { get; set; } = default!; + public ModerationReasons ReasonType { get; set; } + public DateTime CreatedAt { get; set; } +} + +public enum ModerationTypes +{ + Ban, + Warn, +} + +// TODO: Get reasons from @MYHM and add them here +public enum ModerationReasons +{ + Spamming, + Harassment, + HateSpeech, + NSFW, + Other, +} diff --git a/Models/MyhmConfiguration.cs b/Data/MyhmConfiguration.cs similarity index 83% rename from Models/MyhmConfiguration.cs rename to Data/MyhmConfiguration.cs index fecf389..3ddc4c8 100644 --- a/Models/MyhmConfiguration.cs +++ b/Data/MyhmConfiguration.cs @@ -1,8 +1,8 @@ -namespace Myhm.Models +namespace Myhm.Data { public class MyhmConfiguration { - public required string GlobalToken { get; init; } + public required string AuthToken { get; init; } public required string DatabaseConnectionString { get; init; } public required DatabaseTypes DatabaseType { get; init; } public bool UseSentry { get; init; } = true; diff --git a/Data/MyhmContext.cs b/Data/MyhmContext.cs index fd8061d..5d00f35 100644 --- a/Data/MyhmContext.cs +++ b/Data/MyhmContext.cs @@ -1,15 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Myhm.Models; +using static EnumStringValues.EnumExtensions; namespace Myhm.Data { public class MyhmContext(DbContextOptions options) : DbContext(options) { + public DbSet Moderation { get; set; } = default!; + public DbSet Token { get; set; } = default!; - //public DbSet Ban { get; set; } = default!; + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder + .Entity() + .Property(m => m.Type) + .HasConversion(v => v.GetStringValue(), v => v.ParseToEnum()); + + modelBuilder + .Entity() + .Property(m => m.ReasonType) + .HasConversion(v => v.GetStringValue(), v => v.ParseToEnum()); + } } } diff --git a/Data/Token.cs b/Data/Token.cs new file mode 100644 index 0000000..d986a1d --- /dev/null +++ b/Data/Token.cs @@ -0,0 +1,9 @@ +namespace Myhm.Data; + +public class Token +{ + public int Id { get; set; } + public string String { get; set; } = default!; + public int DiscordUserId { get; set; } + public DateTime CreatedAt { get; set; } +} diff --git a/Program.cs b/Program.cs index 44d9fcc..81b78ba 100644 --- a/Program.cs +++ b/Program.cs @@ -2,34 +2,30 @@ using System.Reflection; using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; using Myhm.Data; -using Myhm.Models; using Myhm.Util.SwaggerTheme; +using Newtonsoft.Json; var builder = WebApplication.CreateBuilder(args); -// Configuration var config = builder.Configuration.GetSection("Configuration").Get(); builder.Services.Configure(builder.Configuration.GetSection("Configuration")); -if (config?.GlobalToken == "CHANGE-ME") +if ((config?.AuthToken?.Length ?? 0) < 64 && !builder.Environment.IsDevelopment()) { throw new InvalidOperationException( - "Global token is not a valid value, please set the `CONFIGURATION__GLOBALTOKEN` environment variable to a random value. `openssl rand -hex 64` is a good way to generate a random value." + "Global token is not a valid value, please set the `CONFIGURATION__GLOBALTOKEN` environment variable to a random value of at least 64 characters. `openssl rand -hex 64` is a good way to generate a random value." ); } -// Initialize Database builder.Services.AddDbContextFactory(options => options.UseNpgsql(builder.Configuration.GetConnectionString("MyhmContext")) ); -// Sentry if (config?.UseSentry == true) { builder.WebHost.UseSentry(); } -// Add services to the container. builder.Services.AddHttpLogging(o => { }); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(opts => @@ -97,11 +93,9 @@ if (config?.LogRequests == true) app.UseHttpLogging(); } -// Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error", createScopeForErrors: true); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } @@ -109,12 +103,12 @@ app.UseHttpsRedirection(); //app.UseAntiforgery(); -// if (app.Environment.IsDevelopment()) -// { -// app.Logger.LogInformation( -// "Development mode detected, printing configuration: {Configuration}", -// config?.ToJson() -// ); -// } +if (app.Environment.IsDevelopment()) +{ + app.Logger.LogInformation( + "Development mode detected, printing configuration: {Configuration}", + config != null ? JsonConvert.SerializeObject(config) : "null" + ); +} app.Run(); diff --git a/myhm-commission.csproj b/myhm-commission.csproj index 6fb072c..f658b88 100644 --- a/myhm-commission.csproj +++ b/myhm-commission.csproj @@ -13,8 +13,10 @@ + +