diff --git a/DiscordBot/CommandHandlers/SelectMenuHandler.cs b/DiscordBot/CommandHandlers/SelectMenuHandler.cs index 82afcc1..c723493 100644 --- a/DiscordBot/CommandHandlers/SelectMenuHandler.cs +++ b/DiscordBot/CommandHandlers/SelectMenuHandler.cs @@ -1,10 +1,7 @@ -using Discord; -using Discord.Commands; using Discord.WebSocket; -using System.Reflection; +using DiscordBot.Messages; using DiscordBot.Services; using SharedClasses.SharedModels; -using DiscordBot.Messages; namespace DiscordBot.CommandHandlers { @@ -33,6 +30,10 @@ namespace DiscordBot.CommandHandlers 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.REMOVE_USER_DROP_DOWN: + RemoveUserMessage.Parameters removeUserParameters = RemoveUserMessage.ParseId(component.Data.CustomId); + await RemoveUser(component, removeUserParameters); + break; case Constants.ComponentIds.ACCOUNT_SELECT_DROP_DOWN: AccountSelectionMessage.Parameters accountParameters = AccountSelectionMessage.ParseId(component.Data.CustomId); int accountId = int.Parse(component.Data.Values.First()); @@ -55,5 +56,24 @@ namespace DiscordBot.CommandHandlers break; } } + + private async Task RemoveUser(SocketMessageComponent component, RemoveUserMessage.Parameters removeUserParameters) + { + ApiSignUp signOff = new ApiSignUp() + { + raidId = removeUserParameters.RaidId, + signedUpByUserId = removeUserParameters.SignedUpByUserId + }; + if (ulong.TryParse(component.Data.Values.First(), out ulong userId)) + { + signOff.userId = userId; + } + else + { + signOff.userName = component.Data.Values.First(); + } + await _httpService.SignOff(signOff); + await _handlerFunctions.UpdateOrRespond(component, $"signed off {component.Data.Values.First()}", null, true); + } } } \ No newline at end of file diff --git a/DiscordBot/CommandHandlers/SlashCommandHandler.cs b/DiscordBot/CommandHandlers/SlashCommandHandler.cs index df40bc6..4ab7f68 100644 --- a/DiscordBot/CommandHandlers/SlashCommandHandler.cs +++ b/DiscordBot/CommandHandlers/SlashCommandHandler.cs @@ -94,6 +94,10 @@ namespace DiscordBot.CommandHandlers await _httpService.SignOff(signOffExternal); await command.RespondAsync($"signed off {userName}", ephemeral:true); break; + case Constants.SlashCommands.REMOVE_USER_DROPDOWN_COMMAND: + ApiRaid raid = await _httpService.GetRaid(raidId); + await command.RespondAsync("Which user do you want to sign off?", components: RemoveUserMessage.buildMessage(raid, command.User.Id), ephemeral: true); + break; } } diff --git a/DiscordBot/Constants.cs b/DiscordBot/Constants.cs index b15ddb9..4afe09b 100644 --- a/DiscordBot/Constants.cs +++ b/DiscordBot/Constants.cs @@ -15,6 +15,7 @@ public const string ROLE_SELECT_DROP_DOWN = "roleSelectDropDown"; public const string ROLE_SELECT_EXTERNAL_DROP_DOWN = "roleSelectExternalDropDown"; public const string ACCOUNT_SELECT_DROP_DOWN = "accountSelectDropDown"; + public const string REMOVE_USER_DROP_DOWN = "removeUserDropDown"; public const string NAME_TEXT_BOX = "nameTextbox"; public const string ACCOUNT_TEXT_BOX = "accountTextBox"; @@ -33,6 +34,7 @@ public const string REMOVE_USER_COMMAND = "remove"; public const string ADD_EXTERNAL_USER_COMMAND = "add-external"; public const string REMOVE_EXTERNAL_USER_COMMAND = "remove-external"; + public const string REMOVE_USER_DROPDOWN_COMMAND = "remove-dropdown"; public class OptionNames { diff --git a/DiscordBot/Messages/RemoveUserMessage.cs b/DiscordBot/Messages/RemoveUserMessage.cs new file mode 100644 index 0000000..9b2fac3 --- /dev/null +++ b/DiscordBot/Messages/RemoveUserMessage.cs @@ -0,0 +1,61 @@ +using Discord; +using SharedClasses.SharedModels; +using System.Security.Principal; + +namespace DiscordBot.Messages +{ + public class RemoveUserMessage + { + + public static MessageComponent buildMessage(ApiRaid raid, ulong signedUpByUserId) + { + var signUpSelect = new SelectMenuBuilder() + .WithPlaceholder("Select an account") + .WithCustomId($"{Constants.ComponentIds.REMOVE_USER_DROP_DOWN}-{raid.RaidId}-{signedUpByUserId}") + .WithMinValues(1) + .WithMaxValues(1); + + foreach (ApiRaid.Role role in raid.Roles) + { + foreach (ApiRaid.Role.User user in role.Users) + { + if(user.UserId > 0) + { + signUpSelect.AddOption($"({user.UserName} | {user.AccountName}", user.UserId.ToString()); + } + else + { + signUpSelect.AddOption(user.UserName, user.UserName); + } + } + } + + 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) + { + ulong.TryParse(ids[2], out parameters.SignedUpByUserId); + } + return parameters; + } + + public class Parameters + { + public int RaidId; + public ulong SignedUpByUserId; + } + } +} diff --git a/DiscordBot/SlashCommands/RaidSlashCommand.cs b/DiscordBot/SlashCommands/RaidSlashCommand.cs index 43c91ed..828192c 100644 --- a/DiscordBot/SlashCommands/RaidSlashCommand.cs +++ b/DiscordBot/SlashCommands/RaidSlashCommand.cs @@ -47,6 +47,12 @@ namespace DiscordBot.SlashCommands .AddOption(Constants.SlashCommands.OptionNames.RAID_ID, ApplicationCommandOptionType.Integer, "The Id of the Raid, found at the bottom of the raid message", isRequired: true) .AddOption(Constants.SlashCommands.OptionNames.USER_NAME, ApplicationCommandOptionType.String, "The user name you want to sign off", isRequired: true) ) + .AddOption(new SlashCommandOptionBuilder() + .WithName(Constants.SlashCommands.REMOVE_USER_DROPDOWN_COMMAND) + .WithDescription("Sign off user via dropdown") + .WithType(ApplicationCommandOptionType.SubCommand) + .AddOption(Constants.SlashCommands.OptionNames.RAID_ID, ApplicationCommandOptionType.Integer, "The Id of the Raid, found at the bottom of the raid message", isRequired: true) + ) ) .AddOption(new SlashCommandOptionBuilder() .WithName(Constants.SlashCommands.SEND_MESSAGE_COMMAND)