fixed Add external user command
This commit is contained in:
parent
a504925752
commit
f40903851e
9 changed files with 122 additions and 39 deletions
|
@ -65,6 +65,7 @@ namespace DiscordBot.CommandHandlers
|
|||
roleId = roleId
|
||||
};
|
||||
await _httpService.SignUp(signUpExternal);
|
||||
await modal.RespondAsync($"signed up {userName}", ephemeral: true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,6 +97,12 @@ namespace DiscordBot.CommandHandlers
|
|||
List<ApiRole> roles = await _httpService.GetRoles(raidId, user.Id);
|
||||
if(await _httpService.DoesUserExist(user.Id))
|
||||
{
|
||||
Tuple<bool, string> signUpAllowed = await _httpService.IsSignUpAllowed(raidId, user.Id, true);
|
||||
if(!signUpAllowed.Item1)
|
||||
{
|
||||
await command.RespondAsync(signUpAllowed.Item2, ephemeral: true);
|
||||
return;
|
||||
}
|
||||
await command.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, raidId, Constants.ComponentIds.SIGN_UP_BUTTON, false, user.Id) , ephemeral: true);
|
||||
}
|
||||
else
|
||||
|
@ -117,6 +123,13 @@ namespace DiscordBot.CommandHandlers
|
|||
|
||||
private async Task SignUpExternalUser(SocketSlashCommand command, int raidId, List<ApiRole> roles)
|
||||
{
|
||||
Tuple<bool, string> signUpAllowed = await _httpService.IsExternalSignUpAllowed(raidId);
|
||||
if(!signUpAllowed.Item1)
|
||||
{
|
||||
await command.RespondAsync(signUpAllowed.Item2, ephemeral: true);
|
||||
return;
|
||||
}
|
||||
|
||||
var signUpSelect = new SelectMenuBuilder()
|
||||
.WithPlaceholder("Select an option")
|
||||
.WithCustomId($"{Constants.ComponentIds.SIGN_UP_EXTERNAL_DROP_DOWN}-{raidId}")
|
||||
|
|
|
@ -37,11 +37,26 @@ namespace DiscordBot.Services
|
|||
return false;
|
||||
}
|
||||
|
||||
public async Task<Tuple<bool, string>> IsSignUpAllowed(int raidId, ulong userId)
|
||||
public async Task<Tuple<bool, string>> IsSignUpAllowed(int raidId, ulong userId, bool ignoreRole = false)
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||
|
||||
var httpResponseMessage = await httpClient.GetAsync($"DiscordBot/IsSignUpAllowed/{raidId}/{userId}");
|
||||
var httpResponseMessage = await httpClient.GetAsync($"DiscordBot/IsSignUpAllowed/{raidId}/{userId}/{ignoreRole}");
|
||||
|
||||
if (!httpResponseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
ProblemDetails problemDetails = await httpResponseMessage.Content.ReadFromJsonAsync<ProblemDetails>(_serializerOptions) ?? new ProblemDetails();
|
||||
string errorMessage = string.IsNullOrEmpty(problemDetails.Detail) ? string.Empty : problemDetails.Detail;
|
||||
return new Tuple<bool, string>(false, errorMessage);
|
||||
}
|
||||
return new Tuple<bool, string>(true, string.Empty);
|
||||
}
|
||||
|
||||
public async Task<Tuple<bool, string>> IsExternalSignUpAllowed(int raidId)
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||
|
||||
var httpResponseMessage = await httpClient.GetAsync($"DiscordBot/IsExternalSignUpAllowed/{raidId}");
|
||||
|
||||
if (!httpResponseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue