added error message if signing up fails
This commit is contained in:
parent
766faf7b66
commit
2246624917
6 changed files with 79 additions and 40 deletions
|
@ -103,8 +103,14 @@ namespace DiscordBot.CommandHandlers
|
||||||
if(accounts.Count == 1)
|
if(accounts.Count == 1)
|
||||||
{
|
{
|
||||||
ApiGuildWars2Account account = accounts.First();
|
ApiGuildWars2Account account = accounts.First();
|
||||||
await SignUp(buttonType, raidId, roleId, userIdToSignUp, account.GuildWars2AccountId, signedUpByUserId);
|
if(await SignUp(buttonType, raidId, roleId, userIdToSignUp, account.GuildWars2AccountId, signedUpByUserId))
|
||||||
await UpdateOrRespond(component, "successfully signed up", null, roleMessageExists);
|
{
|
||||||
|
await UpdateOrRespond(component, "successfully signed up", null, roleMessageExists);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await UpdateOrRespond(component, "signing up failed", null, roleMessageExists);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(accounts.Count > 1)
|
else if(accounts.Count > 1)
|
||||||
{
|
{
|
||||||
|
@ -116,7 +122,7 @@ namespace DiscordBot.CommandHandlers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SignUp(string buttonType, int raidId, int roleId, ulong userIdToSignUp, int gw2AccountId, ulong signedUpByUserId)
|
public async Task<bool> SignUp(string buttonType, int raidId, int roleId, ulong userIdToSignUp, int gw2AccountId, ulong signedUpByUserId)
|
||||||
{
|
{
|
||||||
ApiSignUp signUp = new ApiSignUp()
|
ApiSignUp signUp = new ApiSignUp()
|
||||||
{
|
{
|
||||||
|
@ -130,17 +136,19 @@ namespace DiscordBot.CommandHandlers
|
||||||
switch(buttonType)
|
switch(buttonType)
|
||||||
{
|
{
|
||||||
case Constants.ComponentIds.SIGN_UP_BUTTON:
|
case Constants.ComponentIds.SIGN_UP_BUTTON:
|
||||||
await _httpService.SignUp(signUp);
|
return await _httpService.SignUp(signUp);
|
||||||
break;
|
break;
|
||||||
case Constants.ComponentIds.MAYBE_BUTTON:
|
case Constants.ComponentIds.MAYBE_BUTTON:
|
||||||
await _httpService.SignUpMaybe(signUp);
|
return await _httpService.SignUpMaybe(signUp);
|
||||||
break;
|
break;
|
||||||
case Constants.ComponentIds.BACKUP_BUTTON:
|
case Constants.ComponentIds.BACKUP_BUTTON:
|
||||||
await _httpService.SignUpBackup(signUp);
|
return await _httpService.SignUpBackup(signUp);
|
||||||
break;
|
break;
|
||||||
case Constants.ComponentIds.FLEX_BUTTON:
|
case Constants.ComponentIds.FLEX_BUTTON:
|
||||||
await _httpService.SignUpFlex(signUp);
|
return await _httpService.SignUpFlex(signUp);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,14 @@ namespace DiscordBot.CommandHandlers
|
||||||
signedUpByUserId = modal.User.Id,
|
signedUpByUserId = modal.User.Id,
|
||||||
roleId = modalParameters.RoleId
|
roleId = modalParameters.RoleId
|
||||||
};
|
};
|
||||||
await _httpService.SignUp(signUpExternal);
|
if(await _httpService.SignUp(signUpExternal))
|
||||||
await modal.RespondAsync($"signed up {userName}", ephemeral: true);
|
{
|
||||||
|
await modal.RespondAsync($"signed up {userName}", ephemeral: true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await modal.RespondAsync($"signing up failed", ephemeral: true);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,12 +36,22 @@ namespace DiscordBot.CommandHandlers
|
||||||
case Constants.ComponentIds.ACCOUNT_SELECT_DROP_DOWN:
|
case Constants.ComponentIds.ACCOUNT_SELECT_DROP_DOWN:
|
||||||
AccountSelectionMessage.Parameters accountParameters = AccountSelectionMessage.ParseId(component.Data.CustomId);
|
AccountSelectionMessage.Parameters accountParameters = AccountSelectionMessage.ParseId(component.Data.CustomId);
|
||||||
int accountId = int.Parse(component.Data.Values.First());
|
int accountId = int.Parse(component.Data.Values.First());
|
||||||
await _handlerFunctions.SignUp(accountParameters.ButtonType, accountParameters.RaidId, accountParameters.RoleId, accountParameters.UserIdToSignUp, accountId, accountParameters.SignedUpByUserId);
|
if(await _handlerFunctions.SignUp(accountParameters.ButtonType, accountParameters.RaidId, accountParameters.RoleId, accountParameters.UserIdToSignUp, accountId, accountParameters.SignedUpByUserId))
|
||||||
await component.UpdateAsync(x =>
|
|
||||||
{
|
{
|
||||||
x.Content = "successfully signed up";
|
await component.UpdateAsync(x =>
|
||||||
x.Components = null;
|
{
|
||||||
});
|
x.Content = "successfully signed up";
|
||||||
|
x.Components = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await component.UpdateAsync(x =>
|
||||||
|
{
|
||||||
|
x.Content = "signing up failed";
|
||||||
|
x.Components = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,24 +99,24 @@ namespace DiscordBot.Services
|
||||||
return new List<ApiRole>();
|
return new List<ApiRole>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SignUp(ApiSignUp signUp)
|
public async Task<bool> SignUp(ApiSignUp signUp)
|
||||||
{
|
{
|
||||||
await SendSignUp(signUp, "DiscordBot/SignUp");
|
return await SendSignUp(signUp, "DiscordBot/SignUp");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SignUpMaybe(ApiSignUp signUp)
|
public async Task<bool> SignUpMaybe(ApiSignUp signUp)
|
||||||
{
|
{
|
||||||
await SendSignUp(signUp, "DiscordBot/SignUpMaybe");
|
return await SendSignUp(signUp, "DiscordBot/SignUpMaybe");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SignUpBackup(ApiSignUp signUp)
|
public async Task<bool> SignUpBackup(ApiSignUp signUp)
|
||||||
{
|
{
|
||||||
await SendSignUp(signUp, "DiscordBot/SignUpBackup");
|
return await SendSignUp(signUp, "DiscordBot/SignUpBackup");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SignUpFlex(ApiSignUp signUp)
|
public async Task<bool> SignUpFlex(ApiSignUp signUp)
|
||||||
{
|
{
|
||||||
await SendSignUp(signUp, "DiscordBot/SignUpFlex");
|
return await SendSignUp(signUp, "DiscordBot/SignUpFlex");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SignOff(ApiSignUp signUp)
|
public async Task SignOff(ApiSignUp signUp)
|
||||||
|
@ -124,7 +124,7 @@ namespace DiscordBot.Services
|
||||||
await SendSignUp(signUp, "DiscordBot/SignOff");
|
await SendSignUp(signUp, "DiscordBot/SignOff");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SendSignUp(ApiSignUp signUp, string requestUri)
|
private async Task<bool> SendSignUp(ApiSignUp signUp, string requestUri)
|
||||||
{
|
{
|
||||||
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||||
|
|
||||||
|
@ -134,6 +134,14 @@ namespace DiscordBot.Services
|
||||||
Application.Json);
|
Application.Json);
|
||||||
|
|
||||||
var httpResponseMessage = await httpClient.PostAsync(requestUri, raidItemJson);
|
var httpResponseMessage = await httpClient.PostAsync(requestUri, raidItemJson);
|
||||||
|
if (httpResponseMessage.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
using var contentStream =
|
||||||
|
await httpResponseMessage.Content.ReadAsStreamAsync();
|
||||||
|
|
||||||
|
return await JsonSerializer.DeserializeAsync<bool>(contentStream, _serializerOptions);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Tuple<bool, string>> CreateAccount(ApiRaid.Role.User user)
|
public async Task<Tuple<bool, string>> CreateAccount(ApiRaid.Role.User user)
|
||||||
|
|
|
@ -87,67 +87,67 @@ namespace Lieb.Controllers
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("[action]")]
|
[Route("[action]")]
|
||||||
public async Task SignUp(ApiSignUp signUp)
|
public async Task<bool> SignUp(ApiSignUp signUp)
|
||||||
{
|
{
|
||||||
if(signUp.userId != 0)
|
if(signUp.userId != 0)
|
||||||
{
|
{
|
||||||
int accountId = _userService.GetSignUpAccount(signUp.userId, signUp.raidId, signUp.gw2AccountId);
|
int accountId = _userService.GetSignUpAccount(signUp.userId, signUp.raidId, signUp.gw2AccountId);
|
||||||
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.SignedUp, signUp.signedUpByUserId);
|
return await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.SignedUp, signUp.signedUpByUserId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.SignedUp, signUp.signedUpByUserId);
|
return await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.SignedUp, signUp.signedUpByUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("[action]")]
|
[Route("[action]")]
|
||||||
public async Task SignUpMaybe(ApiSignUp signUp)
|
public async Task<bool> SignUpMaybe(ApiSignUp signUp)
|
||||||
{
|
{
|
||||||
if(signUp.userId != 0)
|
if(signUp.userId != 0)
|
||||||
{
|
{
|
||||||
int accountId = _userService.GetSignUpAccount(signUp.userId, signUp.raidId, signUp.gw2AccountId);
|
int accountId = _userService.GetSignUpAccount(signUp.userId, signUp.raidId, signUp.gw2AccountId);
|
||||||
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.Maybe, signUp.signedUpByUserId);
|
return await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.Maybe, signUp.signedUpByUserId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.Maybe, signUp.signedUpByUserId);
|
return await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.Maybe, signUp.signedUpByUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("[action]")]
|
[Route("[action]")]
|
||||||
public async Task SignUpBackup(ApiSignUp signUp)
|
public async Task<bool> SignUpBackup(ApiSignUp signUp)
|
||||||
{
|
{
|
||||||
if(signUp.userId != 0)
|
if(signUp.userId != 0)
|
||||||
{
|
{
|
||||||
int accountId = _userService.GetSignUpAccount(signUp.userId, signUp.raidId, signUp.gw2AccountId);
|
int accountId = _userService.GetSignUpAccount(signUp.userId, signUp.raidId, signUp.gw2AccountId);
|
||||||
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.Backup, signUp.signedUpByUserId);
|
return await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.Backup, signUp.signedUpByUserId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.Backup, signUp.signedUpByUserId);
|
return await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.Backup, signUp.signedUpByUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("[action]")]
|
[Route("[action]")]
|
||||||
public async Task SignUpFlex(ApiSignUp signUp)
|
public async Task<bool> SignUpFlex(ApiSignUp signUp)
|
||||||
{
|
{
|
||||||
if(signUp.userId != 0)
|
if(signUp.userId != 0)
|
||||||
{
|
{
|
||||||
int accountId = _userService.GetSignUpAccount(signUp.userId, signUp.raidId, signUp.gw2AccountId);
|
int accountId = _userService.GetSignUpAccount(signUp.userId, signUp.raidId, signUp.gw2AccountId);
|
||||||
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.Flex, signUp.signedUpByUserId);
|
return await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.Flex, signUp.signedUpByUserId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.Flex, signUp.signedUpByUserId);
|
return await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.Flex, signUp.signedUpByUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("[action]")]
|
[Route("[action]")]
|
||||||
public async Task SignOff(ApiSignUp signUp)
|
public async Task<bool> SignOff(ApiSignUp signUp)
|
||||||
{
|
{
|
||||||
if(signUp.userId != 0)
|
if(signUp.userId != 0)
|
||||||
{
|
{
|
||||||
|
@ -157,6 +157,7 @@ namespace Lieb.Controllers
|
||||||
{
|
{
|
||||||
await _raidService.SignOffExternalUser(signUp.raidId, signUp.userName, signUp.signedUpByUserId);
|
await _raidService.SignOffExternalUser(signUp.raidId, signUp.userName, signUp.signedUpByUserId);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|
|
@ -112,11 +112,11 @@ namespace Lieb.Data
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SignUp(int raidId, ulong liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType, ulong signedUpByUserId = 0)
|
public async Task<bool> SignUp(int raidId, ulong liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType, ulong signedUpByUserId = 0)
|
||||||
{
|
{
|
||||||
if (!IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true))
|
if (!IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true))
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
@ -134,14 +134,19 @@ namespace Lieb.Data
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
await LogSignUp(signUp, userName, signedUpByUserId);
|
await LogSignUp(signUp, userName, signedUpByUserId);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
await _discordService.PostRaidMessage(raidId);
|
await _discordService.PostRaidMessage(raidId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SignUpExternalUser(int raidId, string userName, int plannedRoleId, SignUpType signUpType, ulong signedUpByUserId)
|
public async Task<bool> SignUpExternalUser(int raidId, string userName, int plannedRoleId, SignUpType signUpType, ulong signedUpByUserId)
|
||||||
{
|
{
|
||||||
if (!IsRoleSignUpAllowed(raidId, ulong.MaxValue, plannedRoleId, signUpType, true))
|
if (!IsRoleSignUpAllowed(raidId, ulong.MaxValue, plannedRoleId, signUpType, true))
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
@ -151,6 +156,7 @@ namespace Lieb.Data
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
await LogSignUp(signUp, userName, signedUpByUserId);
|
await LogSignUp(signUp, userName, signedUpByUserId);
|
||||||
await _discordService.PostRaidMessage(raidId);
|
await _discordService.PostRaidMessage(raidId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SignOff(int raidId, ulong liebUserId, ulong signedOffByUserId = 0)
|
public async Task SignOff(int raidId, ulong liebUserId, ulong signedOffByUserId = 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue