flex sign up in the bot is now also only possible if the user is already signed up
This commit is contained in:
parent
19595e52bf
commit
766faf7b66
3 changed files with 37 additions and 3 deletions
|
@ -25,14 +25,24 @@ namespace DiscordBot.CommandHandlers
|
||||||
switch(ids[0])
|
switch(ids[0])
|
||||||
{
|
{
|
||||||
case Constants.ComponentIds.SIGN_UP_BUTTON:
|
case Constants.ComponentIds.SIGN_UP_BUTTON:
|
||||||
|
case Constants.ComponentIds.MAYBE_BUTTON:
|
||||||
RaidMessage.ButtonParameters signUpParameters = RaidMessage.ParseButtonId(component.Data.CustomId);
|
RaidMessage.ButtonParameters signUpParameters = RaidMessage.ParseButtonId(component.Data.CustomId);
|
||||||
await _handlerFunctions.SelectRole(component, signUpParameters.RaidId, signUpParameters.ButtonType, false, component.User.Id, 0);
|
await _handlerFunctions.SelectRole(component, signUpParameters.RaidId, signUpParameters.ButtonType, false, component.User.Id, 0);
|
||||||
break;
|
break;
|
||||||
case Constants.ComponentIds.MAYBE_BUTTON:
|
|
||||||
case Constants.ComponentIds.BACKUP_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:
|
case Constants.ComponentIds.FLEX_BUTTON:
|
||||||
RaidMessage.ButtonParameters maybeParameters = RaidMessage.ParseButtonId(component.Data.CustomId);
|
RaidMessage.ButtonParameters flexParameters = RaidMessage.ParseButtonId(component.Data.CustomId);
|
||||||
await _handlerFunctions.SelectRole(component, maybeParameters.RaidId, maybeParameters.ButtonType, true, component.User.Id, 0);
|
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;
|
break;
|
||||||
case Constants.ComponentIds.SIGN_OFF_BUTTON:
|
case Constants.ComponentIds.SIGN_OFF_BUTTON:
|
||||||
RaidMessage.ButtonParameters signOffParameters = RaidMessage.ParseButtonId(component.Data.CustomId);
|
RaidMessage.ButtonParameters signOffParameters = RaidMessage.ParseButtonId(component.Data.CustomId);
|
||||||
|
|
|
@ -67,6 +67,22 @@ namespace DiscordBot.Services
|
||||||
return new Tuple<bool, string>(true, string.Empty);
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> 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<bool>(contentStream, _serializerOptions);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<List<ApiRole>> GetRoles(int raidId, ulong userId)
|
public async Task<List<ApiRole>> GetRoles(int raidId, ulong userId)
|
||||||
{
|
{
|
||||||
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||||
|
|
|
@ -47,6 +47,14 @@ namespace Lieb.Controllers
|
||||||
return Ok();
|
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]
|
[HttpGet]
|
||||||
[Route("[action]/{raidId}")]
|
[Route("[action]/{raidId}")]
|
||||||
public ActionResult IsExternalSignUpAllowed(int raidId)
|
public ActionResult IsExternalSignUpAllowed(int raidId)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue