Files
archived-discord-bot/CompatBot/Database/BotDb.cs
13xforever 7fd7d09973 RPCS3 Compatibility Bot reimplemented in C# for .NET Core
RPCS3 Compatibility Bot reimplemented in C# for .NET Core

Current status of this PR:
* tested and targeted for .NET Core 2.1
* all functionality is either on par or improved compared to the python version
* compatibility with current bot.db should be preserved in all upgrade scenarios
* some bot management commands were changed (now under !sudo bot)
* standard help generator for the new discord client is ... different;
  compatibility with old format could be restored through custom formatter if needed
* everything has been split in more loosely tied components for easier extensibility and maintenance
* log parsing has been rewritten and should work ~2x as fast
2018-07-20 09:22:28 +02:00

78 lines
2.5 KiB
C#

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CompatApiClient;
using Microsoft.EntityFrameworkCore;
namespace CompatBot.Database
{
internal class BotDb: DbContext
{
private static readonly Lazy<BotDb> instance = new Lazy<BotDb>(() => new BotDb());
public static BotDb Instance => instance.Value;
public DbSet<Moderator> Moderator { get; set; }
public DbSet<Piracystring> Piracystring { get; set; }
public DbSet<Warning> Warning { get; set; }
public DbSet<Explanation> Explanation { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=bot.db");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//configure indices
modelBuilder.Entity<Moderator>().HasIndex(m => m.DiscordId).IsUnique().HasName("moderator_discord_id");
modelBuilder.Entity<Piracystring>().HasIndex(ps => ps.String).IsUnique().HasName("piracystring_string");
modelBuilder.Entity<Warning>().HasIndex(w => w.DiscordId).HasName("warning_discord_id");
modelBuilder.Entity<Explanation>().HasIndex(e => e.Keyword).IsUnique().HasName("explanation_keyword");
//configure default policy of Id being the primary key
modelBuilder.ConfigureDefaultPkConvention();
//configure name conversion for all configured entities from CamelCase to snake_case
modelBuilder.ConfigureMapping(NamingStyles.Underscore);
}
}
internal class Moderator
{
public int Id { get; set; }
public ulong DiscordId { get; set; }
public bool Sudoer { get; set; }
}
internal class Piracystring
{
public int Id { get; set; }
[Required, Column(TypeName = "varchar(255)")]
public string String { get; set; }
}
internal class Warning
{
public int Id { get; set; }
public ulong DiscordId { get; set; }
public ulong IssuerId { get; set; }
[Required]
public string Reason { get; set; }
[Required]
public string FullReason { get; set; }
public long? Timestamp { get; set; }
}
internal class Explanation
{
public int Id { get; set; }
[Required]
public string Keyword { get; set; }
[Required]
public string Text { get; set; }
}
}