diff --git a/DiscordBot/Commands/ControlCommands.cs b/DiscordBot/Commands/ControlCommands.cs index 3bbab05..20ae80f 100644 --- a/DiscordBot/Commands/ControlCommands.cs +++ b/DiscordBot/Commands/ControlCommands.cs @@ -1,6 +1,9 @@ -using Discord; +using System.ComponentModel.DataAnnotations; +using Discord; using Discord.Interactions; using Discord.WebSocket; +using Microsoft.EntityFrameworkCore; +using OpenShock.DiscordBot.OpenShockDiscordDb; namespace OpenShock.DiscordBot.Commands; @@ -8,9 +11,19 @@ namespace OpenShock.DiscordBot.Commands; [IntegrationType(ApplicationIntegrationType.UserInstall, ApplicationIntegrationType.GuildInstall)] public sealed class ControlCommands : InteractionModuleBase { + private readonly OpenShockDiscordContext _db; + + public ControlCommands(OpenShockDiscordContext db) + { + _db = db; + } + [SlashCommand("shock", "Shock a friend that has whitelisted you before")] - public async Task ShockCommand(SocketUser user) + public async Task ShockCommand(SocketUser user, [Range(1, 100)] byte intensity = 50, [Range(0.3, 30)] float duration = 5) { - await RespondAsync("Shocking " + user.Mention + "!"); + await RespondAsync("hiii lol"); + var friend = await _db.UsersFriendwhitelists.FirstOrDefaultAsync(x => x.WhitelistedFriend == Context.User.Id && x.User == user.Id); + + } } \ No newline at end of file diff --git a/DiscordBot/Commands/SetupCommands.cs b/DiscordBot/Commands/SetupCommands.cs new file mode 100644 index 0000000..cd0c6ed --- /dev/null +++ b/DiscordBot/Commands/SetupCommands.cs @@ -0,0 +1,40 @@ +using Discord; +using Discord.Interactions; +using Microsoft.Extensions.Logging; +using OpenShock.DiscordBot.OpenShockDiscordDb; +using OpenShock.SDK.CSharp; + +namespace OpenShock.DiscordBot.Commands; + +[CommandContextType(InteractionContextType.Guild, + InteractionContextType.BotDm, InteractionContextType.PrivateChannel)] +public sealed class SetupCommands : InteractionModuleBase +{ + private readonly OpenShockDiscordContext _db; + private readonly ILogger _logger; + + /// + /// Default constructor for the SetupCommand + /// + /// + /// + public SetupCommands(OpenShockDiscordContext db, ILogger logger) + { + _db = db; + _logger = logger; + } + + [SlashCommand("shocker", "Configure or refresh your shocker settings")] + public async Task ShockerConfig() + { + // var openShockClient = new OpenShockApiClient(new ApiClientOptions() + // { + // Server = + // }) + // + // _db.UsersShockers.Add(new UsersShocker() + // { + // User = + // }); + } +} \ No newline at end of file diff --git a/DiscordBot/Commands/WhitelistCommands.cs b/DiscordBot/Commands/WhitelistCommands.cs new file mode 100644 index 0000000..a405ef9 --- /dev/null +++ b/DiscordBot/Commands/WhitelistCommands.cs @@ -0,0 +1,37 @@ +using Discord; +using Discord.Interactions; +using Discord.WebSocket; +using Microsoft.EntityFrameworkCore; +using OpenShock.DiscordBot.OpenShockDiscordDb; + +namespace OpenShock.DiscordBot.Commands; + +[CommandContextType(InteractionContextType.Guild, InteractionContextType.BotDm, InteractionContextType.PrivateChannel)] +[Group("whitelist", "Whitelist commands for friends to use your shockers")] +public sealed class WhitelistCommands : InteractionModuleBase +{ + private readonly OpenShockDiscordContext _db; + + public WhitelistCommands(OpenShockDiscordContext db) + { + _db = db; + } + + [SlashCommand("add", "Whitelist a friend to use your shockers")] + public async Task AddWhitelist(SocketUser friend) + { + var alreadyWhitelisted = await _db.UsersFriendwhitelists.FirstOrDefaultAsync(x => + x.User == Context.User.Id && x.WhitelistedFriend == friend.Id); + + if (alreadyWhitelisted != null) + { + _db.UsersFriendwhitelists.Add(new UsersFriendwhitelist() + { + User = Context.User.Id, + WhitelistedFriend = friend.Id + }); + } + + await _db.SaveChangesAsync(); + } +} \ No newline at end of file diff --git a/DiscordBot/OpenShockDiscordDb/OpenShockDiscordContext.cs b/DiscordBot/OpenShockDiscordDb/OpenShockDiscordContext.cs index 5108f90..5e3a8d6 100644 --- a/DiscordBot/OpenShockDiscordDb/OpenShockDiscordContext.cs +++ b/DiscordBot/OpenShockDiscordDb/OpenShockDiscordContext.cs @@ -20,6 +20,8 @@ public OpenShockDiscordContext(DbContextOptions options public virtual DbSet Users { get; set; } public virtual DbSet UsersFriendwhitelists { get; set; } + + public virtual DbSet UsersShockers { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -81,11 +83,34 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.ToTable("users_friendwhitelist"); + entity.HasIndex(e => e.WhitelistedFriend, "friend_id").HasAnnotation("Npgsql:StorageParameter:deduplicate_items", "true"); + entity.Property(e => e.User).HasColumnName("user"); entity.Property(e => e.WhitelistedFriend).HasColumnName("whitelisted_friend"); entity.Property(e => e.CreatedOn) .HasDefaultValueSql("CURRENT_TIMESTAMP") .HasColumnName("created_on"); + + entity.HasOne(d => d.UserNavigation).WithMany(p => p.UsersFriendwhitelists) + .HasForeignKey(d => d.User) + .HasConstraintName("fk_user"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.User, e.ShockerId }).HasName("users_shockers_pkey"); + + entity.ToTable("users_shockers"); + + entity.Property(e => e.User).HasColumnName("user"); + entity.Property(e => e.ShockerId).HasColumnName("shocker_id"); + entity.Property(e => e.CreatedAt) + .HasDefaultValueSql("CURRENT_TIMESTAMP") + .HasColumnName("created_at"); + + entity.HasOne(d => d.UserNavigation).WithMany(p => p.UsersShockers) + .HasForeignKey(d => d.User) + .HasConstraintName("fk_user"); }); OnModelCreatingPartial(modelBuilder); diff --git a/DiscordBot/OpenShockDiscordDb/User.cs b/DiscordBot/OpenShockDiscordDb/User.cs index f06a67e..310ded4 100644 --- a/DiscordBot/OpenShockDiscordDb/User.cs +++ b/DiscordBot/OpenShockDiscordDb/User.cs @@ -16,4 +16,8 @@ public partial class User public string ApiKey { get; set; } = null!; public virtual ICollection GuildActiveShockers { get; set; } = new List(); + + public virtual ICollection UsersFriendwhitelists { get; set; } = new List(); + + public virtual ICollection UsersShockers { get; set; } = new List(); } diff --git a/DiscordBot/OpenShockDiscordDb/UsersFriendwhitelist.cs b/DiscordBot/OpenShockDiscordDb/UsersFriendwhitelist.cs index a3873a2..c74bc53 100644 --- a/DiscordBot/OpenShockDiscordDb/UsersFriendwhitelist.cs +++ b/DiscordBot/OpenShockDiscordDb/UsersFriendwhitelist.cs @@ -10,4 +10,6 @@ public partial class UsersFriendwhitelist public decimal WhitelistedFriend { get; set; } public DateTime CreatedOn { get; set; } + + public virtual User UserNavigation { get; set; } = null!; } diff --git a/DiscordBot/OpenShockDiscordDb/UsersShocker.cs b/DiscordBot/OpenShockDiscordDb/UsersShocker.cs new file mode 100644 index 0000000..639b30d --- /dev/null +++ b/DiscordBot/OpenShockDiscordDb/UsersShocker.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace OpenShock.DiscordBot.OpenShockDiscordDb; + +public partial class UsersShocker +{ + public decimal User { get; set; } + + public Guid ShockerId { get; set; } + + public DateTime CreatedAt { get; set; } + + public virtual User UserNavigation { get; set; } = null!; +}