Esempio n. 1
0
        public async Task <IActionResult> OnPost(string message)
        {
            _logger.LogInformation($"BROADCASTING TO ALL WORKSPACES");
            try
            {
                await _publisher.PublishToAllWorkspaceChannels(message);

                TempData["msg"] = "Broadcasted!";
            }
            catch (Exception e)
            {
                TempData["msg"] = $"Broadcast failed '{e}'";
            }

            return(RedirectToPage("Broadcast"));
        }
Esempio n. 2
0
        public async Task Handle(GameweekJustBegan notification, CancellationToken cancellationToken)
        {
            var newGameweek = notification.Gameweek.Id;
            await _publisher.PublishToAllWorkspaceChannels($"Gameweek {newGameweek}!");

            var teams = await _teamRepo.GetAllTeams();

            foreach (var team in teams)
            {
                try
                {
                    var messages = new List <string>();

                    if (team.Subscriptions.ContainsSubscriptionFor(EventSubscription.Captains))
                    {
                        messages.Add(await _captainsByGameweek.GetCaptainsByGameWeek(newGameweek, (int)team.FplbotLeagueId));
                        messages.Add(await _captainsByGameweek.GetCaptainsChartByGameWeek(newGameweek, (int)team.FplbotLeagueId));
                    }
                    else
                    {
                        _logger.LogInformation("Team {team} hasn't subscribed for gw start captains, so bypassing it", team.TeamId);
                    }

                    if (team.Subscriptions.ContainsSubscriptionFor(EventSubscription.Transfers))
                    {
                        messages.Add(await _transfersByGameweek.GetTransfersByGameweekTexts(newGameweek, (int)team.FplbotLeagueId));
                    }
                    else
                    {
                        _logger.LogInformation("Team {team} hasn't subscribed for gw start transfers, so bypassing it", team.TeamId);
                    }

                    await _publisher.PublishToWorkspace(team.TeamId, team.FplBotSlackChannel, messages.ToArray());
                }
                catch (Exception e)
                {
                    _logger.LogError(e, e.Message);
                }
            }
        }