diff --git a/src/main/scala/lc/background/taskThread.scala b/src/main/scala/lc/background/taskThread.scala index 33ae997..2b5cd99 100644 --- a/src/main/scala/lc/background/taskThread.scala +++ b/src/main/scala/lc/background/taskThread.scala @@ -2,7 +2,7 @@ package lc.background import lc.database.Statements import java.util.concurrent.{ScheduledThreadPoolExecutor, TimeUnit} -import lc.core.Captcha +import lc.core.{Captcha, Config} import lc.core.{Parameters, Size} class BackgroundTask(throttle: Int, timeLimit: Int) { @@ -22,13 +22,21 @@ class BackgroundTask(throttle: Int, timeLimit: Int) { if (imageNum.next()) throttleIn = (throttleIn - imageNum.getInt("total")) while (0 < throttleIn) { - Captcha.generateChallenge(Parameters("medium", "image/png", "text", Option(Size(0, 0)))) + Captcha.generateChallenge(getRandomParam()) throttleIn -= 1 } } catch { case exception: Exception => println(exception) } } } + private def getRandomParam(): Parameters = { + val level = Config.allowedLevels.toList(Config.getNextRandomInt(Config.allowedLevels.size)) + val media = Config.allowedMedia.toList(Config.getNextRandomInt(Config.allowedMedia.size)) + val inputType = Config.allowedInputType.toList(Config.getNextRandomInt(Config.allowedInputType.size)) + + Parameters(level, media, inputType, Option(Size(0,0))) + } + def beginThread(delay: Int): Unit = { val ex = new ScheduledThreadPoolExecutor(1) ex.scheduleWithFixedDelay(task, 1, delay, TimeUnit.SECONDS)