Ok NOW i pushed everything
This commit is contained in:
parent
b8110760aa
commit
7f20934311
@ -1,41 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
namespace NadekoBot.Migrations
|
|
||||||
{
|
|
||||||
public partial class QuoteMigration : Migration
|
|
||||||
{
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Quotes",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(nullable: false)
|
|
||||||
.Annotation("Autoincrement", true),
|
|
||||||
AuthorId = table.Column<ulong>(nullable: false),
|
|
||||||
AuthorName = table.Column<string>(nullable: false),
|
|
||||||
GuildId = table.Column<ulong>(nullable: false),
|
|
||||||
Keyword = table.Column<string>(nullable: false),
|
|
||||||
Text = table.Column<string>(nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Quotes", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Quotes_GuildId_Keyword",
|
|
||||||
table: "Quotes",
|
|
||||||
columns: new[] { "GuildId", "Keyword" },
|
|
||||||
unique: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Quotes");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,14 +8,50 @@ using NadekoBot.Services.Database.Impl;
|
|||||||
namespace NadekoBot.Migrations
|
namespace NadekoBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(NadekoSqliteContext))]
|
[DbContext(typeof(NadekoSqliteContext))]
|
||||||
[Migration("20160824125525_QuoteMigration")]
|
[Migration("20160824184118_FirstMigration")]
|
||||||
partial class QuoteMigration
|
partial class FirstMigration
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431");
|
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431");
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Config", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<bool>("DeleteMessageOnCommand");
|
||||||
|
|
||||||
|
b.Property<ulong>("GuildId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("GuildId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Configs");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Donator", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<int>("Amount");
|
||||||
|
|
||||||
|
b.Property<string>("Name");
|
||||||
|
|
||||||
|
b.Property<ulong>("UserId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Donators");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -36,9 +72,6 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("GuildId", "Keyword")
|
|
||||||
.IsUnique();
|
|
||||||
|
|
||||||
b.ToTable("Quotes");
|
b.ToTable("Quotes");
|
||||||
});
|
});
|
||||||
}
|
}
|
82
src/NadekoBot/Migrations/20160824184118_FirstMigration.cs
Normal file
82
src/NadekoBot/Migrations/20160824184118_FirstMigration.cs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations
|
||||||
|
{
|
||||||
|
public partial class FirstMigration : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Configs",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
DeleteMessageOnCommand = table.Column<bool>(nullable: false),
|
||||||
|
GuildId = table.Column<ulong>(nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Configs", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Donators",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
Amount = table.Column<int>(nullable: false),
|
||||||
|
Name = table.Column<string>(nullable: true),
|
||||||
|
UserId = table.Column<ulong>(nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Donators", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Quotes",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Autoincrement", true),
|
||||||
|
AuthorId = table.Column<ulong>(nullable: false),
|
||||||
|
AuthorName = table.Column<string>(nullable: false),
|
||||||
|
GuildId = table.Column<ulong>(nullable: false),
|
||||||
|
Keyword = table.Column<string>(nullable: false),
|
||||||
|
Text = table.Column<string>(nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Quotes", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Configs_GuildId",
|
||||||
|
table: "Configs",
|
||||||
|
column: "GuildId",
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Donators_UserId",
|
||||||
|
table: "Donators",
|
||||||
|
column: "UserId",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Configs");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Donators");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Quotes");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,42 @@ namespace NadekoBot.Migrations
|
|||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431");
|
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431");
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Config", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<bool>("DeleteMessageOnCommand");
|
||||||
|
|
||||||
|
b.Property<ulong>("GuildId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("GuildId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Configs");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Donator", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<int>("Amount");
|
||||||
|
|
||||||
|
b.Property<string>("Name");
|
||||||
|
|
||||||
|
b.Property<ulong>("UserId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Donators");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -35,9 +71,6 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("GuildId", "Keyword")
|
|
||||||
.IsUnique();
|
|
||||||
|
|
||||||
b.ToTable("Quotes");
|
b.ToTable("Quotes");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task CalcOperations(IMessage msg)
|
public async Task CalcOps(IMessage msg)
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
var selection = typeof(Math).GetTypeInfo().GetMethods().Except(typeof(object).GetTypeInfo().GetMethods()).Select(x =>
|
var selection = typeof(Math).GetTypeInfo().GetMethods().Except(typeof(object).GetTypeInfo().GetMethods()).Select(x =>
|
||||||
|
93
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
93
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -213,7 +213,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to ...
|
/// Looks up a localized string similar to ..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string addquote_text {
|
public static string addquote_text {
|
||||||
get {
|
get {
|
||||||
@ -896,6 +896,33 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Shows all available operations in .calc command.
|
||||||
|
/// </summary>
|
||||||
|
public static string calcops_desc {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("calcops_desc", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to `.calcops`.
|
||||||
|
/// </summary>
|
||||||
|
public static string calcops_summary {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("calcops_summary", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to calcops.
|
||||||
|
/// </summary>
|
||||||
|
public static string calcops_text {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("calcops_text", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Evaluate a mathematical expression..
|
/// Looks up a localized string similar to Evaluate a mathematical expression..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -1949,6 +1976,33 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Deletes all quotes on a specified keyword..
|
||||||
|
/// </summary>
|
||||||
|
public static string delallquotes_desc {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("delallquotes_desc", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to `.delallq`.
|
||||||
|
/// </summary>
|
||||||
|
public static string delallquotes_summary {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("delallquotes_summary", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to delallq.
|
||||||
|
/// </summary>
|
||||||
|
public static string delallquotes_text {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("delallquotes_text", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Deletes a custom reaction with given name (and index). **Bot Owner Only.**.
|
/// Looks up a localized string similar to Deletes a custom reaction with given name (and index). **Bot Owner Only.**.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -2013,7 +2067,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to `..qdel abc`.
|
/// Looks up a localized string similar to `.delq abc`.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string deletequote_summary {
|
public static string deletequote_summary {
|
||||||
get {
|
get {
|
||||||
@ -2022,11 +2076,11 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to ..qdel.
|
/// Looks up a localized string similar to deletequote.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string deletequtoe_text {
|
public static string deletequote_text {
|
||||||
get {
|
get {
|
||||||
return ResourceManager.GetString("deletequtoe_text", resourceCulture);
|
return ResourceManager.GetString("deletequote_text", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4730,33 +4784,6 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Shows a random quote..
|
|
||||||
/// </summary>
|
|
||||||
public static string quote_desc {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("quote_desc", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to `~quote`.
|
|
||||||
/// </summary>
|
|
||||||
public static string quote_summary {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("quote_summary", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to quote.
|
|
||||||
/// </summary>
|
|
||||||
public static string quote_text {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("quote_text", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Starts a new animal race..
|
/// Looks up a localized string similar to Starts a new animal race..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -6153,7 +6180,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to ....
|
/// Looks up a localized string similar to ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string showquote_text {
|
public static string showquote_text {
|
||||||
get {
|
get {
|
||||||
|
@ -1288,7 +1288,7 @@
|
|||||||
<value>`;acmdcds`</value>
|
<value>`;acmdcds`</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="addquote_text" xml:space="preserve">
|
<data name="addquote_text" xml:space="preserve">
|
||||||
<value>..</value>
|
<value>.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="addquote_desc" xml:space="preserve">
|
<data name="addquote_desc" xml:space="preserve">
|
||||||
<value>Adds a new quote with the specified name (single word) and message (no limit).</value>
|
<value>Adds a new quote with the specified name (single word) and message (no limit).</value>
|
||||||
@ -1297,7 +1297,7 @@
|
|||||||
<value>`.. abc My message`</value>
|
<value>`.. abc My message`</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="showquote_text" xml:space="preserve">
|
<data name="showquote_text" xml:space="preserve">
|
||||||
<value>...</value>
|
<value>..</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="showquote_desc" xml:space="preserve">
|
<data name="showquote_desc" xml:space="preserve">
|
||||||
<value>Shows a random quote with a specified name.</value>
|
<value>Shows a random quote with a specified name.</value>
|
||||||
@ -1305,14 +1305,14 @@
|
|||||||
<data name="showquote_summary" xml:space="preserve">
|
<data name="showquote_summary" xml:space="preserve">
|
||||||
<value>`... abc`</value>
|
<value>`... abc`</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="deletequtoe_text" xml:space="preserve">
|
<data name="deletequote_text" xml:space="preserve">
|
||||||
<value>..qdel</value>
|
<value>deletequote</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="deletequote_desc" xml:space="preserve">
|
<data name="deletequote_desc" xml:space="preserve">
|
||||||
<value>Deletes all quotes with the specified keyword. You have to either be bot owner or the creator of the quote to delete it.</value>
|
<value>Deletes all quotes with the specified keyword. You have to either be bot owner or the creator of the quote to delete it.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="deletequote_summary" xml:space="preserve">
|
<data name="deletequote_summary" xml:space="preserve">
|
||||||
<value>`..qdel abc`</value>
|
<value>`.delq abc`</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="rip_text" xml:space="preserve">
|
<data name="rip_text" xml:space="preserve">
|
||||||
<value>rip</value>
|
<value>rip</value>
|
||||||
@ -2241,15 +2241,6 @@
|
|||||||
<data name="hashtag_summary" xml:space="preserve">
|
<data name="hashtag_summary" xml:space="preserve">
|
||||||
<value>`~# ff`</value>
|
<value>`~# ff`</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="quote_text" xml:space="preserve">
|
|
||||||
<value>quote</value>
|
|
||||||
</data>
|
|
||||||
<data name="quote_desc" xml:space="preserve">
|
|
||||||
<value>Shows a random quote.</value>
|
|
||||||
</data>
|
|
||||||
<data name="quote_summary" xml:space="preserve">
|
|
||||||
<value>`~quote`</value>
|
|
||||||
</data>
|
|
||||||
<data name="catfact_text" xml:space="preserve">
|
<data name="catfact_text" xml:space="preserve">
|
||||||
<value>catfact</value>
|
<value>catfact</value>
|
||||||
</data>
|
</data>
|
||||||
@ -2619,4 +2610,22 @@
|
|||||||
<data name="guide_text" xml:space="preserve">
|
<data name="guide_text" xml:space="preserve">
|
||||||
<value>readme</value>
|
<value>readme</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="calcops_desc" xml:space="preserve">
|
||||||
|
<value>Shows all available operations in .calc command</value>
|
||||||
|
</data>
|
||||||
|
<data name="calcops_summary" xml:space="preserve">
|
||||||
|
<value>`.calcops`</value>
|
||||||
|
</data>
|
||||||
|
<data name="calcops_text" xml:space="preserve">
|
||||||
|
<value>calcops</value>
|
||||||
|
</data>
|
||||||
|
<data name="delallquotes_desc" xml:space="preserve">
|
||||||
|
<value>Deletes all quotes on a specified keyword.</value>
|
||||||
|
</data>
|
||||||
|
<data name="delallquotes_summary" xml:space="preserve">
|
||||||
|
<value>`.delallq`</value>
|
||||||
|
</data>
|
||||||
|
<data name="delallquotes_text" xml:space="preserve">
|
||||||
|
<value>delallq</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -10,7 +10,9 @@ namespace NadekoBot.Services.Database
|
|||||||
{
|
{
|
||||||
public abstract class NadekoContext : DbContext
|
public abstract class NadekoContext : DbContext
|
||||||
{
|
{
|
||||||
public DbSet<Quote> Quotes { get; }
|
public DbSet<Quote> Quotes { get; set; }
|
||||||
|
public DbSet<Donator> Donators { get; set; }
|
||||||
|
public DbSet<Config> Configs { get; set; }
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
@ -39,6 +41,9 @@ namespace NadekoBot.Services.Database
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
protected abstract override void OnConfiguring(DbContextOptionsBuilder optionsBuilder);
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlite("Filename=./data/NadekoBot.sqlite");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using NadekoBot.Services.Database.Models;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace NadekoBot.Services.Database.Repositories
|
|
||||||
{
|
|
||||||
//some guy from stack overflow wrotethis, thanks to him :D
|
|
||||||
public static class Extensions
|
|
||||||
{
|
|
||||||
public static TEntity Find<TEntity>(this DbSet<TEntity> set, params object[] keyValues) where TEntity : DbEntity
|
|
||||||
{
|
|
||||||
var context = ((IInfrastructure<IServiceProvider>)set).GetService<DbContext>();
|
|
||||||
|
|
||||||
var entityType = context.Model.FindEntityType(typeof(TEntity));
|
|
||||||
var key = entityType.FindPrimaryKey();
|
|
||||||
|
|
||||||
var entries = context.ChangeTracker.Entries<TEntity>();
|
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
foreach (var property in key.Properties)
|
|
||||||
{
|
|
||||||
entries = entries.Where(e => e.Property(property.Name).CurrentValue == keyValues[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
var entry = entries.FirstOrDefault();
|
|
||||||
if (entry != null)
|
|
||||||
{
|
|
||||||
// Return the local object if it exists.
|
|
||||||
return entry.Entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set.Where(x => x.Id == keyValues[0]);
|
|
||||||
var parameter = Expression.Parameter(typeof(TEntity), "x");
|
|
||||||
var query = set.Where((Expression<Func<TEntity, bool>>)
|
|
||||||
Expression.Lambda(
|
|
||||||
Expression.Equal(
|
|
||||||
Expression.Property(parameter, "Id"),
|
|
||||||
Expression.Constant(keyValues[0])),
|
|
||||||
parameter));
|
|
||||||
|
|
||||||
// Look in the database
|
|
||||||
return query.FirstOrDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,19 +16,21 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
|
|
||||||
public Donator AddOrUpdateDonator(ulong userId, string name, int amount)
|
public Donator AddOrUpdateDonator(ulong userId, string name, int amount)
|
||||||
{
|
{
|
||||||
var donator = _set.Find(userId);
|
var donator = _set.Where(d => d.UserId == userId).FirstOrDefault();
|
||||||
|
|
||||||
if (donator == null)
|
if (donator == null)
|
||||||
{
|
{
|
||||||
_set.Add(donator = new Donator
|
_set.Add(donator = new Donator
|
||||||
{
|
{
|
||||||
Amount = amount,
|
Amount = amount,
|
||||||
UserId = userId
|
UserId = userId,
|
||||||
|
Name = name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
donator.Amount += amount;
|
donator.Amount += amount;
|
||||||
|
donator.Name = name;
|
||||||
_set.Update(donator);
|
_set.Update(donator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
public IEnumerable<Quote> GetAllQuotesByKeyword(string keyword) =>
|
public IEnumerable<Quote> GetAllQuotesByKeyword(string keyword) =>
|
||||||
_set.Where(q => q.Keyword == keyword);
|
_set.Where(q => q.Keyword == keyword);
|
||||||
|
|
||||||
public Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string text)
|
public Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword)
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new Random();
|
||||||
return _set.Where(q => q.Text == text).OrderBy(q => rng.Next()).FirstOrDefaultAsync();
|
return _set.Where(q => q.Keyword == keyword).OrderBy(q => rng.Next()).FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,13 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
_set.AddRange(objs);
|
_set.AddRange(objs);
|
||||||
|
|
||||||
public T Get(int id) =>
|
public T Get(int id) =>
|
||||||
_set.Find(id);
|
_set.FirstOrDefault(e => e.Id == id);
|
||||||
|
|
||||||
public IEnumerable<T> GetAll() =>
|
public IEnumerable<T> GetAll() =>
|
||||||
_set.ToList();
|
_set.ToList();
|
||||||
|
|
||||||
public void Remove(int id) =>
|
public void Remove(int id) =>
|
||||||
_set.Remove(_set.Find(id));
|
_set.Remove(this.Get(id));
|
||||||
|
|
||||||
public void Remove(T obj) =>
|
public void Remove(T obj) =>
|
||||||
_set.Remove(obj);
|
_set.Remove(obj);
|
||||||
|
@ -23,7 +23,7 @@ namespace NadekoBot.Services.Database
|
|||||||
|
|
||||||
public UnitOfWork(NadekoContext context)
|
public UnitOfWork(NadekoContext context)
|
||||||
{
|
{
|
||||||
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Complete() =>
|
public int Complete() =>
|
||||||
|
Loading…
Reference in New Issue
Block a user