mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-09-02 14:19:05 +00:00
34 lines
1.3 KiB
Kotlin
34 lines
1.3 KiB
Kotlin
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDice
|
|
import dev.inmo.tgbotapi.extensions.utils.*
|
|
import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
|
|
import kotlinx.coroutines.*
|
|
|
|
/**
|
|
* Starts the long-polling slot-machine detector.
|
|
*
|
|
* [args] must contain the bot token first; later elements are ignored. Slot-machine
|
|
* dice receive a pipe-separated three-reel reply, while other dice receive an
|
|
* explanatory reply. An undecodable slot-machine result is silently ignored.
|
|
*/
|
|
suspend fun main(args: Array<String>) {
|
|
val bot = telegramBot(args.first())
|
|
|
|
bot.buildBehaviourWithLongPolling(scope = CoroutineScope(Dispatchers.IO)) {
|
|
onDice {
|
|
val content = it.content
|
|
val dice = content.dice
|
|
val diceType = dice.animationType
|
|
|
|
if (diceType == SlotMachineDiceAnimationType) {
|
|
val result = dice.calculateSlotMachineResult() ?: return@onDice
|
|
reply(it, "${result.leftReel}|${result.centerReel}|${result.rightReel}")
|
|
} else {
|
|
reply(it, "There is no slot machine dice in message")
|
|
}
|
|
}
|
|
}.join()
|
|
}
|