Example #1
0
    public async Task Handle(InjuryUpdateOccured message, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Handling {message.PlayersWithInjuryUpdates.Count()} injury updates");
        var filtered = message.PlayersWithInjuryUpdates.Where(c => c.Player.IsRelevant());

        if (filtered.Any())
        {
            var formatted = Formatter.FormatInjuryStatusUpdates(filtered);
            var guildSubs = await _repo.GetAllGuildSubscriptions();

            foreach (var guildSub in guildSubs)
            {
                if (guildSub.Subscriptions.ContainsSubscriptionFor(EventSubscription.InjuryUpdates))
                {
                    var options = new SendOptions();
                    options.RequireImmediateDispatch();
                    options.RouteToThisEndpoint();
                    await context.Send(new PublishRichToGuildChannel(guildSub.GuildId, guildSub.ChannelId, "ℹ️ Injury update", formatted), options);
                }
            }
        }
        else
        {
            _logger.LogInformation("All updates injuries irrelevant, so not sending any notification");
        }
    }
Example #2
0
    public async Task Handle(OneHourToDeadline message, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Notifying about 60 minutes to (gw{message.GameweekNearingDeadline.Id}) deadline");
        var allGuilds = await _teamRepo.GetAllGuildSubscriptions();

        var text = $"@here ⏳Gameweek {message.GameweekNearingDeadline.Id} deadline in 60 minutes!";

        foreach (var guild in allGuilds)
        {
            if (guild.Subscriptions.ContainsSubscriptionFor(EventSubscription.Deadlines))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishRichToGuildChannel(guild.GuildId, guild.ChannelId, "ℹ️ Deadline", text), options);
            }
        }
    }
Example #3
0
    public async Task Handle(GameweekJustBegan notification, IMessageHandlerContext context)
    {
        var subs = await _repo.GetAllGuildSubscriptions();

        foreach (var team in subs)
        {
            var options = new SendOptions();
            options.RequireImmediateDispatch();
            options.RouteToThisEndpoint();
            await context.Send(new ProcessGameweekStartedForGuildChannel(team.GuildId, team.ChannelId, notification.NewGameweek.Id), options);
        }
    }
Example #4
0
    public async Task OnGet()
    {
        var guilds = await _repo.GetAllGuilds();

        GuildsWithSubs = new List <GuildWithSubs>();
        var allsubs = await _repo.GetAllGuildSubscriptions();

        foreach (var guild in guilds)
        {
            var subs = allsubs.Where(s => s.GuildId == guild.Id);
            GuildsWithSubs.Add(new GuildWithSubs(guild, subs));
        }
    }
Example #5
0
    public async Task Handle(GameweekFinished message, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Gameweek {message.FinishedGameweek.Id} finished");
        var allSubs = await _repo.GetAllGuildSubscriptions();

        foreach (var sub in allSubs)
        {
            var options = new SendOptions();
            options.RequireImmediateDispatch();
            options.RouteToThisEndpoint();
            await context.Send(new PublishGameweekFinishedToGuild(sub.GuildId, sub.ChannelId, sub.LeagueId, message.FinishedGameweek.Id), options);
        }
    }
Example #6
0
    public async Task Handle(FixtureEventsOccured message, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Handling {message.FixtureEvents.Count} new fixture events");
        var subs = await _repo.GetAllGuildSubscriptions();

        foreach (var sub in subs)
        {
            var options = new SendOptions();
            options.RequireImmediateDispatch();
            options.RouteToThisEndpoint();
            await context.Send(new PublishFixtureEventsToGuild(sub.GuildId, sub.ChannelId, message.FixtureEvents), options);
        }
    }
Example #7
0
    public async Task Handle(NewPlayersRegistered message, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Handling {message.NewPlayers.Count()} new players");
        var guildSubs = await _repo.GetAllGuildSubscriptions();

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

        foreach (var guildSub in guildSubs)
        {
            if (guildSub.Subscriptions.ContainsSubscriptionFor(EventSubscription.NewPlayers) && !string.IsNullOrEmpty(formatted))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishRichToGuildChannel(guildSub.GuildId, guildSub.ChannelId, "ℹ️ New players", formatted), options);
            }
        }
    }
Example #8
0
    public async Task Handle(LineupReady message, IMessageHandlerContext context)
    {
        var subs = await _guildRepository.GetAllGuildSubscriptions();

        var lineups         = message.Lineup;
        var firstMessage    = $"*Lineups {lineups.HomeTeamLineup.TeamName}-{lineups.AwayTeamLineup.TeamName} ready* ";
        var formattedLineup = Formatter.FormatLineup(lineups);

        foreach (var sub in subs)
        {
            if (sub.Subscriptions.ContainsSubscriptionFor(EventSubscription.Lineups))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishRichToGuildChannel(sub.GuildId, sub.ChannelId, $"ℹ️ {firstMessage}", $"{formattedLineup}"), options);
            }
        }
    }
Example #9
0
    public async Task Handle(FixtureRemovedFromGameweek message, IMessageHandlerContext context)
    {
        _logger.LogInformation("Fixture removed from gameweek {Message}", message);
        var subs = await _guildRepo.GetAllGuildSubscriptions();

        foreach (var sub in subs)
        {
            if (sub.Subscriptions.ContainsSubscriptionFor(EventSubscription.FixtureRemovedFromGameweek))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                var formattedMsg = new PublishRichToGuildChannel(sub.GuildId,
                                                                 sub.ChannelId,
                                                                 $"❌ Fixture off!",
                                                                 $"{message.RemovedFixture.Home.Name}-{message.RemovedFixture.Away.Name}" +
                                                                 $" has been removed from gameweek {message.Gameweek}!");
                await context.Send(formattedMsg, options);
            }
        }
    }
Example #10
0
    public async Task Handle(PlayersPriceChanged notification, IMessageHandlerContext context)
    {
        _logger.LogInformation($"Handling {notification.PlayersWithPriceChanges.Count()} price updates");
        var guildSubs = await _repo.GetAllGuildSubscriptions();

        var filtered = notification.PlayersWithPriceChanges.Where(c => c.IsRelevant());

        if (filtered.Any())
        {
            var formatted = Formatter.FormatPriceChanged(filtered);

            foreach (var guildSub in guildSubs)
            {
                if (guildSub.Subscriptions.ContainsSubscriptionFor(EventSubscription.PriceChanges) && !string.IsNullOrEmpty(formatted))
                {
                    var options = new SendOptions();
                    options.RequireImmediateDispatch();
                    options.RouteToThisEndpoint();
                    await context.Send(new PublishRichToGuildChannel(guildSub.GuildId, guildSub.ChannelId, "ℹ️ Price changes", formatted), options);
                }
            }
        }
    }
Example #11
0
    public async Task Handle(FixtureFinished message, IMessageHandlerContext context)
    {
        var subs = await _teamRepo.GetAllGuildSubscriptions();

        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 sub in subs)
        {
            if (sub.Subscriptions.ContainsSubscriptionFor(EventSubscription.FixtureFullTime))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                await context.Send(new PublishRichToGuildChannel(sub.GuildId, sub.ChannelId, $"ℹ️ {title}", $"{threadMessage}"), options);
            }
        }
    }