public override async Task Function(TelegramBotClient bot) { var players = GameManager.GetAllActivePlayersWithTaskMonitoring(); if (players == null || !players.Any()) { return; } var games = players.Select(x => x.Game).Distinct(); foreach (var game in games) { var engine = IGameEngine.Get(game); var newTask = engine.GetTask(game, out List <object>?stuff); if (newTask == null) { continue; } var lastTask = (game.LastTaskId.HasValue) ? GameManager.GetTaskById(game.LastTaskId.Value) : null; if (lastTask == null || !lastTask.Equals(newTask)) { newTask.GameId = game.Id; GameManager.AddTask(newTask); foreach (var player in players.Where(x => x.Game.Id == game.Id)) { var result = new ProcessingResult() { ChatId = player.ChatId, IsHtml = true, Text = player.UpdateTaskInfo == GC2DB.Data.Player.PlayerUpdateStatusInfo.UpdateText ? newTask.Text : "UP!" }; await result.Finish(bot, null); } } } }