diff --git a/LightlessSyncServer/LightlessSyncAuthService/Controllers/UserController.cs b/LightlessSyncServer/LightlessSyncAuthService/Controllers/UserController.cs index df981a8..5d11e47 100644 --- a/LightlessSyncServer/LightlessSyncAuthService/Controllers/UserController.cs +++ b/LightlessSyncServer/LightlessSyncAuthService/Controllers/UserController.cs @@ -17,6 +17,24 @@ public class UserController : Controller LightlessDbContextFactory = lightlessDbContext; } + [Authorize(Policy = "Internal")] + [HttpPost(LightlessAuth.Ban_Uid)] + public async Task MarkForBanUid(string uid) + { + using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync(); + + Logger.LogInformation("Banning user with UID {UID}", uid); + + //Mark User as banned, and not marked for ban + var auth = await dbContext.Auth.FirstOrDefaultAsync(f => f.UserUID == uid); + if (auth != null) + { + auth.MarkForBan = true; + } + + await dbContext.SaveChangesAsync(); + } + [Authorize(Policy = "Internal")] [HttpPost(LightlessAuth.User_Unban_Uid)] public async Task UnBanUserByUid(string uid) diff --git a/LightlessSyncServer/LightlessSyncServices/Discord/MareModule.cs b/LightlessSyncServer/LightlessSyncServices/Discord/MareModule.cs index aaaf4bc..100efcc 100644 --- a/LightlessSyncServer/LightlessSyncServices/Discord/MareModule.cs +++ b/LightlessSyncServer/LightlessSyncServices/Discord/MareModule.cs @@ -224,6 +224,48 @@ public class LightlessModule : InteractionModuleBase await RespondAsync(embeds: new Embed[] { eb.Build() }, ephemeral: true).ConfigureAwait(false); } } + + [SlashCommand("markUidforBan", "ADMIN ONLY: ban a user by their uid")] + public async Task MarkUidForBan([Summary("uid", "uid to ban")] string uid) + { + _logger.LogInformation("SlashCommand:{userId}:{Method}:{params}", + Context.Interaction.User.Id, nameof(MarkUidForBan), + string.Join(",", new[] { $"{nameof(uid)}:{uid}" })); + try + { + using HttpClient c = new HttpClient(); + c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token); + await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue + (nameof(ServicesConfiguration.MainServerAddress)), "/user/ban"), new { uid }) + .ConfigureAwait(false); + var discordChannelForMessages = _lightlessServicesConfiguration.GetValueOrDefault(nameof(ServicesConfiguration.DiscordChannelForMessages), null); + if (discordChannelForMessages != null) + { + var discordChannel = await Context.Guild.GetChannelAsync(discordChannelForMessages.Value).ConfigureAwait(false) as IMessageChannel; + if (discordChannel != null) + { + var embedColor = Color.Blue; + + EmbedBuilder eb = new(); + eb.WithTitle("Ban Alert!"); + eb.WithColor(embedColor); + eb.WithDescription(uid + " has been marked for ban"); + + await discordChannel.SendMessageAsync(embed: eb.Build()).ConfigureAwait(false); + } + } + + await RespondAsync("Message sent", ephemeral: true).ConfigureAwait(false); + } + catch (Exception ex) + { + EmbedBuilder eb = new(); + eb.WithTitle("An error occured"); + eb.WithDescription("Please report this: " + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine); + await RespondAsync(embeds: new Embed[] { eb.Build() }, ephemeral: true).ConfigureAwait(false); + } + } + public async Task HandleUserAdd(string desiredUid, ulong discordUserId) { var embed = new EmbedBuilder();