/// <summary> /// Editing a new sub role /// </summary> /// <param name="commandContextContainer">Current command context</param> /// <param name="mainRoleId">Id of the role</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task RunAddSubRoleAssistantAsync(CommandContextContainer commandContextContainer, long mainRoleId) { var interactivity = commandContextContainer.Client.GetInteractivity(); var currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("ReactWithEmojiPrompt", "Please react with emoji which should be assigned to the role.")) .ConfigureAwait(false); var reaction = await interactivity.WaitForReactionAsync(currentBotMessage, commandContextContainer.User) .ConfigureAwait(false); if (reaction.TimedOut == false && reaction.Result.Emoji.Id > 0) { var subRoleData = new RaidRoleEntity { MainRoleId = mainRoleId, DiscordEmojiId = reaction.Result.Emoji.Id }; currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("DescriptionPrompt", "Please enter the description of the role.")) .ConfigureAwait(false); var currentUserResponse = await interactivity.WaitForMessageAsync(obj => obj.Author.Id == commandContextContainer.User.Id && obj.ChannelId == commandContextContainer.Channel.Id) .ConfigureAwait(false); if (currentUserResponse.TimedOut == false) { subRoleData.Description = currentUserResponse.Result.Content; using (var dbFactory = RepositoryFactory.CreateInstance()) { dbFactory.GetRepository <RaidRoleRepository>() .Add(subRoleData); } } } }
/// <summary> /// Starting the roles adding assistant /// </summary> /// <param name="commandContextContainer">Current command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task RunAddAssistantAsync(CommandContextContainer commandContextContainer) { var currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("ReactWithEmojiPrompt", "Please react with emoji which should be assigned to the role.")) .ConfigureAwait(false); var interactivity = commandContextContainer.Client .GetInteractivity(); var reaction = await interactivity.WaitForReactionAsync(currentBotMessage, commandContextContainer.User) .ConfigureAwait(false); if (reaction.TimedOut == false && reaction.Result.Emoji.Id > 0) { var roleData = new RaidRoleEntity { DiscordEmojiId = reaction.Result.Emoji.Id }; currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("DescriptionPrompt", "Please enter the description of the role.")) .ConfigureAwait(false); var currentUserResponse = await interactivity.WaitForMessageAsync(obj => obj.Author.Id == commandContextContainer.User.Id && obj.ChannelId == commandContextContainer.Channel.Id) .ConfigureAwait(false); if (currentUserResponse.TimedOut == false) { roleData.Description = currentUserResponse.Result.Content; var continueCreation = true; var subRolesData = new List <RaidRoleEntity>(); var checkEmoji = DiscordEmojiService.GetCheckEmoji(commandContextContainer.Client); var crossEmoji = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client); var addSubRoles = true; while (addSubRoles) { var promptText = subRolesData.Count == 0 ? LocalizationGroup.GetText("AddSubRolesPrompt", "Do you want to add sub roles?") : LocalizationGroup.GetText("AddAdditionalSubRolesPrompt", "Do you want to add additional sub roles?"); currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(promptText) .ConfigureAwait(false); var userReactionTask = commandContextContainer.Client .GetInteractivity() .WaitForReactionAsync(currentBotMessage, commandContextContainer.User); await currentBotMessage.CreateReactionAsync(checkEmoji).ConfigureAwait(false); await currentBotMessage.CreateReactionAsync(crossEmoji).ConfigureAwait(false); var userReaction = await userReactionTask.ConfigureAwait(false); if (userReaction.TimedOut == false) { if (userReaction.Result.Emoji.Id == checkEmoji.Id) { currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("ReactWithEmojiPrompt", "Please react with emoji which should be assigned to the role.")) .ConfigureAwait(false); reaction = await interactivity.WaitForReactionAsync(currentBotMessage, commandContextContainer.User) .ConfigureAwait(false); if (reaction.TimedOut == false && reaction.Result.Emoji.Id > 0) { var subRoleData = new RaidRoleEntity { DiscordEmojiId = reaction.Result.Emoji.Id }; currentBotMessage = await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("DescriptionPrompt", "Please enter the description of the role.")) .ConfigureAwait(false); currentUserResponse = await interactivity.WaitForMessageAsync(obj => obj.Author.Id == commandContextContainer.User.Id && obj.ChannelId == commandContextContainer.Channel.Id) .ConfigureAwait(false); if (currentUserResponse.TimedOut == false) { subRoleData.Description = currentUserResponse.Result.Content; subRolesData.Add(subRoleData); } else { continueCreation = false; } } else { continueCreation = false; } } else { addSubRoles = false; } } else { continueCreation = false; } } if (continueCreation) { using (var dbFactory = RepositoryFactory.CreateInstance()) { if (dbFactory.GetRepository <RaidRoleRepository>() .Add(roleData)) { foreach (var subRole in subRolesData) { subRole.MainRoleId = roleData.Id; dbFactory.GetRepository <RaidRoleRepository>() .Add(subRole); } } } await commandContextContainer.Channel .SendMessageAsync(LocalizationGroup.GetText("CreationCompletedMessage", "The creation is completed.")) .ConfigureAwait(false); } } } }