diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index e226ef844..383bf066c 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -314,9 +314,8 @@ namespace ArchiSteamFarm { foreach (string botName in botNames) { if (botName.Equals(SharedInfo.ASF, StringComparison.OrdinalIgnoreCase)) { - foreach (Bot bot in Bots.OrderBy(bot => bot.Key).Select(bot => bot.Value)) { - result.Add(bot); - } + IEnumerable allBots = Bots.OrderBy(bot => bot.Key).Select(bot => bot.Value); + result.UnionWith(allBots); return result; } @@ -324,38 +323,34 @@ namespace ArchiSteamFarm { if (botName.Contains("..")) { string[] botRange = botName.Split(new[] { ".." }, StringSplitOptions.RemoveEmptyEntries); - if (botRange.Length == 2) { - if (Bots.TryGetValue(botRange[0], out Bot firstBot) && Bots.TryGetValue(botRange[1], out Bot lastBot)) { - bool inRange = false; + if ((botRange.Length == 2) && Bots.TryGetValue(botRange[0], out Bot firstBot) && Bots.TryGetValue(botRange[1], out Bot lastBot)) { + foreach (Bot bot in Bots.OrderBy(bot => bot.Key).Select(bot => bot.Value).SkipWhile(bot => bot != firstBot)) { + result.Add(bot); - foreach (Bot bot in Bots.OrderBy(bot => bot.Key).Select(bot => bot.Value)) { - if (bot == firstBot) { - inRange = true; - } else if (!inRange) { - continue; - } - - result.Add(bot); - - if (bot == lastBot) { - break; - } + if (bot == lastBot) { + break; } - - continue; } + + continue; } - } else if (botName.StartsWith("r!", StringComparison.OrdinalIgnoreCase)) { + } + + if (botName.StartsWith("r!", StringComparison.OrdinalIgnoreCase)) { string botPattern = botName.Substring(2); try { - IEnumerable regexMatches = Bots.Where(kvp => Regex.IsMatch(kvp.Key, botPattern, BotsRegex)).Select(kvp => kvp.Value); + Regex regex = new Regex(botPattern, BotsRegex); + + IEnumerable regexMatches = Bots.Where(kvp => regex.IsMatch(kvp.Key)).Select(kvp => kvp.Value); result.UnionWith(regexMatches); } catch (ArgumentException e) { ASF.ArchiLogger.LogGenericWarningException(e); return null; } + + continue; } if (!Bots.TryGetValue(botName, out Bot targetBot)) {