diff --git a/DiscordBot/CommandHandlers/ButtonHandler.cs b/DiscordBot/CommandHandlers/ButtonHandler.cs index 206cf01..c91763a 100644 --- a/DiscordBot/CommandHandlers/ButtonHandler.cs +++ b/DiscordBot/CommandHandlers/ButtonHandler.cs @@ -25,14 +25,24 @@ namespace DiscordBot.CommandHandlers switch(ids[0]) { case Constants.ComponentIds.SIGN_UP_BUTTON: + case Constants.ComponentIds.MAYBE_BUTTON: RaidMessage.ButtonParameters signUpParameters = RaidMessage.ParseButtonId(component.Data.CustomId); await _handlerFunctions.SelectRole(component, signUpParameters.RaidId, signUpParameters.ButtonType, false, component.User.Id, 0); break; - case Constants.ComponentIds.MAYBE_BUTTON: case Constants.ComponentIds.BACKUP_BUTTON: + RaidMessage.ButtonParameters backupParameters = RaidMessage.ParseButtonId(component.Data.CustomId); + await _handlerFunctions.SelectRole(component, backupParameters.RaidId, backupParameters.ButtonType, true, component.User.Id, 0); + break; case Constants.ComponentIds.FLEX_BUTTON: - RaidMessage.ButtonParameters maybeParameters = RaidMessage.ParseButtonId(component.Data.CustomId); - await _handlerFunctions.SelectRole(component, maybeParameters.RaidId, maybeParameters.ButtonType, true, component.User.Id, 0); + RaidMessage.ButtonParameters flexParameters = RaidMessage.ParseButtonId(component.Data.CustomId); + if(await _httpService.IsUserSignedUp(flexParameters.RaidId, component.User.Id)) + { + await _handlerFunctions.SelectRole(component, flexParameters.RaidId, flexParameters.ButtonType, true, component.User.Id, 0); + } + else + { + await component.RespondAsync("Flex sign up is only allowed if you are already signed up.", ephemeral: true); + } break; case Constants.ComponentIds.SIGN_OFF_BUTTON: RaidMessage.ButtonParameters signOffParameters = RaidMessage.ParseButtonId(component.Data.CustomId); diff --git a/DiscordBot/Services/HttpService.cs b/DiscordBot/Services/HttpService.cs index a8e5c65..597ed49 100644 --- a/DiscordBot/Services/HttpService.cs +++ b/DiscordBot/Services/HttpService.cs @@ -67,6 +67,22 @@ namespace DiscordBot.Services return new Tuple(true, string.Empty); } + public async Task IsUserSignedUp(int raidId, ulong userId) + { + var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME); + + var httpResponseMessage = await httpClient.GetAsync($"DiscordBot/IsUserSignedUp/{raidId}/{userId}"); + + if (httpResponseMessage.IsSuccessStatusCode) + { + using var contentStream = + await httpResponseMessage.Content.ReadAsStreamAsync(); + + return await JsonSerializer.DeserializeAsync(contentStream, _serializerOptions); + } + return false; + } + public async Task> GetRoles(int raidId, ulong userId) { var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME); diff --git a/Lieb/Controllers/DiscordBotController.cs b/Lieb/Controllers/DiscordBotController.cs index c7ebb8c..3a8e608 100644 --- a/Lieb/Controllers/DiscordBotController.cs +++ b/Lieb/Controllers/DiscordBotController.cs @@ -47,6 +47,14 @@ namespace Lieb.Controllers return Ok(); } + [HttpGet] + [Route("[action]/{raidId}/{userId}")] + public bool IsUserSignedUp(int raidId, ulong userId) + { + Raid raid = _raidService.GetRaid(raidId); + return raid.SignUps.Where(s => s.LiebUserId == userId && s.SignUpType != SignUpType.Flex && s.SignUpType != SignUpType.SignedOff).Any(); + } + [HttpGet] [Route("[action]/{raidId}")] public ActionResult IsExternalSignUpAllowed(int raidId)