diff --git a/Sharpy/Commands/Music/Play.cs b/Sharpy/Commands/Music/Play.cs index 16c3dac..534dfc7 100644 --- a/Sharpy/Commands/Music/Play.cs +++ b/Sharpy/Commands/Music/Play.cs @@ -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) { diff --git a/Sharpy/Commands/Music/Search.cs b/Sharpy/Commands/Music/Search.cs index 3fc22a4..c5e7420 100644 --- a/Sharpy/Commands/Music/Search.cs +++ b/Sharpy/Commands/Music/Search.cs @@ -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(); diff --git a/Sharpy/Database/Context.cs b/Sharpy/Database/Context.cs new file mode 100644 index 0000000..8910769 --- /dev/null +++ b/Sharpy/Database/Context.cs @@ -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 { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseNpgsql( + $"Host={Sharpy.config.GetSection("database").GetValue("host")};Port={Sharpy.config.GetSection("database").GetValue("port")};Database={Sharpy.config.GetSection("database").GetValue("database")};Username={Sharpy.config.GetSection("database").GetValue("username")};Password={Sharpy.config.GetSection("database").GetValue("password")}"); + } + } +} diff --git a/Sharpy/Database/Models/Infractions.cs b/Sharpy/Database/Models/Infractions.cs new file mode 100644 index 0000000..1fa44a2 --- /dev/null +++ b/Sharpy/Database/Models/Infractions.cs @@ -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 + } +} diff --git a/Sharpy/Migrations/20211016030853_InitialCreate.Designer.cs b/Sharpy/Migrations/20211016030853_InitialCreate.Designer.cs new file mode 100644 index 0000000..ae49320 --- /dev/null +++ b/Sharpy/Migrations/20211016030853_InitialCreate.Designer.cs @@ -0,0 +1,50 @@ +// +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("InfractionId") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("InfractionReason") + .IsRequired() + .HasColumnType("text"); + + b.Property("InfractionType") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("numeric(20,0)"); + + b.HasKey("InfractionId"); + + b.ToTable("Infractions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sharpy/Migrations/20211016030853_InitialCreate.cs b/Sharpy/Migrations/20211016030853_InitialCreate.cs new file mode 100644 index 0000000..2802e11 --- /dev/null +++ b/Sharpy/Migrations/20211016030853_InitialCreate.cs @@ -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(type: "uuid", nullable: false), + InfractionType = table.Column(type: "integer", nullable: false), + InfractionReason = table.Column(type: "text", nullable: false), + UserId = table.Column(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"); + } + } +} diff --git a/Sharpy/Migrations/ContextModelSnapshot.cs b/Sharpy/Migrations/ContextModelSnapshot.cs new file mode 100644 index 0000000..6cc996d --- /dev/null +++ b/Sharpy/Migrations/ContextModelSnapshot.cs @@ -0,0 +1,48 @@ +// +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("InfractionId") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("InfractionReason") + .IsRequired() + .HasColumnType("text"); + + b.Property("InfractionType") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("numeric(20,0)"); + + b.HasKey("InfractionId"); + + b.ToTable("Infractions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sharpy/Program.cs b/Sharpy/Program.cs index e4a0883..e96b6a4 100644 --- a/Sharpy/Program.cs +++ b/Sharpy/Program.cs @@ -1,7 +1,4 @@ using System; -#if RELEASE -using System.Net; -#endif using System.Threading.Tasks; using DSharpPlus; using DSharpPlus.Entities; @@ -13,82 +10,94 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Sharpy.Commands.General; using Sharpy.Commands.Music; - -IConfiguration config = new ConfigurationBuilder() - .AddJsonFile("appsettings.json", false, true) - .Build(); - -#if DEBUG -var discord = new DiscordClient(new DiscordConfiguration -{ - AlwaysCacheMembers = true, - AutoReconnect = true, - GatewayCompressionLevel = GatewayCompressionLevel.Stream, - HttpTimeout = TimeSpan.FromSeconds(10), - Intents = DiscordIntents.All, - LogTimestampFormat = "MMM dd yyyy - hh:mm:ss tt", - MinimumLogLevel = LogLevel.Debug, - ReconnectIndefinitely = false, - Token = config.GetValue("token"), - TokenType = TokenType.Bot -}); -#else -var discord = new DiscordClient(new DiscordConfiguration -{ - AlwaysCacheMembers = true, - AutoReconnect = true, - GatewayCompressionLevel = GatewayCompressionLevel.Stream, - HttpTimeout = TimeSpan.FromSeconds(10), - Intents = DiscordIntents.All, - LogTimestampFormat = "MMM dd yyyy - hh:mm:ss tt", - MinimumLogLevel = LogLevel.Information, - ReconnectIndefinitely = false, - ShardCount = Convert.ToInt32(Dns.GetHostName().Substring(Dns.GetHostName().IndexOf('-') + 1)), - ShardId = Convert.ToInt32(Dns.GetHostName().Substring(Dns.GetHostName().IndexOf('-') + 1)), - Token = config.GetValue("token"), - TokenType = TokenType.Bot, -}); +#if RELEASE +using System.Net; #endif -var services = new ServiceCollection() - .BuildServiceProvider(); - -// Register Lavalink -var lavalink = discord.UseLavalink(); - -// Register Slash Commands -var slash = discord.UseSlashCommands(new SlashCommandsConfiguration +namespace Sharpy { - Services = services -}); - -// Register Commands -// General -slash.RegisterCommands(772228301552222258); - -// Music -slash.RegisterCommands(772228301552222258); -slash.RegisterCommands(772228301552222258); - -await discord.ConnectAsync(new DiscordActivity("With DSharpPlus")); -await lavalink.ConnectAsync(new LavalinkConfiguration -{ - Password = config.GetSection("lavalink").GetValue("password"), - RestEndpoint = new ConnectionEndpoint + public static class Sharpy { - Hostname = config.GetSection("lavalink").GetValue("host"), - Port = config.GetSection("lavalink").GetValue("port"), - Secured = false - }, - ResumeTimeout = 30, - SocketAutoReconnect = true, - SocketEndpoint = new ConnectionEndpoint - { - Hostname = config.GetSection("lavalink").GetValue("host"), - Port = config.GetSection("lavalink").GetValue("port"), - Secured = false - }, - WebSocketCloseTimeout = 30 -}); + public static readonly IConfiguration config = new ConfigurationBuilder() + .AddJsonFile("appsettings.json", false, true) + .Build(); -await Task.Delay(-1); + public static async Task Main() + { +#if DEBUG + var discord = new DiscordClient(new DiscordConfiguration + { + AlwaysCacheMembers = true, + AutoReconnect = true, + GatewayCompressionLevel = GatewayCompressionLevel.Stream, + HttpTimeout = TimeSpan.FromSeconds(10), + Intents = DiscordIntents.All, + LogTimestampFormat = "MMM dd yyyy - hh:mm:ss tt", + MinimumLogLevel = LogLevel.Debug, + ReconnectIndefinitely = false, + Token = config.GetValue("token"), + TokenType = TokenType.Bot + }); +#else + var discord = new DiscordClient(new DiscordConfiguration + { + AlwaysCacheMembers = true, + AutoReconnect = true, + GatewayCompressionLevel = GatewayCompressionLevel.Stream, + HttpTimeout = TimeSpan.FromSeconds(10), + Intents = DiscordIntents.All, + LogTimestampFormat = "MMM dd yyyy - hh:mm:ss tt", + MinimumLogLevel = LogLevel.Information, + ReconnectIndefinitely = false, + ShardCount = Convert.ToInt32(Dns.GetHostName().Substring(Dns.GetHostName().IndexOf('-') + 1)), + ShardId = Convert.ToInt32(Dns.GetHostName().Substring(Dns.GetHostName().IndexOf('-') + 1)), + Token = config.GetValue("token"), + TokenType = TokenType.Bot, + }); +#endif + + var services = new ServiceCollection() + .BuildServiceProvider(); + + // Register Lavalink + var lavalink = discord.UseLavalink(); + + // Register Slash Commands + var slash = discord.UseSlashCommands(new SlashCommandsConfiguration + { + Services = services + }); + + // Register Commands + // General + slash.RegisterCommands(772228301552222258); + + // Music + slash.RegisterCommands(772228301552222258); + slash.RegisterCommands(772228301552222258); + + await discord.ConnectAsync(new DiscordActivity("With DSharpPlus")); + await lavalink.ConnectAsync(new LavalinkConfiguration + { + Password = config.GetSection("lavalink").GetValue("password"), + RestEndpoint = new ConnectionEndpoint + { + Hostname = config.GetSection("lavalink").GetValue("host"), + Port = config.GetSection("lavalink").GetValue("port"), + Secured = false + }, + ResumeTimeout = 30, + SocketAutoReconnect = true, + SocketEndpoint = new ConnectionEndpoint + { + Hostname = config.GetSection("lavalink").GetValue("host"), + Port = config.GetSection("lavalink").GetValue("port"), + Secured = false + }, + WebSocketCloseTimeout = 30 + }); + + await Task.Delay(-1); + } + } +} diff --git a/Sharpy/Sharpy.csproj b/Sharpy/Sharpy.csproj index 705196c..806c6a9 100644 --- a/Sharpy/Sharpy.csproj +++ b/Sharpy/Sharpy.csproj @@ -3,7 +3,7 @@ Exe net6.0 - enable + disable false Release;Debug x64 @@ -39,11 +39,21 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + @@ -52,4 +62,8 @@ + + + +