diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 0c570a6c0..427543d01 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -705,6 +705,8 @@ namespace ArchiSteamFarm { } return await ResponseRedeem(steamID, args[1], ERedeemFlags.ForceForwarding | ERedeemFlags.SkipInitial).ConfigureAwait(false); + case "!REJOINCHAT": + return await ResponseRejoinChat(steamID, args[1]).ConfigureAwait(false); case "!RESUME": return await ResponseResume(steamID, args[1]).ConfigureAwait(false); case "!START": @@ -2814,23 +2816,51 @@ namespace ArchiSteamFarm { return responses.Count > 0 ? string.Join("", responses) : null; } - private static string ResponseRejoinChat(ulong steamID) { + private string ResponseRejoinChat(ulong steamID) { if (steamID == 0) { - ASF.ArchiLogger.LogNullError(nameof(steamID)); + ArchiLogger.LogNullError(nameof(steamID)); return null; } - if (!IsOwner(steamID)) { + if (!IsMaster(steamID)) { return null; } - foreach (Bot bot in Bots.Values) { - bot.JoinMasterChat(); - } - + JoinMasterChat(); return FormatStaticResponse(Strings.Done); } + private static async Task ResponseRejoinChat(ulong steamID, string botNames) { + if ((steamID == 0) || string.IsNullOrEmpty(botNames)) { + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNames)); + return null; + } + + HashSet bots = GetBots(botNames); + if ((bots == null) || (bots.Count == 0)) { + return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNames)) : null; + } + + ICollection results; + IEnumerable> tasks = bots.Select(bot => Task.Run(() => bot.ResponseRejoinChat(steamID))); + + switch (Program.GlobalConfig.OptimizationMode) { + case GlobalConfig.EOptimizationMode.MinMemoryUsage: + results = new List(bots.Count); + foreach (Task task in tasks) { + results.Add(await task.ConfigureAwait(false)); + } + + break; + default: + results = await Task.WhenAll(tasks).ConfigureAwait(false); + break; + } + + List responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); + return responses.Count > 0 ? string.Join("", responses) : null; + } + private static string ResponseRestart(ulong steamID) { if (steamID == 0) { ASF.ArchiLogger.LogNullError(nameof(steamID));