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]))
|
if(await _handlerFunctions.IsRaidSignUpAllowed(component, parsedRaidId, ids[0]))
|
||||||
{
|
{
|
||||||
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
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;
|
break;
|
||||||
case Constants.ComponentIds.MAYBE_BUTTON:
|
case Constants.ComponentIds.MAYBE_BUTTON:
|
||||||
|
@ -43,7 +43,7 @@ namespace DiscordBot.CommandHandlers
|
||||||
if(await _handlerFunctions.IsRaidSignUpAllowed(component, parsedRaidId, ids[0]))
|
if(await _handlerFunctions.IsRaidSignUpAllowed(component, parsedRaidId, ids[0]))
|
||||||
{
|
{
|
||||||
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
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;
|
break;
|
||||||
case Constants.ComponentIds.SIGN_OFF_BUTTON:
|
case Constants.ComponentIds.SIGN_OFF_BUTTON:
|
||||||
|
|
|
@ -22,13 +22,7 @@ namespace DiscordBot.CommandHandlers
|
||||||
{
|
{
|
||||||
if(! await _httpService.DoesUserExist(component.User.Id))
|
if(! await _httpService.DoesUserExist(component.User.Id))
|
||||||
{
|
{
|
||||||
var mb = new ModalBuilder()
|
await component.RespondWithModalAsync(CreateAccountModal.buildMessage(raidId, pressedButtonId, component.User.Username));
|
||||||
.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());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Tuple<bool, string> signUpAllowed = await _httpService.IsSignUpAllowed(raidId, component.User.Id);
|
Tuple<bool, string> signUpAllowed = await _httpService.IsSignUpAllowed(raidId, component.User.Id);
|
||||||
|
|
|
@ -41,24 +41,26 @@ namespace DiscordBot.CommandHandlers
|
||||||
}
|
}
|
||||||
|
|
||||||
//sign up
|
//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);
|
List<ApiRole> roles = await _httpService.GetRoles(createAccountParameters.RaidId, modal.User.Id);
|
||||||
await modal.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, parsedRaidId, ids[2], false) , ephemeral: true);
|
await modal.RespondAsync("Please choose a role.",
|
||||||
|
components: RoleSelectionMessage.buildMessage(roles, createAccountParameters.RaidId, createAccountParameters.ButtonId, false),
|
||||||
|
ephemeral: true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await _handlerFunctions.Respond(modal);
|
await _handlerFunctions.Respond(modal);
|
||||||
break;
|
break;
|
||||||
case Constants.ComponentIds.SIGN_UP_EXTERNAL_MODAL:
|
case Constants.ComponentIds.SIGN_UP_EXTERNAL_MODAL:
|
||||||
string userName = components.First(x => x.CustomId == Constants.ComponentIds.NAME_TEXT_BOX).Value;
|
string userName = components.First(x => x.CustomId == Constants.ComponentIds.NAME_TEXT_BOX).Value;
|
||||||
int raidId = int.Parse(ids[1]);
|
ExternalUserNameModal.Parameters modalParameters = ExternalUserNameModal.ParseId(modal.Data.CustomId);
|
||||||
int roleId = int.Parse(ids[2]);
|
|
||||||
ApiSignUp signUpExternal = new ApiSignUp()
|
ApiSignUp signUpExternal = new ApiSignUp()
|
||||||
{
|
{
|
||||||
raidId = raidId,
|
raidId = modalParameters.RaidId,
|
||||||
userName = userName,
|
userName = userName,
|
||||||
signedUpByUserId = modal.User.Id,
|
signedUpByUserId = modal.User.Id,
|
||||||
roleId = roleId
|
roleId = modalParameters.RoleId
|
||||||
};
|
};
|
||||||
await _httpService.SignUp(signUpExternal);
|
await _httpService.SignUp(signUpExternal);
|
||||||
await modal.RespondAsync($"signed up {userName}", ephemeral: true);
|
await modal.RespondAsync($"signed up {userName}", ephemeral: true);
|
||||||
|
|
|
@ -22,49 +22,63 @@ namespace DiscordBot.CommandHandlers
|
||||||
public async Task Handler(SocketMessageComponent component)
|
public async Task Handler(SocketMessageComponent component)
|
||||||
{
|
{
|
||||||
string[] ids = component.Data.CustomId.Split('-');
|
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])
|
switch(ids[0])
|
||||||
{
|
{
|
||||||
case Constants.ComponentIds.SIGN_UP_DROP_DOWN:
|
case Constants.ComponentIds.SIGN_UP_DROP_DOWN:
|
||||||
ulong userId = 0;
|
RoleSelectionMessage.Parameters roleParameters = RoleSelectionMessage.ParseId(component.Data.CustomId);
|
||||||
if(ids.Length >= 4)
|
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 ManageSignUp(roleParameters.ButtonType, roleParameters.RaidId, component, userIdToSignUp, signedUpByUserId);
|
||||||
await component.RespondAsync("successfully signed up", ephemeral: true);
|
|
||||||
break;
|
break;
|
||||||
case Constants.ComponentIds.SIGN_UP_EXTERNAL_DROP_DOWN:
|
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;
|
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;
|
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,
|
ApiGuildWars2Account account = accounts.First();
|
||||||
roleId = parsedRoleId
|
await SignUp(buttonType, raidId, parsedRoleId, userIdToSignUp, account.GuildWars2AccountId, signedUpByUserId);
|
||||||
};
|
await component.RespondAsync("successfully signed up", ephemeral: true);
|
||||||
|
}
|
||||||
if(userIdToSignUp == 0)
|
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
|
else
|
||||||
{
|
{
|
||||||
signUp.userId = userIdToSignUp;
|
await component.RespondAsync("no suitable Guild Wars 2 account found.", ephemeral: true);
|
||||||
signUp.signedUpByUserId = component.User.Id;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
switch(buttonType)
|
||||||
{
|
{
|
||||||
|
@ -82,15 +96,5 @@ namespace DiscordBot.CommandHandlers
|
||||||
break;
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,6 +25,9 @@ namespace DiscordBot.CommandHandlers
|
||||||
|
|
||||||
|
|
||||||
public async Task Handler(SocketSlashCommand command)
|
public async Task Handler(SocketSlashCommand command)
|
||||||
|
{
|
||||||
|
Tuple<bool, string> commandExecutionAllowed = await _httpService.IsSlashCommandAllowed(command.User.Id, command.Data.Name);
|
||||||
|
if(commandExecutionAllowed.Item1)
|
||||||
{
|
{
|
||||||
switch (command.Data.Name)
|
switch (command.Data.Name)
|
||||||
{
|
{
|
||||||
|
@ -33,6 +36,11 @@ namespace DiscordBot.CommandHandlers
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await command.RespondAsync(commandExecutionAllowed.Item2, ephemeral:true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task HandleRaidCommands(SocketSlashCommand command)
|
private async Task HandleRaidCommands(SocketSlashCommand command)
|
||||||
{
|
{
|
||||||
|
@ -103,7 +111,7 @@ namespace DiscordBot.CommandHandlers
|
||||||
await command.RespondAsync(signUpAllowed.Item2, ephemeral: true);
|
await command.RespondAsync(signUpAllowed.Item2, ephemeral: true);
|
||||||
return;
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -129,23 +137,7 @@ namespace DiscordBot.CommandHandlers
|
||||||
await command.RespondAsync(signUpAllowed.Item2, ephemeral: true);
|
await command.RespondAsync(signUpAllowed.Item2, ephemeral: true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await command.RespondAsync("Please choose a role.", components: ExternalRoleSelectionMessage.buildMessage(roles, raidId) , ephemeral: true);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SendMessages(string message, int raidId)
|
private async Task SendMessages(string message, int raidId)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
public const string SIGN_UP_DROP_DOWN = "signUpDropDown";
|
public const string SIGN_UP_DROP_DOWN = "signUpDropDown";
|
||||||
public const string SIGN_UP_EXTERNAL_DROP_DOWN = "signUpExternalDropDown";
|
public const string SIGN_UP_EXTERNAL_DROP_DOWN = "signUpExternalDropDown";
|
||||||
|
public const string ACCOUNT_SELECT_DROP_DOWN = "accountSelectDropDown";
|
||||||
|
|
||||||
public const string NAME_TEXT_BOX = "nameTextbox";
|
public const string NAME_TEXT_BOX = "nameTextbox";
|
||||||
public const string ACCOUNT_TEXT_BOX = "accountTextBox";
|
public const string ACCOUNT_TEXT_BOX = "accountTextBox";
|
||||||
|
|
64
DiscordBot/Messages/AccountSelectionMessage.cs
Normal file
64
DiscordBot/Messages/AccountSelectionMessage.cs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
using Discord;
|
||||||
|
using SharedClasses.SharedModels;
|
||||||
|
|
||||||
|
namespace DiscordBot.Messages
|
||||||
|
{
|
||||||
|
public class AccountSelectionMessage
|
||||||
|
{
|
||||||
|
public static MessageComponent buildMessage(List<ApiGuildWars2Account> accounts, int raidId, string buttonType, int roleId, ulong userIdToSignUp, ulong signedUpByUserId)
|
||||||
|
{
|
||||||
|
var signUpSelect = new SelectMenuBuilder()
|
||||||
|
.WithPlaceholder("Select an account")
|
||||||
|
.WithCustomId($"{Constants.ComponentIds.ACCOUNT_SELECT_DROP_DOWN}-{raidId}-{buttonType}-{roleId}-{userIdToSignUp}-{signedUpByUserId}")
|
||||||
|
.WithMinValues(1)
|
||||||
|
.WithMaxValues(1);
|
||||||
|
|
||||||
|
foreach(ApiGuildWars2Account account in accounts)
|
||||||
|
{
|
||||||
|
signUpSelect.AddOption(account.AccountName, account.GuildWars2AccountId.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder = new ComponentBuilder()
|
||||||
|
.WithSelectMenu(signUpSelect, 0);
|
||||||
|
|
||||||
|
return builder.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Parameters ParseId(string customId)
|
||||||
|
{
|
||||||
|
Parameters parameters = new Parameters();
|
||||||
|
|
||||||
|
string[] ids = customId.Split('-');
|
||||||
|
if(ids.Length > 1)
|
||||||
|
{
|
||||||
|
int.TryParse(ids[1],out parameters.RaidId);
|
||||||
|
}
|
||||||
|
if(ids.Length > 2)
|
||||||
|
{
|
||||||
|
parameters.ButtonType = ids[2];
|
||||||
|
}
|
||||||
|
if(ids.Length > 3)
|
||||||
|
{
|
||||||
|
int.TryParse(ids[3],out parameters.RoleId);
|
||||||
|
}
|
||||||
|
if(ids.Length > 4)
|
||||||
|
{
|
||||||
|
ulong.TryParse(ids[4],out parameters.UserIdToSignUp);
|
||||||
|
}
|
||||||
|
if(ids.Length > 5)
|
||||||
|
{
|
||||||
|
ulong.TryParse(ids[5],out parameters.SignedUpByUserId);
|
||||||
|
}
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Parameters
|
||||||
|
{
|
||||||
|
public int RaidId;
|
||||||
|
public string ButtonType = string.Empty;
|
||||||
|
public int RoleId;
|
||||||
|
public ulong UserIdToSignUp;
|
||||||
|
public ulong SignedUpByUserId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
DiscordBot/Messages/CreateAccountModal.cs
Normal file
40
DiscordBot/Messages/CreateAccountModal.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
using Discord;
|
||||||
|
|
||||||
|
namespace DiscordBot.Messages
|
||||||
|
{
|
||||||
|
public class CreateAccountModal
|
||||||
|
{
|
||||||
|
public static Modal buildMessage(int raidId, string pressedButtonId, string defaultUserName)
|
||||||
|
{
|
||||||
|
var mb = new ModalBuilder()
|
||||||
|
.WithTitle("Create Account")
|
||||||
|
.WithCustomId($"{Constants.ComponentIds.CREATE_ACCOUNT_MODAL}-{raidId}-{pressedButtonId}")
|
||||||
|
.AddTextInput("Name", Constants.ComponentIds.NAME_TEXT_BOX, placeholder: defaultUserName, required: true, value: defaultUserName)
|
||||||
|
.AddTextInput("Guild Wars 2 Account", Constants.ComponentIds.ACCOUNT_TEXT_BOX, placeholder: "Account.1234", required: true);
|
||||||
|
|
||||||
|
return mb.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Parameters ParseId(string customId)
|
||||||
|
{
|
||||||
|
Parameters parameters = new Parameters();
|
||||||
|
|
||||||
|
string[] ids = customId.Split('-');
|
||||||
|
if(ids.Length > 1)
|
||||||
|
{
|
||||||
|
int.TryParse(ids[1],out parameters.RaidId);
|
||||||
|
}
|
||||||
|
if(ids.Length > 2)
|
||||||
|
{
|
||||||
|
parameters.ButtonId = ids[2];
|
||||||
|
}
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Parameters
|
||||||
|
{
|
||||||
|
public int RaidId;
|
||||||
|
public string ButtonId = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,24 +1,21 @@
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.WebSocket;
|
|
||||||
using System;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using SharedClasses.SharedModels;
|
using SharedClasses.SharedModels;
|
||||||
|
|
||||||
namespace DiscordBot.Messages
|
namespace DiscordBot.Messages
|
||||||
{
|
{
|
||||||
public class SignUpMessage
|
public class ExternalRoleSelectionMessage
|
||||||
{
|
{
|
||||||
public static MessageComponent buildMessage(List<ApiRole> roles, int raidId, string buttonType, bool allRoles, ulong userIdToSignUp = 0)
|
public static MessageComponent buildMessage(List<ApiRole> roles, int raidId)
|
||||||
{
|
{
|
||||||
var signUpSelect = new SelectMenuBuilder()
|
var signUpSelect = new SelectMenuBuilder()
|
||||||
.WithPlaceholder("Select an option")
|
.WithPlaceholder("Select an option")
|
||||||
.WithCustomId($"{Constants.ComponentIds.SIGN_UP_DROP_DOWN}-{raidId}-{buttonType}-{userIdToSignUp}")
|
.WithCustomId($"{Constants.ComponentIds.SIGN_UP_EXTERNAL_DROP_DOWN}-{raidId}")
|
||||||
.WithMinValues(1)
|
.WithMinValues(1)
|
||||||
.WithMaxValues(1);
|
.WithMaxValues(1);
|
||||||
|
|
||||||
foreach(ApiRole role in roles)
|
foreach(ApiRole role in roles)
|
||||||
{
|
{
|
||||||
if(allRoles || role.IsSignUpAllowed)
|
if(role.IsSignUpAllowed)
|
||||||
signUpSelect.AddOption(role.Name, role.roleId.ToString(), role.Description);
|
signUpSelect.AddOption(role.Name, role.roleId.ToString(), role.Description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,5 +24,22 @@ namespace DiscordBot.Messages
|
||||||
|
|
||||||
return builder.Build();
|
return builder.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Parameters ParseId(string customId)
|
||||||
|
{
|
||||||
|
Parameters parameters = new Parameters();
|
||||||
|
|
||||||
|
string[] ids = customId.Split('-');
|
||||||
|
if(ids.Length > 1)
|
||||||
|
{
|
||||||
|
int.TryParse(ids[1],out parameters.RaidId);
|
||||||
|
}
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Parameters
|
||||||
|
{
|
||||||
|
public int RaidId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
43
DiscordBot/Messages/ExternalUserNameModal.cs
Normal file
43
DiscordBot/Messages/ExternalUserNameModal.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
using Discord;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using SharedClasses.SharedModels;
|
||||||
|
|
||||||
|
namespace DiscordBot.Messages
|
||||||
|
{
|
||||||
|
public class ExternalUserNameModal
|
||||||
|
{
|
||||||
|
public static Modal buildMessage(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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Parameters ParseId(string customId)
|
||||||
|
{
|
||||||
|
Parameters parameters = new Parameters();
|
||||||
|
|
||||||
|
string[] ids = customId.Split('-');
|
||||||
|
if(ids.Length > 1)
|
||||||
|
{
|
||||||
|
int.TryParse(ids[1],out parameters.RaidId);
|
||||||
|
}
|
||||||
|
if(ids.Length > 2)
|
||||||
|
{
|
||||||
|
int.TryParse(ids[2],out parameters.RoleId);
|
||||||
|
}
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Parameters
|
||||||
|
{
|
||||||
|
public int RaidId;
|
||||||
|
public int RoleId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
DiscordBot/Messages/RoleSelectionMessage.cs
Normal file
55
DiscordBot/Messages/RoleSelectionMessage.cs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
using Discord;
|
||||||
|
using SharedClasses.SharedModels;
|
||||||
|
|
||||||
|
namespace DiscordBot.Messages
|
||||||
|
{
|
||||||
|
public class RoleSelectionMessage
|
||||||
|
{
|
||||||
|
public static MessageComponent buildMessage(List<ApiRole> roles, int raidId, string buttonType, bool allRoles, ulong userIdToSignUp = 0)
|
||||||
|
{
|
||||||
|
var signUpSelect = new SelectMenuBuilder()
|
||||||
|
.WithPlaceholder("Select an option")
|
||||||
|
.WithCustomId($"{Constants.ComponentIds.SIGN_UP_DROP_DOWN}-{raidId}-{buttonType}-{userIdToSignUp}")
|
||||||
|
.WithMinValues(1)
|
||||||
|
.WithMaxValues(1);
|
||||||
|
|
||||||
|
foreach(ApiRole role in roles)
|
||||||
|
{
|
||||||
|
if(allRoles || role.IsSignUpAllowed)
|
||||||
|
signUpSelect.AddOption(role.Name, role.roleId.ToString(), role.Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder = new ComponentBuilder()
|
||||||
|
.WithSelectMenu(signUpSelect, 0);
|
||||||
|
|
||||||
|
return builder.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Parameters ParseId(string customId)
|
||||||
|
{
|
||||||
|
Parameters parameters = new Parameters();
|
||||||
|
|
||||||
|
string[] ids = customId.Split('-');
|
||||||
|
if(ids.Length > 1)
|
||||||
|
{
|
||||||
|
int.TryParse(ids[1],out parameters.RaidId);
|
||||||
|
}
|
||||||
|
if(ids.Length > 2)
|
||||||
|
{
|
||||||
|
parameters.ButtonType = ids[2];
|
||||||
|
}
|
||||||
|
if(ids.Length > 3)
|
||||||
|
{
|
||||||
|
ulong.TryParse(ids[3],out parameters.UserIdToSignUp);
|
||||||
|
}
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Parameters
|
||||||
|
{
|
||||||
|
public int RaidId;
|
||||||
|
public string ButtonType = string.Empty;
|
||||||
|
public ulong UserIdToSignUp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -187,5 +187,36 @@ namespace DiscordBot.Services
|
||||||
}
|
}
|
||||||
return new ApiRaid.Role.User();
|
return new ApiRaid.Role.User();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<ApiGuildWars2Account>> GetSignUpAccounts(ulong userId, int raidId)
|
||||||
|
{
|
||||||
|
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||||
|
|
||||||
|
var httpResponseMessage = await httpClient.GetAsync($"DiscordBot/GetSignUpAccounts/{userId}/{raidId}");
|
||||||
|
|
||||||
|
if (httpResponseMessage.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
using var contentStream =
|
||||||
|
await httpResponseMessage.Content.ReadAsStreamAsync();
|
||||||
|
|
||||||
|
return await JsonSerializer.DeserializeAsync<List<ApiGuildWars2Account>>(contentStream, _serializerOptions);
|
||||||
|
}
|
||||||
|
return new List<ApiGuildWars2Account>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Tuple<bool, string>> IsSlashCommandAllowed(ulong userId, string command)
|
||||||
|
{
|
||||||
|
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||||
|
|
||||||
|
var httpResponseMessage = await httpClient.GetAsync($"DiscordBot/IsSlashCommandAllowed/{userId}/{command}");
|
||||||
|
|
||||||
|
if (!httpResponseMessage.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
ProblemDetails problemDetails = await httpResponseMessage.Content.ReadFromJsonAsync<ProblemDetails>(_serializerOptions) ?? new ProblemDetails();
|
||||||
|
string errorMessage = string.IsNullOrEmpty(problemDetails.Detail) ? string.Empty : problemDetails.Detail;
|
||||||
|
return new Tuple<bool, string>(false, errorMessage);
|
||||||
|
}
|
||||||
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue