mirror of
https://github.com/InsanusMokrassar/BooruGrabberTelegramBot.git
synced 2024-11-25 17:28:44 +00:00
add rating and attach urls options
This commit is contained in:
parent
42567b72f4
commit
034f5fb7ca
@ -101,20 +101,22 @@ suspend fun main(args: Array<String>) {
|
|||||||
urls.isEmpty() -> return@runCatchingSafely
|
urls.isEmpty() -> return@runCatchingSafely
|
||||||
urls.size == 1 -> sendPhoto(
|
urls.size == 1 -> sendPhoto(
|
||||||
chatId,
|
chatId,
|
||||||
FileUrl(urls.first())
|
FileUrl(urls.first()),
|
||||||
|
if (settings.attachUrls) urls.first() else null
|
||||||
)
|
)
|
||||||
settings.gallery -> urls.chunked(mediaCountInMediaGroup.last + 1).forEach {
|
settings.gallery -> urls.chunked(mediaCountInMediaGroup.last + 1).forEach {
|
||||||
sendVisualMediaGroup(
|
sendVisualMediaGroup(
|
||||||
chatId,
|
chatId,
|
||||||
it.map {
|
it.map {
|
||||||
TelegramMediaPhoto(FileUrl(it))
|
TelegramMediaPhoto(FileUrl(it), if (settings.attachUrls) it else null)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> urls.forEach {
|
else -> urls.forEach {
|
||||||
sendPhoto(
|
sendPhoto(
|
||||||
chatId,
|
chatId,
|
||||||
FileUrl(it)
|
FileUrl(it),
|
||||||
|
if (settings.attachUrls) it else null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import net.kodehawa.lib.imageboards.DefaultImageBoards
|
|||||||
import net.kodehawa.lib.imageboards.ImageBoard
|
import net.kodehawa.lib.imageboards.ImageBoard
|
||||||
import net.kodehawa.lib.imageboards.boards.DefaultBoards
|
import net.kodehawa.lib.imageboards.boards.DefaultBoards
|
||||||
import net.kodehawa.lib.imageboards.entities.BoardImage
|
import net.kodehawa.lib.imageboards.entities.BoardImage
|
||||||
|
import net.kodehawa.lib.imageboards.entities.Rating
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ChatSettings(
|
data class ChatSettings(
|
||||||
@ -18,7 +19,9 @@ data class ChatSettings(
|
|||||||
@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 rating: Rating? = null,
|
||||||
|
val attachUrls: Boolean = false
|
||||||
) {
|
) {
|
||||||
val scheduler by lazy {
|
val scheduler by lazy {
|
||||||
krontabTemplate ?.toSchedule()
|
krontabTemplate ?.toSchedule()
|
||||||
@ -38,7 +41,7 @@ data class ChatSettings(
|
|||||||
|
|
||||||
suspend fun makeRequest(page: Int): List<BoardImage> {
|
suspend fun makeRequest(page: Int): List<BoardImage> {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
board.search(page, count, query).blocking()
|
board.search(page, count, query, rating).blocking()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import com.github.ajalt.clikt.core.CliktCommand
|
import com.github.ajalt.clikt.core.CliktCommand
|
||||||
import com.github.ajalt.clikt.parameters.arguments.*
|
import com.github.ajalt.clikt.parameters.arguments.*
|
||||||
import com.github.ajalt.clikt.parameters.options.*
|
import com.github.ajalt.clikt.parameters.options.*
|
||||||
|
import com.github.ajalt.clikt.parameters.types.enum
|
||||||
import com.github.ajalt.clikt.parameters.types.int
|
import com.github.ajalt.clikt.parameters.types.int
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.repos.KeyValueRepo
|
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||||
import dev.inmo.micro_utils.repos.set
|
import dev.inmo.micro_utils.repos.set
|
||||||
import dev.inmo.tgbotapi.types.ChatId
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import net.kodehawa.lib.imageboards.entities.Rating
|
||||||
|
|
||||||
class EnableArgsParser: 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") {
|
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") {
|
||||||
@ -20,6 +22,8 @@ class EnableArgsParser: CliktCommand(name = "enable") {
|
|||||||
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 }}")
|
||||||
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")
|
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")
|
||||||
|
val rating by option("-r", "--rating").enum<Rating> { it.name.lowercase() }
|
||||||
|
val attachUrls by option("-a", "--attach_urls").flag(default = false)
|
||||||
|
|
||||||
var resultSettings: ChatSettings? = null
|
var resultSettings: ChatSettings? = null
|
||||||
private set
|
private set
|
||||||
@ -30,7 +34,9 @@ class EnableArgsParser: CliktCommand(name = "enable") {
|
|||||||
krontab,
|
krontab,
|
||||||
board,
|
board,
|
||||||
count,
|
count,
|
||||||
gallery
|
gallery,
|
||||||
|
rating,
|
||||||
|
attachUrls
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user