reworked sign up workflow
This commit is contained in:
parent
2a9cd89783
commit
19595e52bf
4 changed files with 51 additions and 20 deletions
|
@ -42,7 +42,7 @@ namespace DiscordBot.CommandHandlers
|
|||
userId = component.User.Id
|
||||
};
|
||||
await _httpService.SignOff(signOff);
|
||||
await _handlerFunctions.Respond(component);
|
||||
await component.RespondAsync("Signed Off", ephemeral: true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,14 +79,15 @@ namespace DiscordBot.CommandHandlers
|
|||
if(await IsRaidSignUpAllowed(component, raidId, buttonType))
|
||||
{
|
||||
List<ApiRole> roles = new List<ApiRole>();
|
||||
roles = await _httpService.GetRoles(raidId, userIdToSignUp);
|
||||
roles = await _httpService.GetRoles(raidId, userIdToSignUp);
|
||||
ApiRaid raid = await _httpService.GetRaid(raidId);
|
||||
if(roles.Count > 1)
|
||||
{
|
||||
await component.RespondAsync("Please choose a role.", components: RoleSelectionMessage.buildMessage(roles, raidId, buttonType, allRoles, userIdToSignUp, signedUpByUserId) , ephemeral: true);
|
||||
await component.RespondAsync($"{raid.Title}: Please choose a role.", components: RoleSelectionMessage.buildMessage(roles, raidId, buttonType, allRoles, userIdToSignUp, signedUpByUserId) , ephemeral: true);
|
||||
}
|
||||
else if(roles.Count == 1)
|
||||
{
|
||||
await SelectAccount(buttonType, raidId, component, roles.First().roleId, userIdToSignUp, signedUpByUserId);
|
||||
await SelectAccount(buttonType, raidId, component, roles.First().roleId, userIdToSignUp, signedUpByUserId, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -95,7 +96,7 @@ namespace DiscordBot.CommandHandlers
|
|||
}
|
||||
}
|
||||
|
||||
public async Task SelectAccount(string buttonType, int raidId, SocketInteraction component, int roleId, ulong userIdToSignUp, ulong signedUpByUserId)
|
||||
public async Task SelectAccount(string buttonType, int raidId, SocketInteraction component, int roleId, ulong userIdToSignUp, ulong signedUpByUserId, bool roleMessageExists = true)
|
||||
{
|
||||
|
||||
List<ApiGuildWars2Account> accounts = await _httpService.GetSignUpAccounts(userIdToSignUp, raidId);
|
||||
|
@ -103,15 +104,15 @@ namespace DiscordBot.CommandHandlers
|
|||
{
|
||||
ApiGuildWars2Account account = accounts.First();
|
||||
await SignUp(buttonType, raidId, roleId, userIdToSignUp, account.GuildWars2AccountId, signedUpByUserId);
|
||||
await component.RespondAsync("successfully signed up", ephemeral: true);
|
||||
await UpdateOrRespond(component, "successfully signed up", null, roleMessageExists);
|
||||
}
|
||||
else if(accounts.Count > 1)
|
||||
{
|
||||
await component.RespondAsync("Please choose an account.", components: AccountSelectionMessage.buildMessage(accounts, raidId, buttonType, roleId, userIdToSignUp, signedUpByUserId) , ephemeral: true);
|
||||
await UpdateOrRespond(component, "Please choose an account.", AccountSelectionMessage.buildMessage(accounts, raidId, buttonType, roleId, userIdToSignUp, signedUpByUserId), roleMessageExists);
|
||||
}
|
||||
else
|
||||
{
|
||||
await component.RespondAsync("no suitable Guild Wars 2 account found.", ephemeral: true);
|
||||
await UpdateOrRespond(component, "no suitable Guild Wars 2 account found.", null, roleMessageExists);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,17 +143,21 @@ namespace DiscordBot.CommandHandlers
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//to avoid error messages because of no response...
|
||||
public async Task Respond(SocketInteraction component)
|
||||
{
|
||||
try
|
||||
{
|
||||
await component.RespondAsync();
|
||||
}
|
||||
catch(Discord.Net.HttpException e)
|
||||
{
|
||||
|
||||
public async Task UpdateOrRespond(SocketInteraction component, string messageText, MessageComponent messageComponent, bool editMessage)
|
||||
{
|
||||
if(editMessage && component is SocketMessageComponent)
|
||||
{
|
||||
SocketMessageComponent socketComponent = component as SocketMessageComponent;
|
||||
await socketComponent.UpdateAsync(x =>
|
||||
{
|
||||
x.Content = messageText;
|
||||
x.Components = messageComponent;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await component.RespondAsync(messageText, components: messageComponent , ephemeral: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,11 @@ namespace DiscordBot.CommandHandlers
|
|||
AccountSelectionMessage.Parameters accountParameters = AccountSelectionMessage.ParseId(component.Data.CustomId);
|
||||
int accountId = int.Parse(component.Data.Values.First());
|
||||
await _handlerFunctions.SignUp(accountParameters.ButtonType, accountParameters.RaidId, accountParameters.RoleId, accountParameters.UserIdToSignUp, accountId, accountParameters.SignedUpByUserId);
|
||||
await component.RespondAsync("successfully signed up", ephemeral: true);
|
||||
await component.UpdateAsync(x =>
|
||||
{
|
||||
x.Content = "successfully signed up";
|
||||
x.Components = null;
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace DiscordBot.Messages
|
|||
public static MessageComponent buildMessage(List<ApiRole> roles, int raidId, string buttonType, bool allRoles, ulong userIdToSignUp, ulong signedUpByUserId)
|
||||
{
|
||||
var signUpSelect = new SelectMenuBuilder()
|
||||
.WithPlaceholder($"Select a role")
|
||||
.WithPlaceholder($"Select a role - {GetButtonName(buttonType)}")
|
||||
.WithCustomId($"{Constants.ComponentIds.ROLE_SELECT_DROP_DOWN}-{raidId}-{buttonType}-{userIdToSignUp}-{signedUpByUserId}")
|
||||
.WithMinValues(1)
|
||||
.WithMaxValues(1);
|
||||
|
@ -25,6 +25,28 @@ namespace DiscordBot.Messages
|
|||
return builder.Build();
|
||||
}
|
||||
|
||||
private static string GetButtonName(string buttonType)
|
||||
{
|
||||
switch(buttonType)
|
||||
{
|
||||
case Constants.ComponentIds.SIGN_UP_BUTTON:
|
||||
return "Sign Up";
|
||||
break;
|
||||
case Constants.ComponentIds.MAYBE_BUTTON:
|
||||
return "Maybe";
|
||||
break;
|
||||
case Constants.ComponentIds.BACKUP_BUTTON:
|
||||
return "Backup";
|
||||
break;
|
||||
case Constants.ComponentIds.FLEX_BUTTON:
|
||||
return "Flex";
|
||||
break;
|
||||
default:
|
||||
return string.Empty;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Parameters ParseId(string customId)
|
||||
{
|
||||
Parameters parameters = new Parameters();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue