reworkes sign up messages
This commit is contained in:
parent
57d8df1463
commit
03624a5859
9 changed files with 136 additions and 126 deletions
|
@ -24,77 +24,22 @@ namespace DiscordBot.CommandHandlers
|
|||
string[] ids = component.Data.CustomId.Split('-');
|
||||
switch(ids[0])
|
||||
{
|
||||
case Constants.ComponentIds.SIGN_UP_DROP_DOWN:
|
||||
case Constants.ComponentIds.ROLE_SELECT_DROP_DOWN:
|
||||
RoleSelectionMessage.Parameters roleParameters = RoleSelectionMessage.ParseId(component.Data.CustomId);
|
||||
ulong userIdToSignUp = component.User.Id;;
|
||||
ulong signedUpByUserId = 0;
|
||||
if(roleParameters.UserIdToSignUp != 0)
|
||||
{
|
||||
userIdToSignUp = roleParameters.UserIdToSignUp;
|
||||
signedUpByUserId = component.User.Id;
|
||||
}
|
||||
await ManageSignUp(roleParameters.ButtonType, roleParameters.RaidId, component, userIdToSignUp, signedUpByUserId);
|
||||
int parsedRoleId = int.Parse(component.Data.Values.First());
|
||||
await _handlerFunctions.SelectAccount(roleParameters.ButtonType, roleParameters.RaidId, component, parsedRoleId, roleParameters.UserIdToSignUp, roleParameters.SignedUpByUserId);
|
||||
break;
|
||||
case Constants.ComponentIds.SIGN_UP_EXTERNAL_DROP_DOWN:
|
||||
case Constants.ComponentIds.ROLE_SELECT_EXTERNAL_DROP_DOWN:
|
||||
ExternalRoleSelectionMessage.Parameters externalRoleParameters = ExternalRoleSelectionMessage.ParseId(component.Data.CustomId);
|
||||
await component.RespondWithModalAsync(ExternalUserNameModal.buildMessage(externalRoleParameters.RaidId, int.Parse(component.Data.Values.First())));
|
||||
break;
|
||||
case Constants.ComponentIds.ACCOUNT_SELECT_DROP_DOWN:
|
||||
AccountSelectionMessage.Parameters accountParameters = AccountSelectionMessage.ParseId(component.Data.CustomId);
|
||||
int accountId = int.Parse(component.Data.Values.First());
|
||||
await SignUp(accountParameters.ButtonType, accountParameters.RaidId, accountParameters.RoleId, accountParameters.UserIdToSignUp, accountId, accountParameters.SignedUpByUserId);
|
||||
await _handlerFunctions.SignUp(accountParameters.ButtonType, accountParameters.RaidId, accountParameters.RoleId, accountParameters.UserIdToSignUp, accountId, accountParameters.SignedUpByUserId);
|
||||
await component.RespondAsync("successfully signed up", ephemeral: true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ManageSignUp(string buttonType, int raidId, SocketMessageComponent component, ulong userIdToSignUp, ulong signedUpByUserId = 0)
|
||||
{
|
||||
if(! int.TryParse(component.Data.Values.First(), out int parsedRoleId)) return;
|
||||
|
||||
List<ApiGuildWars2Account> accounts = await _httpService.GetSignUpAccounts(userIdToSignUp, raidId);
|
||||
if(accounts.Count == 1)
|
||||
{
|
||||
ApiGuildWars2Account account = accounts.First();
|
||||
await SignUp(buttonType, raidId, parsedRoleId, userIdToSignUp, account.GuildWars2AccountId, signedUpByUserId);
|
||||
await component.RespondAsync("successfully signed up", ephemeral: true);
|
||||
}
|
||||
else if(accounts.Count > 1)
|
||||
{
|
||||
await component.RespondAsync("Please choose an account.", components: AccountSelectionMessage.buildMessage(accounts, raidId, buttonType, parsedRoleId, userIdToSignUp, signedUpByUserId) , ephemeral: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
await component.RespondAsync("no suitable Guild Wars 2 account found.", ephemeral: true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SignUp(string buttonType, int raidId, int roleId, ulong userIdToSignUp, int gw2AccountId, ulong signedUpByUserId = 0)
|
||||
{
|
||||
ApiSignUp signUp = new ApiSignUp()
|
||||
{
|
||||
raidId = raidId,
|
||||
roleId = roleId,
|
||||
gw2AccountId = gw2AccountId,
|
||||
userId = userIdToSignUp,
|
||||
signedUpByUserId = signedUpByUserId
|
||||
};
|
||||
|
||||
switch(buttonType)
|
||||
{
|
||||
case Constants.ComponentIds.SIGN_UP_BUTTON:
|
||||
await _httpService.SignUp(signUp);
|
||||
break;
|
||||
case Constants.ComponentIds.MAYBE_BUTTON:
|
||||
await _httpService.SignUpMaybe(signUp);
|
||||
break;
|
||||
case Constants.ComponentIds.BACKUP_BUTTON:
|
||||
await _httpService.SignUpBackup(signUp);
|
||||
break;
|
||||
case Constants.ComponentIds.FLEX_BUTTON:
|
||||
await _httpService.SignUpFlex(signUp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue