some functionality of sticker set handler bot

This commit is contained in:
InsanusMokrassar 2023-03-11 15:55:09 +06:00
parent 7e7bbfaa93
commit 8ef50537ae
2 changed files with 48 additions and 1 deletions

View File

@ -1,3 +1,48 @@
import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.tgbotapi.extensions.api.bot.getMe
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
import dev.inmo.tgbotapi.extensions.api.get.getStickerSet
import dev.inmo.tgbotapi.extensions.api.stickers.createNewStickerSet
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onSticker
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
import dev.inmo.tgbotapi.requests.stickers.InputSticker
import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.toChatId
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
suspend fun main(args: Array<String>) { suspend fun main(args: Array<String>) {
build telegramBotWithBehaviourAndLongPolling(args.first(), scope = CoroutineScope(Dispatchers.IO)) {
val me = getMe()
onSticker {
val stickerSetName = "${it.chat.id}_by_${me.username.username}"
val sticker = it.content.media
runCatchingSafely {
getStickerSet(stickerSetName)
}.getOrElse { _ ->
createNewStickerSet(
it.chat.id.toChatId(),
stickerSetName,
"Sticker set by ${me.firstName}",
it.content.media.stickerFormat,
listOf(
when (sticker) {
is CustomEmojiSticker -> InputSticker.WithKeywords.CustomEmoji(
downloadFileToTemp(sticker.fileId).asMultipartFile(),
sticker.emoji ?.let(::listOf) ?: emptyList(),
emptyList()
)
is MaskSticker -> TODO()
is RegularSticker -> TODO()
is UnknownSticker -> TODO()
}
),
sticker
)
}
}
}
} }

View File

@ -34,3 +34,5 @@ include ":UserChatShared"
include ":RightsChangerBot" include ":RightsChangerBot"
include ":LiveLocationsBot" include ":LiveLocationsBot"
include ":StickerSetHandler"