From 5ae0a4de2478d4630b10c9487e4412b5405eb0d7 Mon Sep 17 00:00:00 2001 From: Sellara <147769367+Sella-GH@users.noreply.github.com> Date: Tue, 4 Jun 2024 23:09:23 +0200 Subject: [PATCH] More improving of Linq --- AzzyBot-Next/Utilities/AzzyHelp.cs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/AzzyBot-Next/Utilities/AzzyHelp.cs b/AzzyBot-Next/Utilities/AzzyHelp.cs index 50b10be3..8373f3d5 100644 --- a/AzzyBot-Next/Utilities/AzzyHelp.cs +++ b/AzzyBot-Next/Utilities/AzzyHelp.cs @@ -37,16 +37,7 @@ public static AzzyHelpRecord GetSingleCommand(IReadOnlyDictionary> record in GetCommandGroups(commands, adminServer, approvedDebug, member)) - { - foreach (AzzyHelpRecord subRecord in record.Value) - { - if (subRecord.Name == commandName) - return subRecord; - } - } - - throw new InvalidOperationException("Command not found"); + return GetCommandGroups(commands, adminServer, approvedDebug, member).FirstOrDefault(r => r.Value.Any(c => c.Name == commandName)).Value.FirstOrDefault() ?? throw new InvalidOperationException("Command not found"); } private static Dictionary> GetCommandGroups(IReadOnlyDictionary commands, bool adminServer, bool approvedDebug, DiscordMember member)