Skip to content

Commit

Permalink
Add support for bot.. and ..bot syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Sep 24, 2023
1 parent b5ecd31 commit af6eb07
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions ArchiSteamFarm/Steam/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ public EAccess GetAccess(ulong steamID) {
throw new InvalidOperationException(nameof(Bots));
}

if (BotsComparer == null) {
throw new InvalidOperationException(nameof(BotsComparer));
}

string[] botNames = args.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

HashSet<Bot> result = new();
Expand All @@ -491,26 +495,41 @@ public EAccess GetAccess(ulong steamID) {
return result;
}

if (botName.Contains("..", StringComparison.Ordinal)) {
if ((botName.Length > 2) && botName.Contains("..", StringComparison.Ordinal)) {
string[] botRange = botName.Split(new[] { ".." }, StringSplitOptions.RemoveEmptyEntries);

if (botRange.Length == 2) {
Bot? firstBot = GetBot(botRange[0]);
Bot? firstBot = GetBot(botRange[0]);

if (firstBot != null) {
switch (botRange.Length) {
case 1:
// Either bot.. or ..bot
IEnumerable<Bot> query = Bots.OrderBy(static bot => bot.Key, BotsComparer).Select(static bot => bot.Value);

if (firstBot != null) {
Bot? lastBot = GetBot(botRange[1]);
query = botName.StartsWith("..", StringComparison.Ordinal) ? query.TakeWhile(bot => bot != firstBot) : query.SkipWhile(bot => bot != firstBot);

if (lastBot != null) {
foreach (Bot bot in Bots.OrderBy(static bot => bot.Key, BotsComparer).Select(static bot => bot.Value).SkipWhile(bot => bot != firstBot)) {
foreach (Bot bot in query) {
result.Add(bot);
}

result.Add(firstBot);

if (bot == lastBot) {
break;
continue;
case 2:
// firstBot..lastBot
Bot? lastBot = GetBot(botRange[1]);

if ((lastBot != null) && (BotsComparer.Compare(firstBot.BotName, lastBot.BotName) <= 0)) {
foreach (Bot bot in Bots.OrderBy(static bot => bot.Key, BotsComparer).Select(static bot => bot.Value).SkipWhile(bot => bot != firstBot).TakeWhile(bot => bot != lastBot)) {
result.Add(bot);
}

result.Add(lastBot);

continue;
}

continue;
}
break;
}
}
}
Expand Down

0 comments on commit af6eb07

Please sign in to comment.