Misc GetBots() enhancements

This commit is contained in:
JustArchi
2019-01-19 04:08:08 +01:00
parent f668dd3309
commit ee8e9f27c6

View File

@@ -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<Bot> 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<Bot> regexMatches = Bots.Where(kvp => Regex.IsMatch(kvp.Key, botPattern, BotsRegex)).Select(kvp => kvp.Value);
Regex regex = new Regex(botPattern, BotsRegex);
IEnumerable<Bot> 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)) {