2016-08-24 01:32:48 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NadekoBot.Services.Database.Models;
|
2016-10-10 04:38:20 +00:00
|
|
|
|
using NadekoBot.Extensions;
|
2016-08-24 01:32:48 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Services.Database
|
|
|
|
|
{
|
2016-11-15 11:01:02 +00:00
|
|
|
|
public class NadekoContext : DbContext
|
2016-08-24 01:32:48 +00:00
|
|
|
|
{
|
2016-08-24 19:38:17 +00:00
|
|
|
|
public DbSet<Quote> Quotes { get; set; }
|
|
|
|
|
public DbSet<Donator> Donators { get; set; }
|
2016-08-24 23:41:11 +00:00
|
|
|
|
public DbSet<GuildConfig> GuildConfigs { get; set; }
|
2016-08-25 17:23:47 +00:00
|
|
|
|
public DbSet<ClashWar> ClashOfClans { get; set; }
|
|
|
|
|
public DbSet<ClashCaller> ClashCallers { get; set; }
|
2016-08-25 22:05:29 +00:00
|
|
|
|
public DbSet<Reminder> Reminders { get; set; }
|
2016-08-26 17:25:54 +00:00
|
|
|
|
public DbSet<SelfAssignedRole> SelfAssignableRoles { get; set; }
|
2016-08-28 00:46:36 +00:00
|
|
|
|
public DbSet<BotConfig> BotConfig { get; set; }
|
2016-08-28 20:59:12 +00:00
|
|
|
|
public DbSet<Repeater> Repeaters { get; set; }
|
2016-08-30 01:17:16 +00:00
|
|
|
|
public DbSet<Currency> Currency { get; set; }
|
2016-09-04 13:11:02 +00:00
|
|
|
|
public DbSet<ConvertUnit> ConversionUnits { get; set; }
|
2016-10-01 03:49:05 +00:00
|
|
|
|
public DbSet<MusicPlaylist> MusicPlaylists { get; set; }
|
2016-10-08 02:25:12 +00:00
|
|
|
|
public DbSet<CustomReaction> CustomReactions { get; set; }
|
2016-10-15 00:58:15 +00:00
|
|
|
|
public DbSet<CurrencyTransaction> CurrencyTransactions { get; set; }
|
2016-11-27 02:51:10 +00:00
|
|
|
|
public DbSet<UserPokeTypes> PokeGame { get; set; }
|
2016-08-24 01:32:48 +00:00
|
|
|
|
|
2016-09-05 10:27:58 +00:00
|
|
|
|
//logging
|
|
|
|
|
public DbSet<LogSetting> LogSettings { get; set; }
|
|
|
|
|
public DbSet<IgnoredLogChannel> IgnoredLogChannels { get; set; }
|
|
|
|
|
public DbSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceCHannels { get; set; }
|
|
|
|
|
|
2016-09-10 19:40:25 +00:00
|
|
|
|
//orphans xD
|
|
|
|
|
public DbSet<EightBallResponse> EightBallResponses { get; set; }
|
|
|
|
|
public DbSet<RaceAnimal> RaceAnimals { get; set; }
|
|
|
|
|
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
|
|
|
|
|
|
2016-09-14 01:38:44 +00:00
|
|
|
|
public NadekoContext()
|
|
|
|
|
{
|
2016-12-13 03:49:44 +00:00
|
|
|
|
this.Database.Migrate();
|
2016-11-15 11:01:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NadekoContext(DbContextOptions options) : base(options)
|
|
|
|
|
{
|
|
|
|
|
this.Database.Migrate();
|
|
|
|
|
EnsureSeedData();
|
2016-09-14 01:38:44 +00:00
|
|
|
|
}
|
2016-12-13 03:49:44 +00:00
|
|
|
|
////Uncomment this to db initialisation with dotnet ef migration add [module]
|
2016-11-22 11:31:55 +00:00
|
|
|
|
//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
|
//{
|
|
|
|
|
// optionsBuilder.UseSqlite("Filename=./data/NadekoBot.db");
|
|
|
|
|
//}
|
2016-09-14 01:38:44 +00:00
|
|
|
|
|
2016-09-10 19:40:25 +00:00
|
|
|
|
public void EnsureSeedData()
|
|
|
|
|
{
|
|
|
|
|
if (!BotConfig.Any())
|
|
|
|
|
{
|
|
|
|
|
var bc = new BotConfig();
|
|
|
|
|
|
2016-10-10 04:38:20 +00:00
|
|
|
|
bc.ModulePrefixes.AddRange(new HashSet<ModulePrefix>()
|
2016-09-10 19:40:25 +00:00
|
|
|
|
{
|
|
|
|
|
new ModulePrefix() { ModuleName = "Administration", Prefix = "." },
|
|
|
|
|
new ModulePrefix() { ModuleName = "Searches", Prefix = "~" },
|
2016-09-10 19:45:12 +00:00
|
|
|
|
new ModulePrefix() { ModuleName = "Translator", Prefix = "~" },
|
2016-09-10 19:40:25 +00:00
|
|
|
|
new ModulePrefix() { ModuleName = "NSFW", Prefix = "~" },
|
|
|
|
|
new ModulePrefix() { ModuleName = "ClashOfClans", Prefix = "," },
|
|
|
|
|
new ModulePrefix() { ModuleName = "Help", Prefix = "-" },
|
|
|
|
|
new ModulePrefix() { ModuleName = "Music", Prefix = "!!" },
|
|
|
|
|
new ModulePrefix() { ModuleName = "Trello", Prefix = "trello" },
|
|
|
|
|
new ModulePrefix() { ModuleName = "Games", Prefix = ">" },
|
|
|
|
|
new ModulePrefix() { ModuleName = "Gambling", Prefix = "$" },
|
|
|
|
|
new ModulePrefix() { ModuleName = "Permissions", Prefix = ";" },
|
|
|
|
|
new ModulePrefix() { ModuleName = "Pokemon", Prefix = ">" },
|
2016-10-08 02:25:12 +00:00
|
|
|
|
new ModulePrefix() { ModuleName = "Utility", Prefix = "." },
|
2016-11-27 02:51:10 +00:00
|
|
|
|
new ModulePrefix() { ModuleName = "CustomReactions", Prefix = "." },
|
|
|
|
|
new ModulePrefix() { ModuleName = "PokeGame", Prefix = ">" }
|
2016-09-10 19:40:25 +00:00
|
|
|
|
});
|
2016-10-10 04:38:20 +00:00
|
|
|
|
bc.RaceAnimals.AddRange(new HashSet<RaceAnimal>
|
2016-09-10 19:40:25 +00:00
|
|
|
|
{
|
|
|
|
|
new RaceAnimal { Icon = "🐼", Name = "Panda" },
|
|
|
|
|
new RaceAnimal { Icon = "🐻", Name = "Bear" },
|
|
|
|
|
new RaceAnimal { Icon = "🐧", Name = "Pengu" },
|
|
|
|
|
new RaceAnimal { Icon = "🐨", Name = "Koala" },
|
|
|
|
|
new RaceAnimal { Icon = "🐬", Name = "Dolphin" },
|
|
|
|
|
new RaceAnimal { Icon = "🐞", Name = "Ladybird" },
|
|
|
|
|
new RaceAnimal { Icon = "🦀", Name = "Crab" },
|
|
|
|
|
new RaceAnimal { Icon = "🦄", Name = "Unicorn" }
|
|
|
|
|
});
|
2016-10-10 04:38:20 +00:00
|
|
|
|
bc.EightBallResponses.AddRange(new HashSet<EightBallResponse>
|
2016-09-10 19:40:25 +00:00
|
|
|
|
{
|
|
|
|
|
new EightBallResponse() { Text = "Most definitely yes" },
|
|
|
|
|
new EightBallResponse() { Text = "For sure" },
|
|
|
|
|
new EightBallResponse() { Text = "Totally!" },
|
|
|
|
|
new EightBallResponse() { Text = "Of course!" },
|
|
|
|
|
new EightBallResponse() { Text = "As I see it, yes" },
|
|
|
|
|
new EightBallResponse() { Text = "My sources say yes" },
|
|
|
|
|
new EightBallResponse() { Text = "Yes" },
|
|
|
|
|
new EightBallResponse() { Text = "Most likely" },
|
|
|
|
|
new EightBallResponse() { Text = "Perhaps" },
|
|
|
|
|
new EightBallResponse() { Text = "Maybe" },
|
|
|
|
|
new EightBallResponse() { Text = "Not sure" },
|
|
|
|
|
new EightBallResponse() { Text = "It is uncertain" },
|
|
|
|
|
new EightBallResponse() { Text = "Ask me again later" },
|
|
|
|
|
new EightBallResponse() { Text = "Don't count on it" },
|
|
|
|
|
new EightBallResponse() { Text = "Probably not" },
|
|
|
|
|
new EightBallResponse() { Text = "Very doubtful" },
|
|
|
|
|
new EightBallResponse() { Text = "Most likely no" },
|
|
|
|
|
new EightBallResponse() { Text = "Nope" },
|
|
|
|
|
new EightBallResponse() { Text = "No" },
|
|
|
|
|
new EightBallResponse() { Text = "My sources say no" },
|
|
|
|
|
new EightBallResponse() { Text = "Dont even think about it" },
|
|
|
|
|
new EightBallResponse() { Text = "Definitely no" },
|
|
|
|
|
new EightBallResponse() { Text = "NO - It may cause disease contraction" }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BotConfig.Add(bc);
|
|
|
|
|
|
|
|
|
|
this.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-24 13:29:01 +00:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
#region QUOTES
|
2016-08-24 17:04:24 +00:00
|
|
|
|
|
2016-08-24 13:29:01 +00:00
|
|
|
|
var quoteEntity = modelBuilder.Entity<Quote>();
|
|
|
|
|
|
2016-08-24 17:04:24 +00:00
|
|
|
|
#endregion
|
2016-08-28 00:46:36 +00:00
|
|
|
|
|
2016-08-24 17:04:24 +00:00
|
|
|
|
#region Donators
|
2016-08-24 13:29:01 +00:00
|
|
|
|
|
2016-08-24 17:04:24 +00:00
|
|
|
|
var donatorEntity = modelBuilder.Entity<Donator>();
|
|
|
|
|
donatorEntity
|
|
|
|
|
.HasIndex(d => d.UserId)
|
2016-08-24 13:29:01 +00:00
|
|
|
|
.IsUnique();
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2016-09-10 19:40:25 +00:00
|
|
|
|
#region GuildConfig
|
2016-08-24 17:04:24 +00:00
|
|
|
|
|
2016-08-24 23:41:11 +00:00
|
|
|
|
var configEntity = modelBuilder.Entity<GuildConfig>();
|
2016-08-24 17:04:24 +00:00
|
|
|
|
configEntity
|
|
|
|
|
.HasIndex(c => c.GuildId)
|
|
|
|
|
.IsUnique();
|
|
|
|
|
|
2016-08-24 13:29:01 +00:00
|
|
|
|
#endregion
|
2016-08-25 17:23:47 +00:00
|
|
|
|
|
2016-09-10 19:40:25 +00:00
|
|
|
|
#region BotConfig
|
|
|
|
|
var botConfigEntity = modelBuilder.Entity<BotConfig>();
|
|
|
|
|
//botConfigEntity
|
|
|
|
|
// .HasMany(c => c.ModulePrefixes)
|
|
|
|
|
// .WithOne(mp => mp.BotConfig)
|
|
|
|
|
// .HasForeignKey(mp => mp.BotConfigId);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2016-08-25 17:23:47 +00:00
|
|
|
|
#region ClashOfClans
|
|
|
|
|
|
|
|
|
|
var callersEntity = modelBuilder.Entity<ClashCaller>();
|
|
|
|
|
callersEntity
|
|
|
|
|
.HasOne(c => c.ClashWar)
|
|
|
|
|
.WithMany(c => c.Bases);
|
|
|
|
|
|
|
|
|
|
#endregion
|
2016-08-26 17:25:54 +00:00
|
|
|
|
|
|
|
|
|
#region Self Assignable Roles
|
|
|
|
|
|
|
|
|
|
var selfassignableRolesEntity = modelBuilder.Entity<SelfAssignedRole>();
|
|
|
|
|
|
|
|
|
|
selfassignableRolesEntity
|
|
|
|
|
.HasIndex(s => new { s.GuildId, s.RoleId })
|
|
|
|
|
.IsUnique();
|
|
|
|
|
|
|
|
|
|
#endregion
|
2016-08-28 20:59:12 +00:00
|
|
|
|
|
|
|
|
|
#region Repeater
|
|
|
|
|
|
|
|
|
|
var repeaterEntity = modelBuilder.Entity<Repeater>();
|
|
|
|
|
|
|
|
|
|
repeaterEntity
|
|
|
|
|
.HasIndex(r => r.ChannelId)
|
|
|
|
|
.IsUnique();
|
|
|
|
|
|
|
|
|
|
#endregion
|
2016-08-30 01:17:16 +00:00
|
|
|
|
|
|
|
|
|
#region Currency
|
|
|
|
|
var currencyEntity = modelBuilder.Entity<Currency>();
|
|
|
|
|
|
|
|
|
|
currencyEntity
|
|
|
|
|
.HasIndex(c => c.UserId)
|
|
|
|
|
.IsUnique();
|
|
|
|
|
#endregion
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-09-27 13:26:37 +00:00
|
|
|
|
#region Permission
|
|
|
|
|
var permissionEntity = modelBuilder.Entity<Permission>();
|
|
|
|
|
permissionEntity
|
|
|
|
|
.HasOne(p => p.Next)
|
2016-10-07 13:00:42 +00:00
|
|
|
|
.WithOne(p => p.Previous)
|
|
|
|
|
.IsRequired(false);
|
2016-09-27 13:26:37 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2016-09-05 10:27:58 +00:00
|
|
|
|
#region LogSettings
|
|
|
|
|
|
|
|
|
|
//var logSettingEntity = modelBuilder.Entity<LogSetting>();
|
|
|
|
|
|
|
|
|
|
//logSettingEntity
|
|
|
|
|
// .HasMany(ls => ls.IgnoredChannels)
|
|
|
|
|
// .WithOne(ls => ls.LogSetting)
|
|
|
|
|
// .HasPrincipalKey(ls => ls.id;
|
|
|
|
|
|
|
|
|
|
//logSettingEntity
|
|
|
|
|
// .HasMany(ls => ls.IgnoredVoicePresenceChannelIds)
|
|
|
|
|
// .WithOne(ls => ls.LogSetting);
|
|
|
|
|
#endregion
|
2016-10-02 01:00:03 +00:00
|
|
|
|
|
|
|
|
|
#region MusicPlaylists
|
|
|
|
|
var musicPlaylistEntity = modelBuilder.Entity<MusicPlaylist>();
|
|
|
|
|
|
|
|
|
|
musicPlaylistEntity
|
2016-10-02 02:15:57 +00:00
|
|
|
|
.HasMany(p => p.Songs)
|
2016-10-02 01:00:03 +00:00
|
|
|
|
.WithOne()
|
|
|
|
|
.OnDelete(Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Cascade);
|
2016-11-27 02:51:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region PokeGame
|
|
|
|
|
var pokeGameEntity = modelBuilder.Entity<UserPokeTypes>();
|
|
|
|
|
|
|
|
|
|
pokeGameEntity
|
|
|
|
|
.HasIndex(pt => pt.UserId)
|
|
|
|
|
.IsUnique();
|
|
|
|
|
|
2016-10-02 01:00:03 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2016-08-24 13:29:01 +00:00
|
|
|
|
}
|
2016-08-24 01:32:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|