コード例 #1
0
        private async Task AskRoleForInteractionTarget(ICity city, Role role, IReadOnlyCollection <IPerson> choosers)
        {
            var names = city.Population
                        .Where(p => p.IsAlive && !choosers.Contains(p))
                        .Select(p => p.Name).ToArray();

            await AddCityVoting(city.Name);

            var messageText = CreateMessageText("<b>Who will be your target?</b>\n\n", city.Name, names);

            var cityVotingPool = cityVotingPools[city.Name];

            foreach (var userId in choosers.Select(person => personToChat[person]))
            {
                cityVotingPool.AddChatId(userId);
                cityVotingPool.AddRole(userId, role);
            }

            var roleVoting = new RoleVotingPool(names);

            cityVotingPool.AddRoleVoting(role, roleVoting);

            if (names.Length == 1)
            {
                // bot.SendTextMessageAsync(chatId, $"{role.Name} automatically chosen {targets[0]}").Wait();
                roleVoting.Vote(0, 0); // illegal move
                return;
            }

            await Task.WhenAll(choosers.Select(person => bot.SendTextMessageAsync(personToChat[person], messageText, ParseMode.Html)));
        }