forked from Sarah/Lieb-Website
reworkes sign up messages
This commit is contained in:
parent
57d8df1463
commit
03624a5859
9 changed files with 136 additions and 126 deletions
|
@ -22,34 +22,23 @@ 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_BUTTON:
|
||||
if(await _handlerFunctions.IsRaidSignUpAllowed(component, parsedRaidId, ids[0]))
|
||||
{
|
||||
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
||||
await component.RespondAsync("Please choose a role.", components: RoleSelectionMessage.buildMessage(roles, parsedRaidId, ids[0], false) , ephemeral: true);
|
||||
}
|
||||
break;
|
||||
RaidMessage.ButtonParameters signUpParameters = RaidMessage.ParseButtonId(component.Data.CustomId);
|
||||
await _handlerFunctions.SelectRole(component, signUpParameters.RaidId, signUpParameters.ButtonType, false, component.User.Id, 0);
|
||||
break;
|
||||
case Constants.ComponentIds.MAYBE_BUTTON:
|
||||
case Constants.ComponentIds.BACKUP_BUTTON:
|
||||
case Constants.ComponentIds.FLEX_BUTTON:
|
||||
if(await _handlerFunctions.IsRaidSignUpAllowed(component, parsedRaidId, ids[0]))
|
||||
{
|
||||
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
||||
await component.RespondAsync("Please choose a role.", components: RoleSelectionMessage.buildMessage(roles, parsedRaidId, ids[0], true) , ephemeral: true);
|
||||
}
|
||||
break;
|
||||
RaidMessage.ButtonParameters maybeParameters = RaidMessage.ParseButtonId(component.Data.CustomId);
|
||||
await _handlerFunctions.SelectRole(component, maybeParameters.RaidId, maybeParameters.ButtonType, true, component.User.Id, 0);
|
||||
break;
|
||||
case Constants.ComponentIds.SIGN_OFF_BUTTON:
|
||||
RaidMessage.ButtonParameters signOffParameters = RaidMessage.ParseButtonId(component.Data.CustomId);
|
||||
ApiSignUp signOff = new ApiSignUp()
|
||||
{
|
||||
raidId = parsedRaidId,
|
||||
raidId = signOffParameters.RaidId,
|
||||
userId = component.User.Id
|
||||
};
|
||||
await _httpService.SignOff(signOff);
|
||||
|
@ -57,6 +46,5 @@ namespace DiscordBot.CommandHandlers
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -69,6 +69,75 @@ namespace DiscordBot.CommandHandlers
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SelectRole(SocketInteraction component, int raidId, string buttonType, bool allRoles, ulong userIdToSignUp, ulong signedUpByUserId)
|
||||
{
|
||||
if(await IsRaidSignUpAllowed(component, raidId, buttonType))
|
||||
{
|
||||
List<ApiRole> roles = new List<ApiRole>();
|
||||
roles = await _httpService.GetRoles(raidId, userIdToSignUp);
|
||||
if(roles.Count > 1)
|
||||
{
|
||||
await component.RespondAsync("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);
|
||||
}
|
||||
else
|
||||
{
|
||||
await component.RespondAsync("no role found.", ephemeral: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SelectAccount(string buttonType, int raidId, SocketInteraction component, int roleId, ulong userIdToSignUp, ulong signedUpByUserId)
|
||||
{
|
||||
|
||||
List<ApiGuildWars2Account> accounts = await _httpService.GetSignUpAccounts(userIdToSignUp, raidId);
|
||||
if(accounts.Count == 1)
|
||||
{
|
||||
ApiGuildWars2Account account = accounts.First();
|
||||
await SignUp(buttonType, raidId, roleId, 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, roleId, userIdToSignUp, signedUpByUserId) , ephemeral: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
await component.RespondAsync("no suitable Guild Wars 2 account found.", ephemeral: true);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SignUp(string buttonType, int raidId, int roleId, ulong userIdToSignUp, int gw2AccountId, ulong signedUpByUserId)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//to avoid error messages because of no response...
|
||||
public async Task Respond(SocketInteraction component)
|
||||
|
|
|
@ -42,15 +42,7 @@ namespace DiscordBot.CommandHandlers
|
|||
|
||||
//sign up
|
||||
CreateAccountModal.Parameters createAccountParameters = CreateAccountModal.ParseId(modal.Data.CustomId);
|
||||
if(await _handlerFunctions.IsRaidSignUpAllowed(modal, createAccountParameters.RaidId, createAccountParameters.ButtonId))
|
||||
{
|
||||
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);
|
||||
await _handlerFunctions.SelectRole(modal, createAccountParameters.RaidId, createAccountParameters.ButtonId, false, modal.User.Id, 0);
|
||||
break;
|
||||
case Constants.ComponentIds.SIGN_UP_EXTERNAL_MODAL:
|
||||
string userName = components.First(x => x.CustomId == Constants.ComponentIds.NAME_TEXT_BOX).Value;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,8 +22,6 @@ namespace DiscordBot.CommandHandlers
|
|||
_handlerFunctions = new HandlerFunctions(_httpService);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task Handler(SocketSlashCommand command)
|
||||
{
|
||||
Tuple<bool, string> commandExecutionAllowed = await _httpService.IsSlashCommandAllowed(command.User.Id, command.Data.Name);
|
||||
|
@ -99,24 +97,20 @@ namespace DiscordBot.CommandHandlers
|
|||
}
|
||||
|
||||
private async Task SignUpUser(SocketSlashCommand command, IUser user, int raidId)
|
||||
{
|
||||
if(await _handlerFunctions.IsRaidSignUpAllowed(command, raidId, Constants.ComponentIds.SIGN_UP_BUTTON))
|
||||
{
|
||||
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: RoleSelectionMessage.buildMessage(roles, raidId, Constants.ComponentIds.SIGN_UP_BUTTON, false, user.Id) , ephemeral: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(await _httpService.DoesUserExist(user.Id))
|
||||
{
|
||||
Tuple<bool, string> signUpAllowed = await _httpService.IsSignUpAllowed(raidId, user.Id, true);
|
||||
if(!signUpAllowed.Item1)
|
||||
{
|
||||
await SignUpExternalUser(command, raidId, roles);
|
||||
await command.RespondAsync(signUpAllowed.Item2, ephemeral: true);
|
||||
return;
|
||||
}
|
||||
await _handlerFunctions.SelectRole(command, raidId, Constants.ComponentIds.SIGN_UP_BUTTON, false, user.Id, command.User.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
await SignUpExternalUser(command, raidId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,21 +119,16 @@ namespace DiscordBot.CommandHandlers
|
|||
if(await _handlerFunctions.IsRaidSignUpAllowed(command, raidId, Constants.ComponentIds.SIGN_UP_BUTTON))
|
||||
{
|
||||
List<ApiRole> roles = await _httpService.GetRoles(raidId, uint.MaxValue);
|
||||
await SignUpExternalUser(command, raidId, roles);
|
||||
Tuple<bool, string> signUpAllowed = await _httpService.IsExternalSignUpAllowed(raidId);
|
||||
if(!signUpAllowed.Item1)
|
||||
{
|
||||
await command.RespondAsync(signUpAllowed.Item2, ephemeral: true);
|
||||
return;
|
||||
}
|
||||
await command.RespondAsync("Please choose a role.", components: ExternalRoleSelectionMessage.buildMessage(roles, raidId) , ephemeral: true);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
await command.RespondAsync("Please choose a role.", components: ExternalRoleSelectionMessage.buildMessage(roles, raidId) , ephemeral: true);
|
||||
}
|
||||
|
||||
private async Task SendMessages(string message, int raidId)
|
||||
{
|
||||
ApiRaid raid = await _httpService.GetRaid(raidId);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue