reworked discord messages
This commit is contained in:
parent
38127b6c44
commit
62bacb5ad7
12 changed files with 318 additions and 78 deletions
|
@ -34,7 +34,7 @@ namespace DiscordBot.CommandHandlers
|
|||
if(await _handlerFunctions.IsRaidSignUpAllowed(component, parsedRaidId, ids[0]))
|
||||
{
|
||||
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
||||
await component.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, parsedRaidId, ids[0], false) , ephemeral: true);
|
||||
await component.RespondAsync("Please choose a role.", components: RoleSelectionMessage.buildMessage(roles, parsedRaidId, ids[0], false) , ephemeral: true);
|
||||
}
|
||||
break;
|
||||
case Constants.ComponentIds.MAYBE_BUTTON:
|
||||
|
@ -43,7 +43,7 @@ namespace DiscordBot.CommandHandlers
|
|||
if(await _handlerFunctions.IsRaidSignUpAllowed(component, parsedRaidId, ids[0]))
|
||||
{
|
||||
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
||||
await component.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, parsedRaidId, ids[0], true) , ephemeral: true);
|
||||
await component.RespondAsync("Please choose a role.", components: RoleSelectionMessage.buildMessage(roles, parsedRaidId, ids[0], true) , ephemeral: true);
|
||||
}
|
||||
break;
|
||||
case Constants.ComponentIds.SIGN_OFF_BUTTON:
|
||||
|
|
|
@ -22,13 +22,7 @@ namespace DiscordBot.CommandHandlers
|
|||
{
|
||||
if(! await _httpService.DoesUserExist(component.User.Id))
|
||||
{
|
||||
var mb = new ModalBuilder()
|
||||
.WithTitle("Create Account")
|
||||
.WithCustomId($"{Constants.ComponentIds.CREATE_ACCOUNT_MODAL}-{raidId}-{pressedButtonId}")
|
||||
.AddTextInput("Name", Constants.ComponentIds.NAME_TEXT_BOX, placeholder: component.User.Username, required: true, value: component.User.Username)
|
||||
.AddTextInput("Guild Wars 2 Account", Constants.ComponentIds.ACCOUNT_TEXT_BOX, placeholder: "Account.1234", required: true);
|
||||
|
||||
await component.RespondWithModalAsync(mb.Build());
|
||||
await component.RespondWithModalAsync(CreateAccountModal.buildMessage(raidId, pressedButtonId, component.User.Username));
|
||||
return false;
|
||||
}
|
||||
Tuple<bool, string> signUpAllowed = await _httpService.IsSignUpAllowed(raidId, component.User.Id);
|
||||
|
|
|
@ -41,24 +41,26 @@ namespace DiscordBot.CommandHandlers
|
|||
}
|
||||
|
||||
//sign up
|
||||
if(ids.Length > 2 && int.TryParse(ids[1], out int parsedRaidId) && await _handlerFunctions.IsRaidSignUpAllowed(modal, parsedRaidId, ids[2]))
|
||||
CreateAccountModal.Parameters createAccountParameters = CreateAccountModal.ParseId(modal.Data.CustomId);
|
||||
if(await _handlerFunctions.IsRaidSignUpAllowed(modal, createAccountParameters.RaidId, createAccountParameters.ButtonId))
|
||||
{
|
||||
List<ApiRole> roles = await _httpService.GetRoles(parsedRaidId, modal.User.Id);
|
||||
await modal.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, parsedRaidId, ids[2], false) , ephemeral: true);
|
||||
List<ApiRole> roles = await _httpService.GetRoles(createAccountParameters.RaidId, modal.User.Id);
|
||||
await modal.RespondAsync("Please choose a role.",
|
||||
components: RoleSelectionMessage.buildMessage(roles, createAccountParameters.RaidId, createAccountParameters.ButtonId, false),
|
||||
ephemeral: true);
|
||||
return;
|
||||
}
|
||||
await _handlerFunctions.Respond(modal);
|
||||
break;
|
||||
case Constants.ComponentIds.SIGN_UP_EXTERNAL_MODAL:
|
||||
string userName = components.First(x => x.CustomId == Constants.ComponentIds.NAME_TEXT_BOX).Value;
|
||||
int raidId = int.Parse(ids[1]);
|
||||
int roleId = int.Parse(ids[2]);
|
||||
ExternalUserNameModal.Parameters modalParameters = ExternalUserNameModal.ParseId(modal.Data.CustomId);
|
||||
ApiSignUp signUpExternal = new ApiSignUp()
|
||||
{
|
||||
raidId = raidId,
|
||||
raidId = modalParameters.RaidId,
|
||||
userName = userName,
|
||||
signedUpByUserId = modal.User.Id,
|
||||
roleId = roleId
|
||||
roleId = modalParameters.RoleId
|
||||
};
|
||||
await _httpService.SignUp(signUpExternal);
|
||||
await modal.RespondAsync($"signed up {userName}", ephemeral: true);
|
||||
|
|
|
@ -22,49 +22,63 @@ namespace DiscordBot.CommandHandlers
|
|||
public async Task Handler(SocketMessageComponent component)
|
||||
{
|
||||
string[] ids = component.Data.CustomId.Split('-');
|
||||
List<ApiRole> roles = new List<ApiRole>();
|
||||
int parsedRaidId = 0;
|
||||
if(ids.Length > 1)
|
||||
{
|
||||
int.TryParse(ids[1],out parsedRaidId);
|
||||
}
|
||||
|
||||
switch(ids[0])
|
||||
{
|
||||
case Constants.ComponentIds.SIGN_UP_DROP_DOWN:
|
||||
ulong userId = 0;
|
||||
if(ids.Length >= 4)
|
||||
RoleSelectionMessage.Parameters roleParameters = RoleSelectionMessage.ParseId(component.Data.CustomId);
|
||||
ulong userIdToSignUp = component.User.Id;;
|
||||
ulong signedUpByUserId = 0;
|
||||
if(roleParameters.UserIdToSignUp != 0)
|
||||
{
|
||||
ulong.TryParse(ids[3],out userId);
|
||||
userIdToSignUp = roleParameters.UserIdToSignUp;
|
||||
signedUpByUserId = component.User.Id;
|
||||
}
|
||||
await ManageSignUp(ids[2], parsedRaidId, component, userId);
|
||||
await component.RespondAsync("successfully signed up", ephemeral: true);
|
||||
await ManageSignUp(roleParameters.ButtonType, roleParameters.RaidId, component, userIdToSignUp, signedUpByUserId);
|
||||
break;
|
||||
case Constants.ComponentIds.SIGN_UP_EXTERNAL_DROP_DOWN:
|
||||
await component.RespondWithModalAsync(CreateUserNameModal(parsedRaidId, int.Parse(component.Data.Values.First())));
|
||||
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 component.RespondAsync("successfully signed up", ephemeral: true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ManageSignUp(string buttonType, int raidId, SocketMessageComponent component, ulong userIdToSignUp)
|
||||
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;
|
||||
|
||||
ApiSignUp signUp = new ApiSignUp()
|
||||
List<ApiGuildWars2Account> accounts = await _httpService.GetSignUpAccounts(userIdToSignUp, raidId);
|
||||
if(accounts.Count == 1)
|
||||
{
|
||||
raidId = raidId,
|
||||
roleId = parsedRoleId
|
||||
};
|
||||
|
||||
if(userIdToSignUp == 0)
|
||||
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)
|
||||
{
|
||||
signUp.userId = component.User.Id;
|
||||
await component.RespondAsync("Please choose an account.", components: AccountSelectionMessage.buildMessage(accounts, raidId, buttonType, parsedRoleId, userIdToSignUp, signedUpByUserId) , ephemeral: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
signUp.userId = userIdToSignUp;
|
||||
signUp.signedUpByUserId = component.User.Id;
|
||||
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)
|
||||
{
|
||||
|
@ -82,15 +96,5 @@ namespace DiscordBot.CommandHandlers
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private Modal CreateUserNameModal(int raidId, int roleId)
|
||||
{
|
||||
var mb = new ModalBuilder()
|
||||
.WithTitle("Create Account")
|
||||
.WithCustomId($"{Constants.ComponentIds.SIGN_UP_EXTERNAL_MODAL}-{raidId}-{roleId}")
|
||||
.AddTextInput("Name", Constants.ComponentIds.NAME_TEXT_BOX, placeholder: "Name", required: true);
|
||||
|
||||
return mb.Build();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,11 +26,19 @@ namespace DiscordBot.CommandHandlers
|
|||
|
||||
public async Task Handler(SocketSlashCommand command)
|
||||
{
|
||||
switch (command.Data.Name)
|
||||
Tuple<bool, string> commandExecutionAllowed = await _httpService.IsSlashCommandAllowed(command.User.Id, command.Data.Name);
|
||||
if(commandExecutionAllowed.Item1)
|
||||
{
|
||||
case Constants.SlashCommands.RAID:
|
||||
await HandleRaidCommands(command);
|
||||
break;
|
||||
switch (command.Data.Name)
|
||||
{
|
||||
case Constants.SlashCommands.RAID:
|
||||
await HandleRaidCommands(command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await command.RespondAsync(commandExecutionAllowed.Item2, ephemeral:true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +111,7 @@ namespace DiscordBot.CommandHandlers
|
|||
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);
|
||||
await command.RespondAsync("Please choose a role.", components: RoleSelectionMessage.buildMessage(roles, raidId, Constants.ComponentIds.SIGN_UP_BUTTON, false, user.Id) , ephemeral: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -129,23 +137,7 @@ namespace DiscordBot.CommandHandlers
|
|||
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}")
|
||||
.WithMinValues(1)
|
||||
.WithMaxValues(1);
|
||||
|
||||
foreach(ApiRole role in roles)
|
||||
{
|
||||
if(role.IsSignUpAllowed)
|
||||
signUpSelect.AddOption(role.Name, role.roleId.ToString(), role.Description);
|
||||
}
|
||||
|
||||
var builder = new ComponentBuilder()
|
||||
.WithSelectMenu(signUpSelect, 0);
|
||||
|
||||
await command.RespondAsync("Please choose a role.", components: builder.Build() , ephemeral: true);
|
||||
await command.RespondAsync("Please choose a role.", components: ExternalRoleSelectionMessage.buildMessage(roles, raidId) , ephemeral: true);
|
||||
}
|
||||
|
||||
private async Task SendMessages(string message, int raidId)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue