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) val settings = settings ?: repo.get(chatId)
chatsChangingMutex.withLock { chatsChangingMutex.withLock {
chatsSendingJobs[chatId] ?.cancel() chatsSendingJobs[chatId] ?.cancel()
settings ?.let { settings ?.scheduler ?.let {
chatsSendingJobs[chatId] = settings.scheduler.asFlow().subscribeSafelyWithoutExceptions(scope) { chatsSendingJobs[chatId] = it.asFlow().subscribeSafelyWithoutExceptions(scope) {
triggerSendForChat(chatId, settings) triggerSendForChat(chatId, settings)
} }
} }
@ -174,9 +174,9 @@ suspend fun main(args: Array<String>) {
} }
} }
onCommand("request", requireOnlyCommandInMessage = false) { 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 { repo.get(it.chat.id) ?: run {
if (it.chat is PrivateChat) { if (it.chat is PrivateChat) {
reply(it, "Unable to find default config") reply(it, "Unable to find default config")

View File

@ -14,14 +14,14 @@ import net.kodehawa.lib.imageboards.entities.BoardImage
@Serializable @Serializable
data class ChatSettings( data class ChatSettings(
val query: String, val query: String,
val krontabTemplate: KrontabTemplate, val krontabTemplate: KrontabTemplate?,
@Serializable(BoardSerializer::class) @Serializable(BoardSerializer::class)
private val boardBase: DefaultBoards, private val boardBase: DefaultBoards,
val count: Int = 1, val count: Int = 1,
val gallery: Boolean = false val gallery: Boolean = false
) { ) {
val scheduler by lazy { val scheduler by lazy {
krontabTemplate.toSchedule() krontabTemplate ?.toSchedule()
} }
val board: ImageBoard<*> 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 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) { val krontab by option("-k", "--krontab").transformValues(5) {
it.joinToString(" ") 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 { val board by option("-b", "--board").convert {
ChatSettings.BoardSerializer.types.getValue(it) ChatSettings.BoardSerializer.types.getValue(it)
}.required().help("Board type. Possible values: ${ChatSettings.BoardSerializer.types.keys.joinToString { it }}") }.required().help("Board type. Possible values: ${ChatSettings.BoardSerializer.types.keys.joinToString { it }}")