2020-01-17 20:45:05 -07:00
|
|
|
package lila.clas
|
|
|
|
|
2020-01-18 08:40:03 -07:00
|
|
|
import scala.concurrent.ExecutionContext
|
2020-01-17 20:45:05 -07:00
|
|
|
|
2021-03-05 01:55:21 -07:00
|
|
|
import lila.common.CuteNameGenerator
|
2020-01-17 20:45:05 -07:00
|
|
|
|
2021-03-06 04:58:13 -07:00
|
|
|
final class NameGenerator(userRepo: lila.user.UserRepo)(implicit ec: ExecutionContext) {
|
2021-03-05 01:55:21 -07:00
|
|
|
|
|
|
|
def apply(maxSize: Int = 17, triesLeft: Int = 20): Fu[Option[String]] = {
|
|
|
|
CuteNameGenerator.make(maxSize) ?? { name =>
|
|
|
|
userRepo.nameExists(name) flatMap {
|
|
|
|
case true if triesLeft > 0 => apply(maxSize, triesLeft - 1)
|
|
|
|
case true => fuccess(none)
|
|
|
|
case _ => fuccess(name.some)
|
|
|
|
}
|
2020-01-18 08:40:03 -07:00
|
|
|
}
|
2020-01-17 20:45:05 -07:00
|
|
|
}
|
|
|
|
}
|