/// <summary> /// Editing a 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 RunEditSubRoleAssistantAsync(CommandContextContainer commandContextContainer, long mainRoleId) { var roleId = await SelectRoleAsync(commandContextContainer, mainRoleId).ConfigureAwait(false); if (roleId != null) { var builder = new DiscordEmbedBuilder(); builder.WithTitle(LocalizationGroup.GetText("RoleEditTitle", "Raid role configuration")); var descriptionEmoji = DiscordEmojiService.GetEditEmoji(commandContextContainer.Client); var emojiEmoji = DiscordEmojiService.GetEmojiEmoji(commandContextContainer.Client); var cancelEmoji = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client); var commands = new StringBuilder(); commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditDescriptionCommand", "{0} Edit description", descriptionEmoji)); commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditEmojiCommand", "{0} Edit emoji", emojiEmoji)); commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantCancelCommand", "{0} Cancel", cancelEmoji)); builder.AddField(LocalizationGroup.GetText("AssistantCommandsField", "Commands"), commands.ToString()); var message = await commandContextContainer.Channel .SendMessageAsync(builder) .ConfigureAwait(false); var userReactionTask = commandContextContainer.Client .GetInteractivity() .WaitForReactionAsync(message, commandContextContainer.User); await message.CreateReactionAsync(descriptionEmoji).ConfigureAwait(false); await message.CreateReactionAsync(emojiEmoji).ConfigureAwait(false); await message.CreateReactionAsync(cancelEmoji).ConfigureAwait(false); var userReaction = await userReactionTask.ConfigureAwait(false); if (userReaction.TimedOut == false) { if (userReaction.Result.Emoji.Id == descriptionEmoji.Id) { await RunEditDescriptionAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false); } else if (userReaction.Result.Emoji.Id == emojiEmoji.Id) { await RunEditEmojiAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false); } } } }
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditSuperiorRoleCommand", "{0} Edit superior role", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var newSuperiorLevelId = await RunSubElement <RaidExperienceLevelSuperiorLevelDialogElement, long?>() .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var levelId = DialogContext.GetValue <long>("ExperienceLevelId"); dbFactory.GetRepository <RaidExperienceLevelRepository>() .Refresh(obj => obj.SuperiorExperienceLevelId == levelId, obj => obj.SuperiorExperienceLevelId = obj.SuperiorRaidExperienceLevel.SuperiorExperienceLevelId); if (dbFactory.GetRepository <RaidExperienceLevelRepository>() .RefreshRange(obj => obj.Id != levelId, obj => obj.SuperiorExperienceLevelId = newSuperiorLevelId)) { if (dbFactory.GetRepository <RaidExperienceLevelRepository>() .RefreshRange(obj => obj.SuperiorExperienceLevelId == newSuperiorLevelId && obj.Id != levelId, obj => obj.SuperiorExperienceLevelId = levelId)) { dbFactory.GetRepository <RaidExperienceLevelRepository>() .RefreshRanks(); } } } return true; } },
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditDescriptionCommand", "{0} Edit description", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var description = await RunSubElement <CalendarTemplateDescriptionDialogElement, string>() .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var templateId = DialogContext.GetValue <long>("CalendarTemplateId"); dbFactory.GetRepository <CalendarAppointmentTemplateRepository>() .Refresh(obj => obj.Id == templateId, obj => obj.Description = description); } return true; } },
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditAliasCommand", "{0} Edit alias name", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var aliasName = await RunSubElement <RaidTemplateAliasNameDialogElement, string>() .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var templateId = DialogContext.GetValue <long>("TemplateId"); dbFactory.GetRepository <RaidDayTemplateRepository>() .Refresh(obj => obj.Id == templateId, obj => obj.AliasName = aliasName); } return true; } },
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditInGameNameCommand", "{0} Edit in game name", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var inGameName = await RunSubElement <GuildRankInGameNameDialogElement, string>().ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var rankId = DialogContext.GetValue <int>("RankId"); dbFactory.GetRepository <GuildRankRepository>() .Refresh(obj => obj.Id == rankId, obj => obj.InGameName = inGameName); } return true; } },
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { if (_reactions == null) { _reactions = new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add schedule", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var data = await DialogHandler.RunForm <CreateCalendarScheduleData>(CommandContext, false) .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var level = new CalendarAppointmentScheduleEntity { DiscordServerId = CommandContext.Guild.Id, Description = data.Description, CalendarAppointmentTemplateId = data.TemplateId, Type = data.Schedule.Type, AdditionalData = data.Schedule.AdditionalData }; dbFactory.GetRepository <CalendarAppointmentScheduleRepository>() .Add(level); } return(true); } } }; if (GetSchedules().Count > 0) { _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit schedule", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var levelId = await RunSubElement <CalendarScheduleSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("CalendarScheduleId", levelId); bool repeat; do { repeat = await RunSubElement <CalendarScheduleEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); return(true); } }); _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete schedule", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)), Func = async() => { var levelId = await RunSubElement <CalendarScheduleSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("CalendarScheduleId", levelId); return(await RunSubElement <CalendarScheduleDeletionDialogElement, bool>().ConfigureAwait(false)); } }); } _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) }); } return(_reactions); }
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { if (_reactions == null) { _reactions = new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add rank", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var data = await DialogHandler.RunForm <CreateGuildSpecialRankData>(CommandContext, false) .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var rank = new GuildSpecialRankConfigurationEntity { GuildId = dbFactory.GetRepository <GuildRepository>() .GetQuery() .Where(obj => obj.DiscordServerId == CommandContext.Guild.Id) .Select(obj => obj.Id) .First(), Description = data.Description, DiscordRoleId = data.DiscordRoleId, MaximumPoints = data.MaximumPoints, GrantThreshold = data.GrantThreshold, RemoveThreshold = data.RemoveThreshold }; if (dbFactory.GetRepository <GuildSpecialRankConfigurationRepository>() .Add(rank)) { DialogContext.SetValue("RankId", rank.Id); bool repeat; do { repeat = await RunSubElement <GuildSpecialRankEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); } } return(true); } } }; if (GetRanks().Count > 0) { _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit rank", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var levelId = await RunSubElement <GuildSpecialRankSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("RankId", levelId); bool repeat; do { repeat = await RunSubElement <GuildSpecialRankEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); return(true); } }); _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete rank", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)), Func = async() => { var rankId = await RunSubElement <GuildSpecialRankSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("RankId", rankId); return(await RunSubElement <GuildSpecialRankDeletionDialogElement, bool>().ConfigureAwait(false)); } }); } _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) }); } return(_reactions); }
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { return(_reactions ??= new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditApiKeyCommand", "{0} Edit api key", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var success = false; var apiKey = await RunSubElement <AccountApiKeyDialogElement, string>().ConfigureAwait(false); apiKey = apiKey?.Trim(); if (string.IsNullOrWhiteSpace(apiKey) == false) { try { var connector = new GuidWars2ApiConnector(apiKey); await using (connector.ConfigureAwait(false)) { var tokenInformation = await connector.GetTokenInformationAsync() .ConfigureAwait(false); if (tokenInformation?.Permissions != null && tokenInformation.Permissions.Contains(TokenInformation.Permission.Account) && tokenInformation.Permissions.Contains(TokenInformation.Permission.Characters) && tokenInformation.Permissions.Contains(TokenInformation.Permission.Progression)) { var accountInformation = await connector.GetAccountInformationAsync() .ConfigureAwait(false); if (accountInformation.Name == DialogContext.GetValue <string>("AccountName")) { using (var dbFactory = RepositoryFactory.CreateInstance()) { var user = await CommandContext.GetCurrentUser() .ConfigureAwait(false); if (dbFactory.GetRepository <AccountRepository>() .Refresh(obj => obj.UserId == user.Id && obj.Name == accountInformation.Name, obj => { obj.ApiKey = apiKey; obj.Permissions = GuildWars2ApiPermissionConverter.ToPermission(tokenInformation.Permissions); })) { success = true; } } } else { await CommandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("AccountNameMismatch", "The provided api key doesn't match the current account name.")) .ConfigureAwait(false); } } else { await CommandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("InvalidToken", "The provided token is invalid or doesn't have the required permissions.")) .ConfigureAwait(false); } } } catch (HttpRequestException ex) when(ex.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) { await CommandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("InvalidToken", "The provided token is invalid or doesn't have the required permissions.")) .ConfigureAwait(false); } } return success; } }, new () { Emoji = DiscordEmojiService.GetEdit2Emoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditDpsReportUserTokenCommand", "{0} Edit dps report user token", DiscordEmojiService.GetEdit2Emoji(CommandContext.Client)), Func = async() => { var token = await RunSubElement <AccountDpsReportUserTokenDialogElement, string>() .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var accountName = DialogContext.GetValue <string>("AccountName"); var user = await CommandContext.GetCurrentUser() .ConfigureAwait(false); dbFactory.GetRepository <AccountRepository>() .Refresh(obj => obj.UserId == user.Id && obj.Name == accountName, obj => obj.DpsReportUserToken = token); } return true; } }, new () { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) } });
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { if (_reactions == null) { _reactions = new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add template", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var data = await DialogHandler.RunForm <CreateRaidTemplateFormData>(CommandContext, false) .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { dbFactory.GetRepository <RaidDayTemplateRepository>() .Add(new RaidDayTemplateEntity { AliasName = data.AliasName, Title = data.Title, Description = data.Description, Thumbnail = data.Thumbnail }); } return(true); } } }; if (GetTemplates().Count > 0) { _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit template", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var templateId = await RunSubElement <RaidTemplateSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("TemplateId", templateId); bool repeat; do { repeat = await RunSubElement <RaidTemplateEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); return(true); } }); _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete template", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)), Func = async() => { var templateId = await RunSubElement <RaidTemplateSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("TemplateId", templateId); return(await RunSubElement <RaidTemplateDeletionElementBase, bool>().ConfigureAwait(false)); } }); } _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) }); } return(_reactions); }
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { if (_reactions == null) { _reactions = new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add level", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var data = await DialogHandler.RunForm <CreateRaidExperienceLevelData>(CommandContext, false) .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var level = new RaidExperienceLevelEntity { SuperiorExperienceLevelId = data.SuperiorExperienceLevelId, Description = data.Description, DiscordEmoji = data.DiscordEmoji, DiscordRoleId = data.DiscordRoleId, }; if (dbFactory.GetRepository <RaidExperienceLevelRepository>() .Add(level)) { if (dbFactory.GetRepository <RaidExperienceLevelRepository>() .RefreshRange(obj => obj.SuperiorExperienceLevelId == data.SuperiorExperienceLevelId && obj.Id != level.Id, obj => obj.SuperiorExperienceLevelId = level.Id)) { dbFactory.GetRepository <RaidExperienceLevelRepository>() .RefreshRanks(); } } } return(true); } } }; if (GetLevels().Count > 0) { _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit level", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var levelId = await RunSubElement <RaidExperienceLevelSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("ExperienceLevelId", levelId); bool repeat; do { repeat = await RunSubElement <RaidExperienceLevelEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); return(true); } }); _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete level", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)), Func = async() => { var levelId = await RunSubElement <RaidExperienceLevelSelectionDialogElement, long>().ConfigureAwait(false); DialogContext.SetValue("ExperienceLevelId", levelId); return(await RunSubElement <RaidExperienceLevelDeletionDialogElement, bool>().ConfigureAwait(false)); } }); } _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) }); } return(_reactions); }
/// <summary> /// Returns the reactions which should be added to the message /// </summary> /// <returns>Reactions</returns> public override IReadOnlyList <ReactionData <bool> > GetReactions() { if (_reactions == null) { _reactions = new List <ReactionData <bool> > { new () { Emoji = DiscordEmojiService.GetAddEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add rank", DiscordEmojiService.GetAddEmoji(CommandContext.Client)), Func = async() => { var data = await DialogHandler.RunForm <CreateGuildRankFormData>(CommandContext, false) .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var rank = new GuildRankEntity { GuildId = dbFactory.GetRepository <GuildRepository>() .GetQuery() .Where(obj => obj.DiscordServerId == CommandContext.Guild.Id) .Select(obj => obj.Id) .First(), DiscordRoleId = data.DiscordRoleId, InGameName = data.InGameName, Percentage = data.Percentage, Order = data.SuperiorId != null ? dbFactory.GetRepository <GuildRankRepository>() .GetQuery() .Where(obj => obj.Id == data.SuperiorId) .Select(obj => obj.Order) .First() + 1 : 0, }; if (dbFactory.GetRepository <GuildRankRepository>() .Add(rank)) { var order = rank.Order + 1; foreach (var currentRankId in dbFactory.GetRepository <GuildRankRepository>() .GetQuery() .Where(obj => obj.Order >= rank.Order) .OrderBy(obj => obj.Order) .Select(obj => obj.Id)) { dbFactory.GetRepository <GuildRankRepository>() .Refresh(obj => obj.Id == currentRankId, obj => obj.Order = order); order++; } DialogContext.SetValue("RankId", rank.Id); bool repeat; do { repeat = await RunSubElement <GuildRankEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); } } return(true); } } }; if (GetRanks().Count > 0) { _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetEditEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit rank", DiscordEmojiService.GetEditEmoji(CommandContext.Client)), Func = async() => { var levelId = await RunSubElement <GuildRankSelectionDialogElement, int>().ConfigureAwait(false); DialogContext.SetValue("RankId", levelId); bool repeat; do { repeat = await RunSubElement <GuildRankEditDialogElement, bool>().ConfigureAwait(false); }while (repeat); return(true); } }); _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete rank", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)), Func = async() => { var rankId = await RunSubElement <GuildRankSelectionDialogElement, int>().ConfigureAwait(false); DialogContext.SetValue("RankId", rankId); return(await RunSubElement <GuildRankDeletionDialogElement, bool>().ConfigureAwait(false)); } }); } _reactions.Add(new ReactionData <bool> { Emoji = DiscordEmojiService.GetCrossEmoji(CommandContext.Client), CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)), Func = () => Task.FromResult(false) }); } return(_reactions); }
/// <summary> /// Starting the roles assistant /// </summary> /// <param name="commandContextContainer">Current command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task RunAssistantAsync(CommandContextContainer commandContextContainer) { var builder = new DiscordEmbedBuilder(); builder.WithTitle(LocalizationGroup.GetText("AssistantTitle", "Raid role configuration")); builder.WithDescription(LocalizationGroup.GetText("AssistantDescription", "With this assistant you are able to configure the raid roles. The following roles are already created:")); var areRolesAvailable = false; using (var dbFactory = RepositoryFactory.CreateInstance()) { var mainRoles = dbFactory.GetRepository <RaidRoleRepository>() .GetQuery() .Where(obj => obj.MainRoleId == null && obj.IsDeleted == false) .Select(obj => new { obj.DiscordEmojiId, obj.Description, SubRoles = obj.SubRaidRoles .Where(obj2 => obj2.IsDeleted == false) .Select(obj2 => new { obj2.DiscordEmojiId, obj2.Description }) }) .OrderBy(obj => obj.Description) .ToList(); if (mainRoles.Count > 0) { areRolesAvailable = true; foreach (var role in mainRoles) { var roles = new StringBuilder(1024, 1024); foreach (var subRole in role.SubRoles) { roles.Append("> "); roles.Append(DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, subRole.DiscordEmojiId)); roles.Append(' '); roles.Append(subRole.Description); roles.Append('\n'); } roles.Append('\n'); builder.AddField($"{DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, role.DiscordEmojiId)} {role.Description}", roles.ToString()); } } } var addEmoji = DiscordEmojiService.GetAddEmoji(commandContextContainer.Client); var editEmoji = DiscordEmojiService.GetEditEmoji(commandContextContainer.Client); var deleteEmoji = DiscordEmojiService.GetTrashCanEmoji(commandContextContainer.Client); var cancelEmoji = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client); var commands = new StringBuilder(); commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantAddCommand", "{0} Add role", addEmoji)); if (areRolesAvailable) { commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantEditCommand", "{0} Edit role", editEmoji)); commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantDeleteCommand", "{0} Delete role", deleteEmoji)); } commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantCancelCommand", "{0} Cancel", cancelEmoji)); builder.AddField(LocalizationGroup.GetText("AssistantCommandsField", "Commands"), commands.ToString()); var message = await commandContextContainer.Channel .SendMessageAsync(builder) .ConfigureAwait(false); var userReactionTask = commandContextContainer.Client .GetInteractivity() .WaitForReactionAsync(message, commandContextContainer.User); await message.CreateReactionAsync(addEmoji).ConfigureAwait(false); await message.CreateReactionAsync(editEmoji).ConfigureAwait(false); if (areRolesAvailable) { await message.CreateReactionAsync(deleteEmoji).ConfigureAwait(false); await message.CreateReactionAsync(cancelEmoji).ConfigureAwait(false); } var userReaction = await userReactionTask.ConfigureAwait(false); if (userReaction.TimedOut == false) { if (userReaction.Result.Emoji.Id == addEmoji.Id) { await RunAddAssistantAsync(commandContextContainer).ConfigureAwait(false); } else if (userReaction.Result.Emoji.Id == editEmoji.Id && areRolesAvailable) { await RunEditAssistantAsync(commandContextContainer).ConfigureAwait(false); } else if (userReaction.Result.Emoji.Id == deleteEmoji.Id) { await RunDeleteAssistantAsync(commandContextContainer).ConfigureAwait(false); } } }
/// <summary> /// Starting the role editing assistant /// </summary> /// <param name="commandContextContainer">Current command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task RunEditAssistantAsync(CommandContextContainer commandContextContainer) { var roleId = await SelectRoleAsync(commandContextContainer, null).ConfigureAwait(false); if (roleId != null) { var builder = new DiscordEmbedBuilder(); builder.WithTitle(LocalizationGroup.GetText("RoleEditTitle", "Raid role configuration")); var areRolesAvailable = false; using (var dbFactory = RepositoryFactory.CreateInstance()) { var rolesFieldText = new StringBuilder(); var roles = dbFactory.GetRepository <RaidRoleRepository>() .GetQuery() .Where(obj => obj.Id == roleId.Value && obj.IsDeleted == false) .Select(obj => new { obj.DiscordEmojiId, obj.Description, SubRoles = obj.SubRaidRoles .Where(obj2 => obj2.IsDeleted == false) .Select(obj2 => new { obj2.DiscordEmojiId, obj2.Description }) }) .OrderBy(obj => obj.Description) .First(); builder.WithDescription($"{DiscordEmoji.FromGuildEmote(commandContextContainer.Client, roles.DiscordEmojiId)} - {roles.Description}"); if (roles.SubRoles.Any()) { areRolesAvailable = true; foreach (var role in roles.SubRoles) { rolesFieldText.Append(DiscordEmoji.FromGuildEmote(commandContextContainer.Client, role.DiscordEmojiId)); rolesFieldText.Append(" - "); rolesFieldText.Append(role.Description); rolesFieldText.Append('\n'); } builder.AddField(LocalizationGroup.GetText("AssistantRolesField", "Roles"), rolesFieldText.ToString()); } } var addSubRoleEmoji = DiscordEmojiService.GetAddEmoji(commandContextContainer.Client); var descriptionEmoji = DiscordEmojiService.GetEditEmoji(commandContextContainer.Client); var editSubRoleEmoji = DiscordEmojiService.GetEdit2Emoji(commandContextContainer.Client); var emojiEmoji = DiscordEmojiService.GetEmojiEmoji(commandContextContainer.Client); var deleteSubRoleEmoji = DiscordEmojiService.GetTrashCanEmoji(commandContextContainer.Client); var cancelEmoji = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client); var commands = new StringBuilder(); commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditDescriptionCommand", "{0} Edit description", descriptionEmoji)); commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditEmojiCommand", "{0} Edit emoji", emojiEmoji)); commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditAddSubRoleCommand", "{0} Add sub role", addSubRoleEmoji)); if (areRolesAvailable) { commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditSubRoleCommand", "{0} Edit sub role", editSubRoleEmoji)); commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditDeleteSubRoleCommand", "{0} Delete sub role", deleteSubRoleEmoji)); } commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantCancelCommand", "{0} Cancel", cancelEmoji)); builder.AddField(LocalizationGroup.GetText("AssistantCommandsField", "Commands"), commands.ToString()); var message = await commandContextContainer.Channel .SendMessageAsync(builder) .ConfigureAwait(false); var userReactionTask = commandContextContainer.Client .GetInteractivity() .WaitForReactionAsync(message, commandContextContainer.User); await message.CreateReactionAsync(descriptionEmoji).ConfigureAwait(false); await message.CreateReactionAsync(emojiEmoji).ConfigureAwait(false); await message.CreateReactionAsync(addSubRoleEmoji).ConfigureAwait(false); if (areRolesAvailable) { await message.CreateReactionAsync(editSubRoleEmoji).ConfigureAwait(false); await message.CreateReactionAsync(deleteSubRoleEmoji).ConfigureAwait(false); } await message.CreateReactionAsync(cancelEmoji).ConfigureAwait(false); var userReaction = await userReactionTask.ConfigureAwait(false); if (userReaction.TimedOut == false) { if (userReaction.Result.Emoji.Id == addSubRoleEmoji.Id) { await RunAddSubRoleAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false); } else if (userReaction.Result.Emoji.Id == descriptionEmoji.Id) { await RunEditDescriptionAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false); } else if (userReaction.Result.Emoji.Id == editSubRoleEmoji.Id) { await RunEditSubRoleAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false); } else if (userReaction.Result.Emoji.Id == emojiEmoji.Id) { await RunEditEmojiAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false); } else if (userReaction.Result.Emoji.Id == deleteSubRoleEmoji.Id) { await RunDeleteSubRoleAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false); } } } }