mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-12-22 08:37:18 +00:00
update and add SlotMachineDetectorBot
This commit is contained in:
parent
3820e29bf2
commit
d49ce88a0b
9
SlotMachineDetectorBot/README.md
Normal file
9
SlotMachineDetectorBot/README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# SlotMachineDetectorBot
|
||||||
|
|
||||||
|
This bot must reply with information about slot machine answer
|
||||||
|
|
||||||
|
## Launch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../gradlew run --args="BOT_TOKEN"
|
||||||
|
```
|
24
SlotMachineDetectorBot/build.gradle
Normal file
24
SlotMachineDetectorBot/build.gradle
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin'
|
||||||
|
apply plugin: 'application'
|
||||||
|
|
||||||
|
mainClassName="SlotMachineDetectorBotKt"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.shortcuts.filterContentMessages
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling
|
||||||
|
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.startGettingFlowsUpdatesByLongPolling(scope = scope) {
|
||||||
|
filterContentMessages<DiceContent>(scope).onEach {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.launchIn(scope)
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.coroutineContext[Job]!!.join()
|
||||||
|
}
|
@ -2,4 +2,4 @@ kotlin.code.style=official
|
|||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
|
||||||
kotlin_version=1.4.10
|
kotlin_version=1.4.10
|
||||||
telegram_bot_api_version=0.29.3
|
telegram_bot_api_version=0.29.4
|
||||||
|
@ -5,3 +5,4 @@ include ":GetMeBot"
|
|||||||
include ":FilesLoaderBot"
|
include ":FilesLoaderBot"
|
||||||
include ":ResenderBot:ResenderBotLib"
|
include ":ResenderBot:ResenderBotLib"
|
||||||
include ":ResenderBot:jvm_launcher"
|
include ":ResenderBot:jvm_launcher"
|
||||||
|
include ":SlotMachineDetectorBot"
|
||||||
|
Loading…
Reference in New Issue
Block a user