Ejemplo n.º 1
0
        public override async Task <EventHandledResponse> Handle(EventMetaData eventMetadata, AppMentionEvent incomingMessage)
        {
            var isChartRequest = incomingMessage.Text.Contains("chart");

            var gwPattern = $"{Commands.First()} {{gw}}";

            if (isChartRequest)
            {
                gwPattern = $"{Commands.First()} chart {{gw}}|{Commands.First()} {{gw}} chart";
            }
            var gameWeek = await _gameweekHelper.ExtractGameweekOrFallbackToCurrent(incomingMessage.Text, gwPattern);

            if (!gameWeek.HasValue)
            {
                await _workspacePublisher.PublishToWorkspace(eventMetadata.Team_Id, incomingMessage.Channel, "Invalid gameweek :grimacing:");

                return(new EventHandledResponse("Invalid gameweek"));
            }

            var setup = await _slackTeamsRepo.GetTeam(eventMetadata.Team_Id);

            var outgoingMessage = isChartRequest ?
                                  await _captainsByGameWeek.GetCaptainsChartByGameWeek(gameWeek.Value, (int)setup.FplbotLeagueId) :
                                  await _captainsByGameWeek.GetCaptainsByGameWeek(gameWeek.Value, (int)setup.FplbotLeagueId);

            await _workspacePublisher.PublishToWorkspace(eventMetadata.Team_Id, incomingMessage.Channel, outgoingMessage);

            return(new EventHandledResponse(outgoingMessage));
        }
Ejemplo n.º 2
0
    public override async Task <EventHandledResponse> Handle(EventMetaData eventMetadata, AppMentionEvent message)
    {
        var gameweek = await _gameweekHelper.ExtractGameweekOrFallbackToCurrent(message.Text, $"{CommandsFormatted} {{gw}}");


        var team = await _slackTeamRepo.GetTeam(eventMetadata.Team_Id);

        var messageToSend = "You don't follow any league yet. Use the `@fplbot follow` command first.";

        if (team.FplbotLeagueId.HasValue)
        {
            try
            {
                messageToSend =
                    await _transfersClient.GetTransfersByGameweekTexts(gameweek ?? 1, team.FplbotLeagueId.Value);
            }
            catch (HttpRequestException e) when(e.Message.Contains("429"))
            {
                messageToSend = "It seems fetching transfers was a bit heavy for this league. Try again later. ­ЪциРђЇ№ИЈ";
            }
        }

        await _workSpacePublisher.PublishToWorkspace(eventMetadata.Team_Id, message.Channel, messageToSend);

        return(new EventHandledResponse(messageToSend));
    }
Ejemplo n.º 3
0
        public override async Task <EventHandledResponse> Handle(EventMetaData eventMetadata, AppMentionEvent message)
        {
            var gameweek = await _gameweekHelper.ExtractGameweekOrFallbackToCurrent(message.Text, $"{CommandsFormatted} {{gw}}");


            var team = await _slackTeamRepo.GetTeam(eventMetadata.Team_Id);

            var messageToSend = await _transfersClient.GetTransfersByGameweekTexts(gameweek ?? 1, (int)team.FplbotLeagueId);


            await _workSpacePublisher.PublishToWorkspace(eventMetadata.Team_Id, message.Channel, messageToSend);

            return(new EventHandledResponse(messageToSend));
        }
Ejemplo n.º 4
0
        public async Task <HandleResponse> Handle(SlackMessage message)
        {
            var gameweek = await _gameweekHelper.ExtractGameweekOrFallbackToCurrent(new MessageHelper(message.Bot), message.Text, "transfers {gw}");

            var messageToSend = await _transfersClient.GetTransfersByGameweekTexts(gameweek);

            foreach (var pBuilder in _publishers)
            {
                var p = await pBuilder.Build(message.Team.Id);

                await p.Publish(new Notification
                {
                    Recipient = message.ChatHub.Id,
                    Msg       = messageToSend
                });
            }

            return(new HandleResponse(messageToSend));
        }
Ejemplo n.º 5
0
        public async Task <HandleResponse> Handle(SlackMessage message)
        {
            var gameWeek = await _gameweekHelper.ExtractGameweekOrFallbackToCurrent(new MessageHelper(message.Bot), message.Text, "captains {gw}");

            var messageToSend = gameWeek.HasValue ? await _captainsByGameWeek.GetCaptainsByGameWeek(gameWeek.Value) : "Invalid gameweek :grimacing:";

            foreach (var pBuilder in _publishers)
            {
                var p = await pBuilder.Build(message.Team.Id);

                await p.Publish(new Notification
                {
                    Recipient = message.ChatHub.Id,
                    Msg       = messageToSend
                });
            }

            return(new HandleResponse(messageToSend));
        }