feat: added database
This commit is contained in:
parent
baf797d8c3
commit
c7b933b3f8
9 changed files with 281 additions and 80 deletions
|
@ -12,7 +12,8 @@ namespace Sharpy.Commands.Music
|
|||
{
|
||||
[SlashCommand("play", "Plays a song")]
|
||||
[SlashRequireGuild]
|
||||
public async Task PlayCommand(InteractionContext ctx, [Option("song", "The song to play. (Accepts YouTube URLs too)")] string song)
|
||||
public async Task PlayCommand(InteractionContext ctx,
|
||||
[Option("song", "The song to play. (Accepts YouTube URLs too)")] string song)
|
||||
{
|
||||
if (ctx.Member.VoiceState == null || ctx.Member.VoiceState.Channel == null)
|
||||
{
|
||||
|
|
|
@ -12,7 +12,8 @@ namespace Sharpy.Commands.Music
|
|||
{
|
||||
[SlashCommand("search", "Searches for songs")]
|
||||
[SlashRequireGuild]
|
||||
public async Task SearchCommand(InteractionContext ctx, [Option("search", "The song to search for. (Accepts YouTube URLs too)")] string search)
|
||||
public async Task SearchCommand(InteractionContext ctx,
|
||||
[Option("search", "The song to search for. (Accepts YouTube URLs too)")] string search)
|
||||
{
|
||||
var lava = ctx.Client.GetLavalink();
|
||||
|
||||
|
|
17
Sharpy/Database/Context.cs
Normal file
17
Sharpy/Database/Context.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Sharpy.Database.Models;
|
||||
|
||||
namespace Sharpy.Database
|
||||
{
|
||||
public class Context : DbContext
|
||||
{
|
||||
public DbSet<Infractions> Infractions { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(
|
||||
$"Host={Sharpy.config.GetSection("database").GetValue<string>("host")};Port={Sharpy.config.GetSection("database").GetValue<string>("port")};Database={Sharpy.config.GetSection("database").GetValue<string>("database")};Username={Sharpy.config.GetSection("database").GetValue<string>("username")};Password={Sharpy.config.GetSection("database").GetValue<string>("password")}");
|
||||
}
|
||||
}
|
||||
}
|
28
Sharpy/Database/Models/Infractions.cs
Normal file
28
Sharpy/Database/Models/Infractions.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Sharpy.Database.Models
|
||||
{
|
||||
public class Infractions
|
||||
{
|
||||
[Key]
|
||||
public Guid InfractionId { get; set; }
|
||||
|
||||
[Required]
|
||||
public InfractionTypes InfractionType { get; set; }
|
||||
|
||||
[Required]
|
||||
public string InfractionReason { get; set; }
|
||||
|
||||
[Required]
|
||||
public ulong UserId { get; set; }
|
||||
}
|
||||
|
||||
public enum InfractionTypes
|
||||
{
|
||||
Ban,
|
||||
Kick,
|
||||
Mute,
|
||||
Warn
|
||||
}
|
||||
}
|
50
Sharpy/Migrations/20211016030853_InitialCreate.Designer.cs
generated
Normal file
50
Sharpy/Migrations/20211016030853_InitialCreate.Designer.cs
generated
Normal file
|
@ -0,0 +1,50 @@
|
|||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using Sharpy.Database;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Sharpy.Migrations
|
||||
{
|
||||
[DbContext(typeof(Context))]
|
||||
[Migration("20211016030853_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.0-rc.2.21480.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Sharpy.Database.Models.Infractions", b =>
|
||||
{
|
||||
b.Property<Guid>("InfractionId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("InfractionReason")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("InfractionType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<decimal>("UserId")
|
||||
.HasColumnType("numeric(20,0)");
|
||||
|
||||
b.HasKey("InfractionId");
|
||||
|
||||
b.ToTable("Infractions");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
33
Sharpy/Migrations/20211016030853_InitialCreate.cs
Normal file
33
Sharpy/Migrations/20211016030853_InitialCreate.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Sharpy.Migrations
|
||||
{
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Infractions",
|
||||
columns: table => new
|
||||
{
|
||||
InfractionId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
InfractionType = table.Column<int>(type: "integer", nullable: false),
|
||||
InfractionReason = table.Column<string>(type: "text", nullable: false),
|
||||
UserId = table.Column<decimal>(type: "numeric(20,0)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Infractions", x => x.InfractionId);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Infractions");
|
||||
}
|
||||
}
|
||||
}
|
48
Sharpy/Migrations/ContextModelSnapshot.cs
Normal file
48
Sharpy/Migrations/ContextModelSnapshot.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using Sharpy.Database;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Sharpy.Migrations
|
||||
{
|
||||
[DbContext(typeof(Context))]
|
||||
partial class ContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.0-rc.2.21480.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Sharpy.Database.Models.Infractions", b =>
|
||||
{
|
||||
b.Property<Guid>("InfractionId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("InfractionReason")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("InfractionType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<decimal>("UserId")
|
||||
.HasColumnType("numeric(20,0)");
|
||||
|
||||
b.HasKey("InfractionId");
|
||||
|
||||
b.ToTable("Infractions");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
#if RELEASE
|
||||
using System.Net;
|
||||
#endif
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
|
@ -13,11 +10,20 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Sharpy.Commands.General;
|
||||
using Sharpy.Commands.Music;
|
||||
#if RELEASE
|
||||
using System.Net;
|
||||
#endif
|
||||
|
||||
IConfiguration config = new ConfigurationBuilder()
|
||||
namespace Sharpy
|
||||
{
|
||||
public static class Sharpy
|
||||
{
|
||||
public static readonly IConfiguration config = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json", false, true)
|
||||
.Build();
|
||||
|
||||
public static async Task Main()
|
||||
{
|
||||
#if DEBUG
|
||||
var discord = new DiscordClient(new DiscordConfiguration
|
||||
{
|
||||
|
@ -92,3 +98,6 @@ await lavalink.ConnectAsync(new LavalinkConfiguration
|
|||
});
|
||||
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Nullable>disable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Configurations>Release;Debug</Configurations>
|
||||
<Platforms>x64</Platforms>
|
||||
|
@ -39,11 +39,21 @@
|
|||
<PackageReference Include="DSharpPlus.Lavalink" Version="4.2.0-nightly-01030" />
|
||||
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.2.0-nightly-01030" />
|
||||
<PackageReference Include="Hardware.Info" Version="1.1.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-rc.2.21480.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-rc.2.21480.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0-rc.2.21480.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0-rc.2.21480.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0-rc.2.21480.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0-rc.2.21480.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0-rc.2.21480.5" />
|
||||
<PackageReference Include="NATS.Client" Version="0.14.0-pre3" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-rc.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -52,4 +62,8 @@
|
|||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Commands\Moderation" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Reference in a new issue