Example #1
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);
            }
        }
    }
Example #2
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);
            }
        }
    }