public async Task <HandleResponse> Handle(SlackMessage message) { var allPlayersTask = _playerClient.GetAllPlayers(); var teamsTask = _teamsClient.GetAllTeams(); var name = ParsePlayerFromInput(message); var allPlayers = (await allPlayersTask).OrderByDescending(player => player.OwnershipPercentage); var mostPopularMatchingPlayer = FindMostPopularMatchingPlayer(allPlayers.ToArray(), name); var slackClient = await _slackClientService.CreateClient(message.Team.Id); if (mostPopularMatchingPlayer == null) { await slackClient.ChatPostMessage(new ChatPostMessageRequest { Channel = message.ChatHub.Id, Text = $"Couldn't find {name}" }); return(new HandleResponse($"Found no matching player for {name}: ")); } var playerName = $"{mostPopularMatchingPlayer.FirstName} {mostPopularMatchingPlayer.SecondName}"; var teams = await teamsTask; await slackClient.ChatPostMessage(new ChatPostMessageRequest { Channel = message.ChatHub.Id, Blocks = Formatter.GetPlayerCard(mostPopularMatchingPlayer, teams) }); return(new HandleResponse($"Found matching player for {name}: " + playerName)); }
public async Task <HandleResponse> Handle(SlackMessage message) { var slackClient = await _slackClientBuilder.CreateClient(message.Team.Id); var usersTask = slackClient.UsersList(); var gameweeksTask = _gameweekClient.GetGameweeks(); var teamsTask = _teamsclient.GetAllTeams(); var users = await usersTask; var gameweeks = await gameweeksTask; var teams = await teamsTask; var nextGw = gameweeks.First(gw => gw.IsNext); var fixtures = await _fixtureClient.GetFixturesByGameweek(nextGw.Id); var user = users.Members.FirstOrDefault(x => x.Id == message.User?.Id); var userTzOffset = user?.Tz_Offset ?? 0; var textToSend = TextToSend(nextGw, fixtures, teams, userTzOffset); foreach (var pBuilder in _publishers) { var p = await pBuilder.Build(message.Team.Id); await p.Publish(new Notification { Recipient = message.ChatHub.Id, Msg = textToSend }); } return(new HandleResponse(textToSend)); }