mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-24 19:18:49 +00:00
Compare commits
No commits in common. "222134836a3e03e492b43b40f6075ca24d6a318a" and "a3e3f6c22cf9df7adecc9704b4d96eed8eb4456d" have entirely different histories.
222134836a
...
a3e3f6c22c
@ -26,9 +26,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
val contentMessage = waitContentMessage().first()
|
val content = waitContentMessage().first()
|
||||||
val content = contentMessage.content
|
|
||||||
|
|
||||||
when {
|
when {
|
||||||
content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context)
|
content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context)
|
||||||
else -> {
|
else -> {
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
jvm()
|
|
||||||
js(IR) {
|
|
||||||
browser()
|
|
||||||
binaries.executable()
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
implementation kotlin('stdlib')
|
|
||||||
|
|
||||||
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilterExcludeMediaGroups
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
|
|
||||||
private const val nextPageData = "next"
|
|
||||||
private const val previousPageData = "previous"
|
|
||||||
|
|
||||||
fun String.parsePageAndCount(): Pair<Int, Int>? {
|
|
||||||
val (pageString, countString) = split(" ").takeIf { it.count() > 1 } ?: return null
|
|
||||||
return Pair(
|
|
||||||
pageString.toIntOrNull() ?: return null,
|
|
||||||
countString.toIntOrNull() ?: return null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun InlineKeyboardBuilder.includePageButtons(page: Int, count: Int) {
|
|
||||||
val numericButtons = listOfNotNull(
|
|
||||||
page - 1,
|
|
||||||
page,
|
|
||||||
page + 1,
|
|
||||||
)
|
|
||||||
row {
|
|
||||||
val numbersRange = 1 .. count
|
|
||||||
numericButtons.forEach {
|
|
||||||
if (it in numbersRange) {
|
|
||||||
dataButton(it.toString(), "$it $count")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
row {
|
|
||||||
if (page - 1 > 2) {
|
|
||||||
dataButton("<<", "1 $count")
|
|
||||||
}
|
|
||||||
if (page - 1 > 1) {
|
|
||||||
dataButton("<", "${page - 2} $count")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (page + 1 < count) {
|
|
||||||
dataButton(">", "${page + 2} $count")
|
|
||||||
}
|
|
||||||
if (page + 2 < count) {
|
|
||||||
dataButton(">>", "$count $count")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun activateKeyboardsBot(
|
|
||||||
token: String,
|
|
||||||
print: (Any) -> Unit
|
|
||||||
) {
|
|
||||||
val bot = telegramBot(token)
|
|
||||||
|
|
||||||
print(bot.getMe())
|
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
|
||||||
onCommandWithArgs("inline") { message, args ->
|
|
||||||
val numberOfPages = args.firstOrNull() ?.toIntOrNull() ?: 10
|
|
||||||
reply(
|
|
||||||
message,
|
|
||||||
"Your inline keyboard with $numberOfPages pages",
|
|
||||||
replyMarkup = inlineKeyboard {
|
|
||||||
row {
|
|
||||||
includePageButtons(1, numberOfPages)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
onMessageDataCallbackQuery {
|
|
||||||
val (page, count) = it.data.parsePageAndCount() ?: it.let {
|
|
||||||
answer(it, "Unsupported data :(")
|
|
||||||
return@onMessageDataCallbackQuery
|
|
||||||
}
|
|
||||||
|
|
||||||
editMessageText(
|
|
||||||
it.message.withContent<TextContent>() ?: it.let {
|
|
||||||
answer(it, "Unsupported message type :(")
|
|
||||||
return@onMessageDataCallbackQuery
|
|
||||||
},
|
|
||||||
"This is $page of $count",
|
|
||||||
replyMarkup = inlineKeyboard {
|
|
||||||
row {
|
|
||||||
includePageButtons(page, count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
}.join()
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
import kotlinx.browser.document
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import org.w3c.dom.*
|
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.Default)
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
document.addEventListener(
|
|
||||||
"DOMContentLoaded",
|
|
||||||
{
|
|
||||||
val botsContainer = document.getElementById("bots_container") ?: return@addEventListener
|
|
||||||
|
|
||||||
(document.getElementById("bot_token_form") as? HTMLFormElement) ?.onsubmit = {
|
|
||||||
(document.getElementById("bot_token") as? HTMLInputElement) ?.value ?.let { token ->
|
|
||||||
val botContainer = document.createElement("div") as HTMLDivElement
|
|
||||||
botsContainer.append(botContainer)
|
|
||||||
|
|
||||||
val infoDiv = document.createElement("div") as HTMLDivElement
|
|
||||||
botContainer.append(infoDiv)
|
|
||||||
|
|
||||||
scope.launch {
|
|
||||||
activateKeyboardsBot(token) {
|
|
||||||
infoDiv.innerHTML = it.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Keyboards bot</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<form id="bot_token_form">
|
|
||||||
<input type="text" id="bot_token">
|
|
||||||
<input type="submit" value="Start bot">
|
|
||||||
</form>
|
|
||||||
<div id="start_offer">Type your bot token to the input above to start its work</div>
|
|
||||||
<script type="text/javascript" src="KeyboardsBotLib.js"></script>
|
|
||||||
<div id="bots_container"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,21 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
|
||||||
apply plugin: 'application'
|
|
||||||
|
|
||||||
mainClassName="KeyboardsBotJvmKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation project(":KeyboardsBot:KeyboardsBotLib")
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
withContext(Dispatchers.IO) { // IO for inheriting of it in side of activateKeyboardsBot
|
|
||||||
activateKeyboardsBot(args.first()) {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,5 +3,5 @@ org.gradle.parallel=true
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=1.6.10
|
kotlin_version=1.6.10
|
||||||
telegram_bot_api_version=0.38.13
|
telegram_bot_api_version=0.38.11
|
||||||
micro_utils_version=0.9.20
|
micro_utils_version=0.9.17
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
|
||||||
|
@ -1,19 +1,9 @@
|
|||||||
include ":ForwardInfoSenderBot"
|
include ":ForwardInfoSenderBot"
|
||||||
|
|
||||||
include ":RandomFileSenderBot"
|
include ":RandomFileSenderBot"
|
||||||
|
|
||||||
include ":HelloBot"
|
include ":HelloBot"
|
||||||
|
|
||||||
include ":GetMeBot"
|
include ":GetMeBot"
|
||||||
|
|
||||||
include ":FilesLoaderBot"
|
include ":FilesLoaderBot"
|
||||||
|
|
||||||
include ":ResenderBot:ResenderBotLib"
|
include ":ResenderBot:ResenderBotLib"
|
||||||
include ":ResenderBot:jvm_launcher"
|
include ":ResenderBot:jvm_launcher"
|
||||||
|
|
||||||
include ":KeyboardsBot:KeyboardsBotLib"
|
|
||||||
include ":KeyboardsBot:jvm_launcher"
|
|
||||||
|
|
||||||
include ":SlotMachineDetectorBot"
|
include ":SlotMachineDetectorBot"
|
||||||
|
|
||||||
include ":FSMBot"
|
include ":FSMBot"
|
||||||
|
Loading…
Reference in New Issue
Block a user