Ejemplo n.º 1
0
        public async Task Handle(OneHourToDeadline notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Notifying about 60 minutes to (gw{notification.Gameweek.Id}) deadline");
            var allSlackTeams = await _teamRepo.GetAllTeams();

            foreach (var team in allSlackTeams)
            {
                if (team.Subscriptions.ContainsSubscriptionFor(EventSubscription.Deadlines))
                {
                    await _workspacePublisher.PublishToWorkspace(team.TeamId, team.FplBotSlackChannel, $"<!channel> ⏳ Gameweek {notification.Gameweek.Id} deadline in 60 minutes!");
                }
            }
        }
Ejemplo n.º 2
0
    public async Task Handle(FixtureFinished message, IMessageHandlerContext context)
    {
        _logger.LogInformation("Handling fixture full time");
        var teams = await _slackTeamRepo.GetAllTeams();

        var settings = await _settingsClient.GetGlobalSettings();

        var fixtures = await _fixtureClient.GetFixtures();

        var fplfixture    = fixtures.FirstOrDefault(f => f.Id == message.FixtureId);
        var fixture       = FixtureFulltimeModelBuilder.CreateFinishedFixture(settings.Teams, settings.Players, fplfixture);
        var title         = $"*FT: {fixture.HomeTeam.ShortName} {fixture.Fixture.HomeTeamScore}-{fixture.Fixture.AwayTeamScore} {fixture.AwayTeam.ShortName}*";
        var threadMessage = Formatter.FormatProvisionalFinished(fixture);

        foreach (var slackTeam in teams)
        {
            if (slackTeam.HasRegisteredFor(EventSubscription.FixtureFullTime))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishFulltimeMessageToSlackWorkspace(slackTeam.TeamId, title, threadMessage), options);
            }
        }
    }
Ejemplo n.º 3
0
        public async Task Handle(GameweekFinished notification, CancellationToken cancellationToken)
        {
            var gameweek = notification.Gameweek.Id;
            var settings = await _gameweekClient.GetGlobalSettings();

            var gameweeks = settings.Gameweeks;
            var gw        = gameweeks.SingleOrDefault(g => g.Id == gameweek);

            if (gw == null)
            {
                _logger.LogError("Found no gameweek with id {id}", gameweek);
                return;
            }

            var teams = await _teamRepo.GetAllTeams();

            foreach (var team in teams)
            {
                if (!team.Subscriptions.ContainsSubscriptionFor(EventSubscription.Standings))
                {
                    _logger.LogInformation("Team {team} hasn't subscribed for gw standings, so bypassing it", team.TeamId);
                    continue;
                }

                try
                {
                    await _mediator.Publish(new PublishStandingsCommand(team, gw), cancellationToken);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, e.Message);
                }
            }
        }
Ejemplo n.º 4
0
    public async Task Handle(InjuryUpdateOccured notification, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Handling {notification.PlayersWithInjuryUpdates.Count()} injury updates");
        var filtered = notification.PlayersWithInjuryUpdates.Where(c => c.Player.IsRelevant());

        if (filtered.Any())
        {
            var formatted  = Formatter.FormatInjuryStatusUpdates(filtered);
            var slackTeams = await _slackTeamRepo.GetAllTeams();

            foreach (var slackTeam in slackTeams)
            {
                if (slackTeam.HasRegisteredFor(EventSubscription.InjuryUpdates))
                {
                    var options = new SendOptions();
                    options.RequireImmediateDispatch();
                    options.RouteToThisEndpoint();
                    await context.Send(new PublishToSlack(slackTeam.TeamId, slackTeam.FplBotSlackChannel, formatted), options);
                }
            }
        }
        else
        {
            _logger.LogInformation("All updates injuries irrelevant, so not sending any notification");
        }
    }
Ejemplo n.º 5
0
    public async Task Handle(OneHourToDeadline message, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Notifying about 60 minutes to (gw{message.GameweekNearingDeadline.Id}) deadline");
        var allSlackTeams = await _teamRepo.GetAllTeams();

        foreach (var team in allSlackTeams)
        {
            if (team.HasRegisteredFor(EventSubscription.Deadlines))
            {
                var text    = $"<!channel> ⏳ Gameweek {message.GameweekNearingDeadline.Id} deadline in 60 minutes!";
                var command = new PublishToSlack(team.TeamId, team.FplBotSlackChannel, text);
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(command, options);
            }
        }
    }
Ejemplo n.º 6
0
        public async Task OnGet()
        {
            var teams = await _teamRepo.GetAllTeams();

            foreach (var t in teams)
            {
                Workspaces.Add(t);
            }
        }
Ejemplo n.º 7
0
    public async Task PublishToAllWorkspaceChannels(string msg)
    {
        var teams = await _repository.GetAllTeams();

        foreach (var team in teams)
        {
            await PublishToWorkspace(team.TeamId, team.FplBotSlackChannel, msg);
        }
    }
Ejemplo n.º 8
0
        public async Task OnGet()
        {
            var teams = await _teamRepo.GetAllTeams();

            foreach (var t in teams)
            {
                Workspaces.Add(t);
            }

            CurrentLeagueIndexingBookmark = await _indexBookmarkProvider.GetBookmark();
        }
Ejemplo n.º 9
0
    public async Task Handle(GameweekJustBegan notification, IMessageHandlerContext context)
    {
        var teams = await _teamRepo.GetAllTeams();

        foreach (var team in teams)
        {
            var options = new SendOptions();
            options.RequireImmediateDispatch();
            options.RouteToThisEndpoint();
            await context.Send(new ProcessGameweekStartedForSlackWorkspace(team.TeamId, notification.NewGameweek.Id), options);
        }
    }
Ejemplo n.º 10
0
    public async Task Handle(FixtureEventsOccured message, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Handling {message.FixtureEvents.Count} new fixture events");
        var slackTeams = await _slackTeamRepo.GetAllTeams();

        foreach (var slackTeam in slackTeams)
        {
            var options = new SendOptions();
            options.RequireImmediateDispatch();
            options.RouteToThisEndpoint();
            await context.Send(new PublishFixtureEventsToSlackWorkspace(slackTeam.TeamId, message.FixtureEvents), options);
        }
    }
Ejemplo n.º 11
0
    public async Task Handle(GameweekFinished notification, IMessageHandlerContext context)
    {
        var teams = await _teamRepo.GetAllTeams();

        foreach (var team in teams)
        {
            if (team.HasRegisteredFor(EventSubscription.Standings))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishStandingsToSlackWorkspace(team.TeamId, team.FplBotSlackChannel, team.FplbotLeagueId.Value, notification.FinishedGameweek.Id), options);
            }
        }
    }
Ejemplo n.º 12
0
    public async Task Handle(LineupReady message, IMessageHandlerContext context)
    {
        _logger.LogInformation("Handling new lineups");
        var slackTeams = await _slackTeamRepo.GetAllTeams();

        foreach (var slackTeam in slackTeams)
        {
            if (slackTeam.HasRegisteredFor(EventSubscription.Lineups))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishLineupsToSlackWorkspace(slackTeam.TeamId, message.Lineup), options);
            }
        }
    }
Ejemplo n.º 13
0
    public async Task Handle(PlayersPriceChanged notification, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Handling {notification.PlayersWithPriceChanges.Count()} price updates");
        var slackTeams = await _slackTeamRepo.GetAllTeams();

        foreach (var slackTeam in slackTeams)
        {
            if (slackTeam.HasRegisteredFor(EventSubscription.PriceChanges))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishPriceChangesToSlackWorkspace(slackTeam.TeamId, notification.PlayersWithPriceChanges.ToList()), options);
            }
        }
    }
Ejemplo n.º 14
0
        public async Task Handle(FixtureEventsOccured notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Handling new fixture events");
            var slackTeams = await _slackTeamRepo.GetAllTeams();

            foreach (var slackTeam in slackTeams)
            {
                try
                {
                    await HandleForTeam(notification.FixtureEvents, slackTeam);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, e.Message);
                }
            }
        }
Ejemplo n.º 15
0
    public async Task Handle(NewPlayersRegistered notification, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Handling {notification.NewPlayers.Count()} new players");
        var slackTeams = await _slackTeamRepo.GetAllTeams();

        var formatted = Formatter.FormatNewPlayers(notification.NewPlayers);

        foreach (var slackTeam in slackTeams)
        {
            if (slackTeam.HasRegisteredFor(EventSubscription.NewPlayers))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishToSlack(slackTeam.TeamId, slackTeam.FplBotSlackChannel, formatted), options);
            }
        }
    }
    public async Task Handle(FixtureRemovedFromGameweek message, IMessageHandlerContext context)
    {
        _logger.LogInformation("Fixture removed from gameweek {Message}", message);

        var teams = await _teamRepo.GetAllTeams();

        foreach (var team in teams)
        {
            if (team.Subscriptions.ContainsSubscriptionFor(EventSubscription.FixtureAssists))
            {
                var fixture = $"{message.RemovedFixture.Home.Name}-{message.RemovedFixture.Away.Name}";
                var msg     = $"❌ *Fixture off!*\n {fixture} has been removed from gameweek {message.Gameweek}!";
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishToSlack(team.TeamId, team.FplBotSlackChannel, msg), options);
            }
        }
    }
Ejemplo n.º 17
0
        public async Task Handle(FixturesFinished notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Handling fixture full time");
            var teams = await _slackTeamRepo.GetAllTeams();

            foreach (var slackTeam in teams)
            {
                if (slackTeam.Subscriptions.ContainsSubscriptionFor(EventSubscription.FixtureFullTime))
                {
                    foreach (var fixture in notification.FinishedFixture)
                    {
                        var title     = $"*FT: {fixture.HomeTeam.ShortName} {fixture.Fixture.HomeTeamScore}-{fixture.Fixture.AwayTeamScore} {fixture.AwayTeam.ShortName}*";
                        var formatted = Formatter.FormatProvisionalFinished(fixture);
                        await PublishFulltimeMessage(slackTeam, title, formatted);
                    }
                }
            }

            async Task PublishFulltimeMessage(SlackTeam team, string title, string thread)
            {
                var slackClient = _builder.Build(team.AccessToken);

                try
                {
                    var res = await slackClient.ChatPostMessage(team.FplBotSlackChannel, title);

                    if (res.Ok)
                    {
                        await slackClient.ChatPostMessage(new ChatPostMessageRequest
                        {
                            Channel = team.FplBotSlackChannel, thread_ts = res.ts, Text = thread, unfurl_links = "false"
                        });
                    }
                }
                catch (Exception e)
                {
                    _logger.LogWarning(e, e.Message);
                }
            }
        }
Ejemplo n.º 18
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);
                }
            }
        }
Ejemplo n.º 19
0
        public async Task Handle(LineupReady notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Handling new lineups");
            var lineups    = notification.Lineups;
            var slackTeams = await _slackTeamRepo.GetAllTeams();

            var firstMessage    = $"*Lineups {lineups.HomeTeamNameAbbr}-{lineups.AwayTeamNameAbbr} ready* 👇";
            var formattedLineup = Formatter.FormatLineup(lineups);

            foreach (var slackTeam in slackTeams)
            {
                if (slackTeam.Subscriptions.ContainsSubscriptionFor(EventSubscription.Lineups))
                {
                    await PublishLineupToTeam(slackTeam);
                }
            }

            async Task PublishLineupToTeam(SlackTeam team)
            {
                var slackClient = _builder.Build(team.AccessToken);

                try
                {
                    var res = await slackClient.ChatPostMessage(team.FplBotSlackChannel, firstMessage);

                    if (res.Ok)
                    {
                        await slackClient.ChatPostMessage(new ChatPostMessageRequest
                        {
                            Channel = team.FplBotSlackChannel, thread_ts = res.ts, Text = formattedLineup, unfurl_links = "false"
                        });
                    }
                }
                catch (Exception e)
                {
                    _logger.LogWarning(e, e.Message);
                }
            }
        }
Ejemplo n.º 20
0
        public async Task Handle(InjuryUpdateOccured notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Handling player {notification.PlayersWithInjuryUpdates.Count()} status updates");
            var slackTeams = await _slackTeamRepo.GetAllTeams();

            foreach (var slackTeam in slackTeams)
            {
                if (slackTeam.Subscriptions.ContainsSubscriptionFor(EventSubscription.InjuryUpdates))
                {
                    var filtered = notification.PlayersWithInjuryUpdates.Where(c => c.ToPlayer.IsRelevant());
                    if (filtered.Any())
                    {
                        var formatted = Formatter.FormatInjuryStatusUpdates(filtered);
                        await _publisher.PublishToWorkspace(slackTeam.TeamId, slackTeam.FplBotSlackChannel, formatted);
                    }
                    else
                    {
                        _logger.LogInformation("All updates injuries irrelevant, so not sending any notification");
                    }
                }
            }
        }
Ejemplo n.º 21
0
        public async Task Handle(PriceChangeOccured notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Handling {notification.PlayerWithPriceChanges.Count()} price updates");
            var slackTeams = await _slackTeamRepo.GetAllTeams();

            foreach (var slackTeam in slackTeams)
            {
                if (slackTeam.Subscriptions.ContainsSubscriptionFor(EventSubscription.PriceChanges))
                {
                    var filtered = notification.PlayerWithPriceChanges.Where(c => c.ToPlayer.IsRelevant());
                    if (filtered.Any())
                    {
                        var formatted = Formatter.FormatPriceChanged(filtered);
                        await _publisher.PublishToWorkspace(slackTeam.TeamId, slackTeam.FplBotSlackChannel, formatted);
                    }
                    else
                    {
                        _logger.LogInformation("All price changes are all irrelevant, so not sending any notification");
                    }
                }
            }
        }