Skip to content

Commit

Permalink
Moar progress
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHeart committed Jun 17, 2024
1 parent dd36c1e commit 96a1a51
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 3 deletions.
19 changes: 16 additions & 3 deletions DiscordBot/Commands/ControlCommands.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
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;

[CommandContextType(InteractionContextType.Guild, InteractionContextType.BotDm, InteractionContextType.PrivateChannel)]
[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);


}
}
40 changes: 40 additions & 0 deletions DiscordBot/Commands/SetupCommands.cs
Original file line number Diff line number Diff line change
@@ -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<SetupCommand> _logger;

/// <summary>
/// Default constructor for the SetupCommand
/// </summary>
/// <param name="db"></param>
/// <param name="logger"></param>
public SetupCommands(OpenShockDiscordContext db, ILogger<SetupCommand> logger)
{
_db = db;
_logger = logger;
}

[SlashCommand("shocker", "Configure or refresh your shocker settings")]
public async Task ShockerConfig()

Check warning on line 28 in DiscordBot/Commands/SetupCommands.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 28 in DiscordBot/Commands/SetupCommands.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// var openShockClient = new OpenShockApiClient(new ApiClientOptions()
// {
// Server =
// })
//
// _db.UsersShockers.Add(new UsersShocker()
// {
// User =
// });
}
}
37 changes: 37 additions & 0 deletions DiscordBot/Commands/WhitelistCommands.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
25 changes: 25 additions & 0 deletions DiscordBot/OpenShockDiscordDb/OpenShockDiscordContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public OpenShockDiscordContext(DbContextOptions<OpenShockDiscordContext> options
public virtual DbSet<User> Users { get; set; }

public virtual DbSet<UsersFriendwhitelist> UsersFriendwhitelists { get; set; }

public virtual DbSet<UsersShocker> UsersShockers { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -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<UsersShocker>(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);
Expand Down
4 changes: 4 additions & 0 deletions DiscordBot/OpenShockDiscordDb/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public partial class User
public string ApiKey { get; set; } = null!;

public virtual ICollection<GuildActiveShocker> GuildActiveShockers { get; set; } = new List<GuildActiveShocker>();

public virtual ICollection<UsersFriendwhitelist> UsersFriendwhitelists { get; set; } = new List<UsersFriendwhitelist>();

public virtual ICollection<UsersShocker> UsersShockers { get; set; } = new List<UsersShocker>();
}
2 changes: 2 additions & 0 deletions DiscordBot/OpenShockDiscordDb/UsersFriendwhitelist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
}
15 changes: 15 additions & 0 deletions DiscordBot/OpenShockDiscordDb/UsersShocker.cs
Original file line number Diff line number Diff line change
@@ -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!;
}

0 comments on commit 96a1a51

Please sign in to comment.