mirror of
https://github.com/InsanusMokrassar/BooruGrabberTelegramBot.git
synced 2024-11-21 23:53:46 +00:00
improvements
This commit is contained in:
parent
2b7a21342b
commit
ea801e6e0d
@ -21,6 +21,7 @@ import dev.inmo.tgbotapi.types.*
|
|||||||
import dev.inmo.tgbotapi.types.chat.ChannelChat
|
import dev.inmo.tgbotapi.types.chat.ChannelChat
|
||||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto
|
import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto
|
||||||
|
import dev.inmo.tgbotapi.utils.code
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@ -28,7 +29,9 @@ import kotlinx.coroutines.sync.withLock
|
|||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import models.Config
|
import models.Config
|
||||||
import net.kodehawa.lib.imageboards.ImageBoard
|
import net.kodehawa.lib.imageboards.ImageBoard
|
||||||
|
import net.kodehawa.lib.imageboards.boards.DefaultBoards
|
||||||
import net.kodehawa.lib.imageboards.entities.BoardImage
|
import net.kodehawa.lib.imageboards.entities.BoardImage
|
||||||
|
import kotlin.reflect.full.memberProperties
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method by default expects one argument in [args] field: telegram bot configuration
|
* This method by default expects one argument in [args] field: telegram bot configuration
|
||||||
@ -208,6 +211,26 @@ suspend fun main(args: Array<String>) {
|
|||||||
delete(it)
|
delete(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onCommand("take_settings", requireOnlyCommandInMessage = true) {
|
||||||
|
val settings = runCatchingSafely {
|
||||||
|
repo.get(ChatId(it.chat.id.chatId))
|
||||||
|
}.getOrNull()
|
||||||
|
runCatchingSafely {
|
||||||
|
if (settings == null) {
|
||||||
|
reply(it, "You didn't enable requesting")
|
||||||
|
} else {
|
||||||
|
reply(it, ) {
|
||||||
|
+"Query: " + code(settings.query) + "\n"
|
||||||
|
+"Krontab: " + code(settings.krontabTemplate ?: "unset") + "\n"
|
||||||
|
+"Board: " + code(DefaultBoards.values().first { it == settings.board.boardType }.name) + "\n"
|
||||||
|
+"Count: " + code(settings.count.toString()) + "\n"
|
||||||
|
+"Gallery: " + code(settings.gallery.toString()) + "\n"
|
||||||
|
+"Rating: " + code(settings.rating ?.name ?: "unset") + "\n"
|
||||||
|
+"Attach urls: " + code(settings.attachUrls.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setMyCommands(
|
setMyCommands(
|
||||||
listOf(
|
listOf(
|
||||||
@ -216,6 +239,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
BotCommand("request", "Will trigger image immediately with custom settings from arguments or default settings of chat if any"),
|
BotCommand("request", "Will trigger image immediately with custom settings from arguments or default settings of chat if any"),
|
||||||
BotCommand("enable", "Will enable images grabbing for current chat or update exists settings"),
|
BotCommand("enable", "Will enable images grabbing for current chat or update exists settings"),
|
||||||
BotCommand("disable", "Will disable bot for current chat"),
|
BotCommand("disable", "Will disable bot for current chat"),
|
||||||
|
BotCommand("take_settings", "Take your current settings"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,14 +31,8 @@ class EnableArgsParser(
|
|||||||
.transformValues(5) { it.joinToString(" ") }
|
.transformValues(5) { it.joinToString(" ") }
|
||||||
.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")
|
val board by option("-b", "--board")
|
||||||
|
.default("safebooru")
|
||||||
.convert { ChatSettings.BoardSerializer.types.getValue(it) }
|
.convert { ChatSettings.BoardSerializer.types.getValue(it) }
|
||||||
.run {
|
|
||||||
if (onlyQueryIsRequired) {
|
|
||||||
this
|
|
||||||
} else {
|
|
||||||
required()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.help("Board type. Possible values: ${ChatSettings.BoardSerializer.types.keys.joinToString { it }}")
|
.help("Board type. Possible values: ${ChatSettings.BoardSerializer.types.keys.joinToString { it }}")
|
||||||
val gallery by option("-g", "--gallery")
|
val gallery by option("-g", "--gallery")
|
||||||
.flag(default = base.gallery)
|
.flag(default = base.gallery)
|
||||||
|
Loading…
Reference in New Issue
Block a user