示例#1
0
        private void AnnounceCurrentGameWinner(SongGuessingRecord currentGuessingRecord, IChatbotContext context)
        {
            var potentialWinnerModels = context.SongPercentageGuesses
                                        .Where(g => g.SongGuessingRecord.SongGuessingRecordId == currentGuessingRecord.SongGuessingRecordId).ToList()
                                        .Select(pg =>
                                                (Math.Floor(Math.Abs(currentGuessingRecord.FinalPercentage - pg.Guess) * 10) / 10, pg)).ToList();

            // No-one guessed?
            if (!potentialWinnerModels.Any())
            {
                Client.SendMessage(string.IsNullOrEmpty(DevelopmentRoomId) ? _streamerChannel : DevelopmentRoomId, "Nobody guessed! Good luck next time :)");
            }

            var winners = GuessingGameWinner.Create(potentialWinnerModels);

            // TODO: URGENT -> Refactor this to own service when bytes service is brought over to library project.
            GiveBytes(winners.Where(w => w.Difference <= 20).ToList());

            Client.SendMessage(string.IsNullOrEmpty(DevelopmentRoomId) ? _streamerChannel : DevelopmentRoomId,
                               winners[0].Difference > 20 ?
                               $"@{string.Join(", @", winners.Select(w=> w.Username))} has won... nothing!" +
                               $" {string.Join(", ", winners.Select(w => $"{w.Username} guessed {w.Guess}%"))} " +
                               $"You were {winners[0].Difference} away from the actual score. Do you even know {_streamerChannel}?"
                    : winners[0].Difference == 0
                        ? $"@{string.Join(", @", winners.Select(w => w.Username))} has won! You guessed {winners[0].Guess}. You were spot on! You've received {winners[0].BytesWon} bytes"
                        : $"@{string.Join(", @", winners.Select(w => w.Username))} has won! " +
                               $"{string.Join(", ", winners.Select(w => $"{w.Username} guessed {w.Guess}% "))}" +
                               $"You were {winners[0].Difference} away from the actual score. You've received {winners[0].BytesWon} bytes");
        }
        public List <GuessingGameWinner> Get(int guessingGameRecordId, decimal finishedPercentage)
        {
            var guesses = _getSongPercentageGuessesRepository.Get(guessingGameRecordId);

            var potentialWinners = guesses
                                   .Select(pg =>
                                           (Math.Floor(Math.Abs(finishedPercentage - pg.Guess) * 10) / 10,
                                            pg)).ToList();

            return(GuessingGameWinner.Create(potentialWinners));
        }