2022-08-13 08:39:24 +00:00
|
|
|
import dev.inmo.micro_utils.coroutines.defaultSafelyWithoutExceptionHandler
|
|
|
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
|
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
|
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
2022-10-22 11:48:35 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.api.get.*
|
2022-08-13 08:39:24 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
|
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
|
|
|
import dev.inmo.tgbotapi.types.StickerType
|
|
|
|
import dev.inmo.tgbotapi.types.message.textsources.*
|
|
|
|
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
2022-09-19 08:37:01 +00:00
|
|
|
import dev.inmo.tgbotapi.utils.bold
|
|
|
|
import dev.inmo.tgbotapi.utils.buildEntities
|
2022-08-13 08:39:24 +00:00
|
|
|
import kotlinx.coroutines.*
|
|
|
|
|
2022-10-22 11:48:35 +00:00
|
|
|
fun StickerSet?.buildInfo() = buildEntities {
|
|
|
|
if (this@buildInfo == null) {
|
|
|
|
bold("Looks like this stickerset has been removed")
|
|
|
|
} else {
|
|
|
|
bold("StickerSet name: ") + "${name}\n"
|
|
|
|
bold("StickerSet title: ") + "${title}\n"
|
|
|
|
bold(
|
|
|
|
when (stickerType) {
|
|
|
|
StickerType.CustomEmoji -> "Custom emoji"
|
|
|
|
StickerType.Mask -> "Mask"
|
|
|
|
StickerType.Regular -> "Regular"
|
|
|
|
is StickerType.Unknown -> "Unknown type \"${stickerType.type}\""
|
|
|
|
}
|
|
|
|
) + " sticker set with title " + bold(title) + " and name " + bold(name)
|
|
|
|
}
|
2022-08-13 08:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
suspend fun activateStickerInfoBot(
|
|
|
|
token: String,
|
|
|
|
print: (Any) -> Unit
|
|
|
|
) {
|
|
|
|
val bot = telegramBot(token)
|
|
|
|
|
|
|
|
print(bot.getMe())
|
|
|
|
|
|
|
|
defaultSafelyWithoutExceptionHandler = {
|
|
|
|
it.printStackTrace()
|
|
|
|
}
|
|
|
|
|
|
|
|
bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
|
|
|
onText {
|
|
|
|
withTypingAction(it.chat) {
|
|
|
|
it.content.textSources.mapNotNull {
|
|
|
|
if (it is CustomEmojiTextSource) {
|
|
|
|
getCustomEmojiStickerOrNull(it.customEmojiId) ?.stickerSetName
|
|
|
|
} else {
|
|
|
|
null
|
|
|
|
}
|
|
|
|
}.distinct().map {
|
|
|
|
getStickerSet(it)
|
|
|
|
}.distinct().flatMap {
|
|
|
|
it.buildInfo() + regular("\n")
|
|
|
|
}.separateForText().map { entities ->
|
|
|
|
reply(it, entities)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onSticker {
|
2022-10-22 11:48:35 +00:00
|
|
|
val stickerSetInfo = getStickerSetOrNull(it.content.media)
|
2022-08-13 08:39:24 +00:00
|
|
|
reply(
|
|
|
|
it,
|
|
|
|
stickerSetInfo.buildInfo()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
|
|
|
println(it)
|
|
|
|
}
|
|
|
|
}.join()
|
|
|
|
}
|