mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-06-18 20:36:49 +00:00
1.0.0 migration preview
This commit is contained in:
FilesLoaderBot/src/main/kotlin
ForwardInfoSenderBot/src/main/kotlin
GetMeBot/src/main/kotlin
HelloBot/src/main/kotlin
KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin
RandomFileSenderBot/src/main/kotlin
ResenderBot/ResenderBotLib/src/commonMain/kotlin
SlotMachineDetectorBot/src/main/kotlin
WebApp/src
gradle.properties@ -1,35 +1,26 @@
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
||||
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.extensions.utils.shortcuts.filterContentMessages
|
||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
|
||||
import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
|
||||
import dev.inmo.tgbotapi.types.message.content.DiceContent
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
suspend fun main(args: Array<String>) {
|
||||
val bot = telegramBot(args.first())
|
||||
|
||||
val scope = CoroutineScope(Dispatchers.Default)
|
||||
bot.longPolling(scope = scope) {
|
||||
filterContentMessages<DiceContent>(scope).onEach {
|
||||
bot.buildBehaviourWithLongPolling(scope = CoroutineScope(Dispatchers.IO)) {
|
||||
onDice {
|
||||
val content = it.content
|
||||
val dice = content.dice
|
||||
val diceType = dice.animationType
|
||||
|
||||
safely ({ it.printStackTrace() }) {
|
||||
if (diceType == SlotMachineDiceAnimationType) {
|
||||
val result = dice.calculateSlotMachineResult() ?: return@safely
|
||||
bot.reply(it, "${result.leftReel}|${result.centerReel}|${result.rightReel}")
|
||||
} else {
|
||||
bot.reply(it, "There is no slot machine dice in message")
|
||||
}
|
||||
if (diceType == SlotMachineDiceAnimationType) {
|
||||
val result = dice.calculateSlotMachineResult() ?: return@onDice
|
||||
bot.reply(it, "${result.leftReel}|${result.centerReel}|${result.rightReel}")
|
||||
} else {
|
||||
bot.reply(it, "There is no slot machine dice in message")
|
||||
}
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
scope.coroutineContext[Job]!!.join()
|
||||
}
|
||||
}
|
||||
}.join()
|
||||
}
|
||||
|
Reference in New Issue
Block a user