TelegramBotAPI-examples/SlotMachineDetectorBot/src/main/kotlin/SlotMachineDetectorBot.kt

27 lines
1.0 KiB
Kotlin
Raw Permalink Normal View History

2022-05-10 18:23:14 +00:00
import dev.inmo.tgbotapi.bot.ktor.telegramBot
2020-11-02 16:35:05 +00:00
import dev.inmo.tgbotapi.extensions.api.send.reply
2022-05-10 18:23:14 +00:00
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDice
2020-11-02 16:35:05 +00:00
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
import kotlinx.coroutines.*
suspend fun main(args: Array<String>) {
val bot = telegramBot(args.first())
2022-05-10 18:23:14 +00:00
bot.buildBehaviourWithLongPolling(scope = CoroutineScope(Dispatchers.IO)) {
onDice {
2020-11-02 16:35:05 +00:00
val content = it.content
val dice = content.dice
val diceType = dice.animationType
2022-05-10 18:23:14 +00:00
if (diceType == SlotMachineDiceAnimationType) {
val result = dice.calculateSlotMachineResult() ?: return@onDice
2022-06-26 07:03:52 +00:00
reply(it, "${result.leftReel}|${result.centerReel}|${result.rightReel}")
2022-05-10 18:23:14 +00:00
} else {
2022-06-26 07:03:52 +00:00
reply(it, "There is no slot machine dice in message")
2020-11-02 16:35:05 +00:00
}
2022-05-10 18:23:14 +00:00
}
}.join()
}