made krontab in settings optional

This commit is contained in:
InsanusMokrassar 2022-09-09 16:28:14 +06:00
parent 732d2a182f
commit 42567b72f4
3 changed files with 7 additions and 7 deletions

View File

@ -127,8 +127,8 @@ suspend fun main(args: Array<String>) {
val settings = settings ?: repo.get(chatId)
chatsChangingMutex.withLock {
chatsSendingJobs[chatId] ?.cancel()
settings ?.let {
chatsSendingJobs[chatId] = settings.scheduler.asFlow().subscribeSafelyWithoutExceptions(scope) {
settings ?.scheduler ?.let {
chatsSendingJobs[chatId] = it.asFlow().subscribeSafelyWithoutExceptions(scope) {
triggerSendForChat(chatId, settings)
}
}
@ -174,9 +174,9 @@ suspend fun main(args: Array<String>) {
}
}
onCommand("request", requireOnlyCommandInMessage = false) {
val args = it.content.textSources.drop(1).joinToString("") { it.source }.split(" ")
val args = it.content.textSources.drop(1).joinToString("") { it.source }.trim().takeIf { it.isNotBlank() } ?.split(" ")
val chatSettings = if (args.isEmpty()) {
val chatSettings = if (args.isNullOrEmpty()) {
repo.get(it.chat.id) ?: run {
if (it.chat is PrivateChat) {
reply(it, "Unable to find default config")

View File

@ -14,14 +14,14 @@ import net.kodehawa.lib.imageboards.entities.BoardImage
@Serializable
data class ChatSettings(
val query: String,
val krontabTemplate: KrontabTemplate,
val krontabTemplate: KrontabTemplate?,
@Serializable(BoardSerializer::class)
private val boardBase: DefaultBoards,
val count: Int = 1,
val gallery: Boolean = false
) {
val scheduler by lazy {
krontabTemplate.toSchedule()
krontabTemplate ?.toSchedule()
}
val board: ImageBoard<*>

View File

@ -15,7 +15,7 @@ class EnableArgsParser: CliktCommand(name = "enable") {
val query by argument().multiple(required = true).help("Your query to booru. Use syntax \"-- -sometag\" to add excluding of some tag in query")
val krontab by option("-k", "--krontab").transformValues(5) {
it.joinToString(" ")
}.required().help("Krontab in format * * * * *. See https://bookstack.inmo.dev/books/krontab/page/string-format")
}.help("Krontab in format * * * * *. See https://bookstack.inmo.dev/books/krontab/page/string-format")
val board by option("-b", "--board").convert {
ChatSettings.BoardSerializer.types.getValue(it)
}.required().help("Board type. Possible values: ${ChatSettings.BoardSerializer.types.keys.joinToString { it }}")