add request command

This commit is contained in:
2022-09-09 16:19:14 +06:00
parent e764358929
commit 296be3a4e3
2 changed files with 36 additions and 15 deletions

View File

@@ -8,11 +8,7 @@ import dev.inmo.micro_utils.repos.set
import dev.inmo.tgbotapi.types.ChatId
import kotlinx.coroutines.CoroutineScope
class EnableArgsParser(
private val chatId: ChatId,
private val repo: KeyValueRepo<ChatId, ChatSettings>,
private val scope: CoroutineScope
) : CliktCommand(name = "enable") {
class EnableArgsParser: CliktCommand(name = "enable") {
val count by option("-n").int().help("Amount of pictures to grab each trigger time").default(1).check("Count should be in range 1-10") {
it in 1 .. 10
}
@@ -25,16 +21,16 @@ class EnableArgsParser(
}.required().help("Board type. Possible values: ${ChatSettings.BoardSerializer.types.keys.joinToString { it }}")
val gallery by option("-g", "--gallery").flag(default = false).help("Effective only when count passed > 1. Will send chosen images as gallery instead of separated images")
var resultSettings: ChatSettings? = null
private set
override fun run() {
val chatSettings = ChatSettings(
resultSettings = ChatSettings(
query.filterNot { it.isEmpty() }.joinToString(" ").trim(),
krontab,
board,
count,
gallery
)
scope.launchSafelyWithoutExceptions {
repo.set(chatId, chatSettings)
}
}
}