mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-20 06:15:49 +00:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8593263506 | |||
| 4422a4d09b | |||
| 9ecb50e377 | |||
| 8a4b40c6ec | |||
| bba667db30 | |||
| ca0d256bbb | |||
| dc2fd07632 | |||
| 32fe008eef | |||
| 2b938903b6 | |||
| 080db09d2c | |||
| 0efa52fe00 | |||
| c4214798e3 | |||
| fdf510153d | |||
| edb16d7107 | |||
| c49f400201 | |||
| db7de6edf8 | |||
| a0b14233e0 | |||
| 1a479706e2 | |||
| 2719e166a8 | |||
| 051684db23 | |||
| 805cec76ce | |||
| 899c195fd5 | |||
| f5937fc4d6 | |||
| 8cf7b349df | |||
| bf8f8b9e6f | |||
| edc0b1c492 | |||
| a85d58aac1 | |||
| 10860e1bb2 | |||
| 826c27874d | |||
| 4e917e8cf8 | |||
| 96ffae2062 | |||
| 4180721aed | |||
| 4ab0845333 | |||
| 3f9a4e95a3 | |||
| 834d60ff16 | |||
| 650d96974f |
2
.github/workflows/kdocs.yml
vendored
2
.github/workflows/kdocs.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-java@v1
|
- uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 11
|
java-version: 17
|
||||||
- name: Build
|
- name: Build
|
||||||
run: ./gradlew dokkaHtmlMultiModule
|
run: ./gradlew dokkaHtmlMultiModule
|
||||||
- name: Publish KDocs
|
- name: Publish KDocs
|
||||||
|
|||||||
4
.github/workflows/packages_publishing.yml
vendored
4
.github/workflows/packages_publishing.yml
vendored
@@ -7,9 +7,9 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-java@v1
|
- uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 11
|
java-version: 17
|
||||||
- name: Setup LibCurl
|
- name: Setup LibCurl
|
||||||
run: sudo apt install -y libcurl4-openssl-dev
|
run: sudo apt update && sudo apt install -y libcurl4-openssl-dev
|
||||||
- name: Rewrite version
|
- name: Rewrite version
|
||||||
run: |
|
run: |
|
||||||
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
||||||
|
|||||||
31
CHANGELOG.md
31
CHANGELOG.md
@@ -1,5 +1,36 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 9.3.0
|
||||||
|
|
||||||
|
This release become possible thanks to [Anton Lakotka](https://youtrack.jetbrains.com/users/anton.lakotka)
|
||||||
|
|
||||||
|
**THIS RELEASE CONTAINS UPDATES UP TO RELEASE CANDIDATES VERSIONS**
|
||||||
|
|
||||||
|
**UPDATE MAY HAVE BREAKING CHANGES**
|
||||||
|
|
||||||
|
**SINCE THIS UPDATE IT WILL BE REQUIRED TO USE JDK 17+ FOR DEVELOPMENT**
|
||||||
|
|
||||||
|
* `Version`:
|
||||||
|
* `Kotlin`: `1.8.22` -> `1.9.20`
|
||||||
|
* `Serialization`: `1.5.1` -> `1.6.0`
|
||||||
|
* `KorLibs`: `4.0.3` -> `4.0.10`
|
||||||
|
* `UUID`: `0.7.1` -> `0.8.1`
|
||||||
|
* `Ktor`: `2.3.4` -> `2.3.5`
|
||||||
|
* `MicroUtils`: `0.19.9` -> `0.20.12`
|
||||||
|
|
||||||
|
## 9.2.4
|
||||||
|
|
||||||
|
* `Utils`:
|
||||||
|
* New extensions `*.parseCommandsWithNamedArgs`
|
||||||
|
* `BehaviourBuilder`:
|
||||||
|
* In expectaters and triggers of `commands` add `*WithNamedArgs` variants
|
||||||
|
* In expectaters and triggers of `commands` add opportunity to use custom separator
|
||||||
|
|
||||||
|
## 9.2.3
|
||||||
|
|
||||||
|
* `Core`:
|
||||||
|
* Fix in `VoiceContent#createResend`
|
||||||
|
|
||||||
## 9.2.2
|
## 9.2.2
|
||||||
|
|
||||||
* `Core`:
|
* `Core`:
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ Object callback = {
|
|||||||
|
|
||||||
sourceLink {
|
sourceLink {
|
||||||
localDirectory.set(file("../"))
|
localDirectory.set(file("../"))
|
||||||
remoteUrl.set(new URL("https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/"))
|
remoteUrl.set(new URL("https://github.com/InsanusMokrassar/ktgbotapi/tree/master"))
|
||||||
remoteLineSuffix.set("#L")
|
remoteLineSuffix.set("#L")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ kotlin.incremental=true
|
|||||||
kotlin.incremental.js=true
|
kotlin.incremental.js=true
|
||||||
|
|
||||||
library_group=dev.inmo
|
library_group=dev.inmo
|
||||||
library_version=9.2.2
|
library_version=9.3.0
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kotlin = "1.8.22"
|
kotlin = "1.9.20"
|
||||||
kotlin-serialization = "1.5.1"
|
kotlin-serialization = "1.6.0"
|
||||||
kotlin-coroutines = "1.7.3"
|
kotlin-coroutines = "1.7.3"
|
||||||
|
|
||||||
javax-activation = "1.1.1"
|
javax-activation = "1.1.1"
|
||||||
|
|
||||||
korlibs = "4.0.3"
|
korlibs = "4.0.10"
|
||||||
uuid = "0.7.1"
|
uuid = "0.8.1"
|
||||||
ktor = "2.3.4"
|
ktor = "2.3.5"
|
||||||
|
|
||||||
ksp = "1.8.22-1.0.11"
|
ksp = "1.9.20-1.0.14"
|
||||||
kotlin-poet = "1.14.2"
|
kotlin-poet = "1.14.2"
|
||||||
|
|
||||||
microutils = "0.19.9"
|
microutils = "0.20.12"
|
||||||
|
|
||||||
github-release-plugin = "2.4.1"
|
github-release-plugin = "2.4.1"
|
||||||
dokka = "1.8.20"
|
dokka = "1.9.10"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
|
|
||||||
|
|||||||
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.6.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ kotlin {
|
|||||||
jvm {
|
jvm {
|
||||||
compilations.main {
|
compilations.main {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = "1.8"
|
jvmTarget = "17"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
linuxX64()
|
linuxX64()
|
||||||
mingwX64()
|
mingwX64()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
@@ -40,10 +41,18 @@ kotlin {
|
|||||||
implementation libs.kotlin.test.junit
|
implementation libs.kotlin.test.junit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
all {
|
||||||
|
languageSettings {
|
||||||
|
optIn('dev.inmo.tgbotapi.utils.RiskFeature')
|
||||||
|
optIn('dev.inmo.tgbotapi.utils.PreviewFeature')
|
||||||
|
optIn('dev.inmo.micro_utils.common.Warning')
|
||||||
|
optIn('dev.inmo.micro_utils.common.PreviewFeature')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
|
|
||||||
task javadocsJar(type: Jar) {
|
task javadocsJar(type: Jar) {
|
||||||
archiveClassifier.convention("javadoc")
|
archiveClassifier = 'javadoc'
|
||||||
archiveClassifier.set("javadoc")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
@@ -20,22 +19,22 @@ publishing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
developers {
|
developers {
|
||||||
|
|
||||||
developer {
|
developer {
|
||||||
id = "InsanusMokrassar"
|
id = "InsanusMokrassar"
|
||||||
name = "Ovsiannikov Aleksei"
|
name = "Ovsiannikov Aleksei"
|
||||||
email = "ovsyannikov.alexey95@gmail.com"
|
email = "ovsyannikov.alexey95@gmail.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
licenses {
|
licenses {
|
||||||
|
|
||||||
license {
|
license {
|
||||||
name = "Apache Software License 2.0"
|
name = "Apache Software License 2.0"
|
||||||
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
|
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
@@ -43,58 +42,64 @@ publishing {
|
|||||||
maven {
|
maven {
|
||||||
name = "GithubPackages"
|
name = "GithubPackages"
|
||||||
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
|
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
|
||||||
|
|
||||||
credentials {
|
credentials {
|
||||||
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
|
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
|
||||||
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
|
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) {
|
if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) {
|
||||||
maven {
|
maven {
|
||||||
name = "Gitea"
|
name = "Gitea"
|
||||||
url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven")
|
url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven")
|
||||||
|
|
||||||
credentials(HttpHeaderCredentials) {
|
credentials(HttpHeaderCredentials) {
|
||||||
name = "Authorization"
|
name = "Authorization"
|
||||||
value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN')
|
value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN')
|
||||||
}
|
}
|
||||||
|
|
||||||
authentication {
|
authentication {
|
||||||
header(HttpHeaderAuthentication)
|
header(HttpHeaderAuthentication)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||||
maven {
|
maven {
|
||||||
name = "sonatype"
|
name = "sonatype"
|
||||||
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
||||||
|
|
||||||
credentials {
|
credentials {
|
||||||
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||||
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (project.hasProperty("signing.gnupg.keyName")) {
|
if (project.hasProperty("signing.gnupg.keyName")) {
|
||||||
apply plugin: 'signing'
|
apply plugin: 'signing'
|
||||||
|
|
||||||
signing {
|
signing {
|
||||||
useGpgCmd()
|
useGpgCmd()
|
||||||
|
|
||||||
sign publishing.publications
|
sign publishing.publications
|
||||||
}
|
}
|
||||||
|
|
||||||
task signAll {
|
task signAll {
|
||||||
tasks.withType(Sign).forEach {
|
tasks.withType(Sign).forEach {
|
||||||
dependsOn(it)
|
dependsOn(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Workaround to make android sign operations depend on signing tasks
|
||||||
|
project.getTasks().withType(AbstractPublishToMaven.class).configureEach {
|
||||||
|
def signingTasks = project.getTasks().withType(Sign.class)
|
||||||
|
mustRunAfter(signingTasks)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.handlers_registrar.doWithRegistration
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.handlers_registrar.doWithRegistration
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.TelegramBotCommandsDefaults
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgsSources
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithNamedArgs
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
@@ -79,35 +83,54 @@ fun Flow<CommonMessage<TextContent>>.requireCommandsWithoutParams() = filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the commands with their arguments and source messages
|
* Uses [parseCommandsWithArgsSources] on incoming text sources and map them with [CommonMessage]
|
||||||
*/
|
*/
|
||||||
fun Flow<CommonMessage<TextContent>>.commandsWithParams(): Flow<Pair<CommonMessage<TextContent>, List<Pair<BotCommandTextSource, Array<TextSource>>>>> = mapNotNull {
|
fun Flow<CommonMessage<TextContent>>.commandsWithParams(): Flow<Pair<CommonMessage<TextContent>, List<Pair<BotCommandTextSource, Array<TextSource>>>>> = mapNotNull {
|
||||||
var currentCommandTextSource: BotCommandTextSource? = null
|
it to it.content.textSources.parseCommandsWithArgsSources().toList()
|
||||||
val currentArgs = mutableListOf<TextSource>()
|
|
||||||
val result = mutableListOf<Pair<BotCommandTextSource, Array<TextSource>>>()
|
|
||||||
|
|
||||||
fun addCurrentCommandToResult() {
|
|
||||||
currentCommandTextSource ?.let {
|
|
||||||
result.add(it to currentArgs.toTypedArray())
|
|
||||||
currentArgs.clear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it.content.textSources.forEach {
|
|
||||||
it.ifBotCommandTextSource {
|
|
||||||
addCurrentCommandToResult()
|
|
||||||
currentCommandTextSource = it
|
|
||||||
return@forEach
|
|
||||||
}
|
|
||||||
currentArgs.add(it)
|
|
||||||
}
|
|
||||||
addCurrentCommandToResult()
|
|
||||||
|
|
||||||
result.toList().takeIf { it.isNotEmpty() } ?.let { result ->
|
|
||||||
it to result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithArgs] on incoming text sources and map them with [CommonMessage]
|
||||||
|
*/
|
||||||
|
fun Flow<CommonMessage<TextContent>>.commandsWithArgs(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex
|
||||||
|
): Flow<Pair<CommonMessage<TextContent>, List<Pair<String, Array<String>>>>> = mapNotNull {
|
||||||
|
val commandsWithArgs = it.content.textSources.parseCommandsWithArgs(argsSeparator).toList().ifEmpty {
|
||||||
|
return@mapNotNull null
|
||||||
|
}
|
||||||
|
|
||||||
|
it to commandsWithArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithArgs] on incoming text sources and map them with [CommonMessage]
|
||||||
|
*/
|
||||||
|
fun Flow<CommonMessage<TextContent>>.commandsWithArgs(
|
||||||
|
argsSeparator: String
|
||||||
|
): Flow<Pair<CommonMessage<TextContent>, List<Pair<String, Array<String>>>>> = commandsWithArgs(Regex(argsSeparator))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithNamedArgs] on incoming text sources and map them with [CommonMessage]
|
||||||
|
*/
|
||||||
|
fun Flow<CommonMessage<TextContent>>.commandsWithNamedArgs(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
): Flow<Pair<CommonMessage<TextContent>, List<Pair<String, List<Pair<String, String>>>>>> = mapNotNull {
|
||||||
|
val commandsWithArgs = it.content.textSources.parseCommandsWithNamedArgs(argsSeparator, nameArgSeparator).toList().ifEmpty {
|
||||||
|
return@mapNotNull null
|
||||||
|
}
|
||||||
|
|
||||||
|
it to commandsWithArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithNamedArgs] on incoming text sources and map them with [CommonMessage]
|
||||||
|
*/
|
||||||
|
fun Flow<CommonMessage<TextContent>>.commandsWithNamedArgs(
|
||||||
|
argsSeparator: String,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
): Flow<Pair<CommonMessage<TextContent>, List<Pair<String, List<Pair<String, String>>>>>> = commandsWithNamedArgs(Regex(argsSeparator), nameArgSeparator)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flat [commandsWithParams]. Each [Pair] of [BotCommandTextSource] and its [Array] of arg text sources will
|
* Flat [commandsWithParams]. Each [Pair] of [BotCommandTextSource] and its [Array] of arg text sources will
|
||||||
* be associated with its source message
|
* be associated with its source message
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByC
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||||
import dev.inmo.tgbotapi.extensions.utils.botCommandTextSourceOrNull
|
import dev.inmo.tgbotapi.extensions.utils.botCommandTextSourceOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
import dev.inmo.tgbotapi.extensions.utils.extensions.TelegramBotCommandsDefaults
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithNamedArgs
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
||||||
@@ -124,6 +126,7 @@ suspend fun <BC : BehaviourContext> BC.commandWithArgs(
|
|||||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
||||||
) = command(
|
) = command(
|
||||||
commandRegex,
|
commandRegex,
|
||||||
@@ -132,7 +135,7 @@ suspend fun <BC : BehaviourContext> BC.commandWithArgs(
|
|||||||
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
markerFactory = markerFactory
|
markerFactory = markerFactory
|
||||||
) {
|
) {
|
||||||
val args = it.parseCommandsWithParams().let { commandsWithArgs ->
|
val args = it.parseCommandsWithArgs(argsSeparator = argsSeparator).let { commandsWithArgs ->
|
||||||
val key = commandsWithArgs.keys.firstOrNull { it.matches(commandRegex) } ?: return@let null
|
val key = commandsWithArgs.keys.firstOrNull { it.matches(commandRegex) } ?: return@let null
|
||||||
commandsWithArgs[key]
|
commandsWithArgs[key]
|
||||||
} ?: emptyArray()
|
} ?: emptyArray()
|
||||||
@@ -144,12 +147,14 @@ suspend fun <BC : BehaviourContext> BC.commandWithArgs(
|
|||||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
||||||
) = commandWithArgs(
|
) = commandWithArgs(
|
||||||
command.toRegex(),
|
command.toRegex(),
|
||||||
initialFilter = initialFilter,
|
initialFilter = initialFilter,
|
||||||
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
markerFactory = markerFactory,
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
scenarioReceiver = scenarioReceiver
|
scenarioReceiver = scenarioReceiver
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -158,12 +163,72 @@ suspend fun <BC : BehaviourContext> BC.commandWithArgs(
|
|||||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
||||||
) = commandWithArgs(
|
) = commandWithArgs(
|
||||||
botCommand.command,
|
botCommand.command,
|
||||||
initialFilter = initialFilter,
|
initialFilter = initialFilter,
|
||||||
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
markerFactory = markerFactory,
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
|
scenarioReceiver = scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.commandWithNamedArgs(
|
||||||
|
commandRegex: Regex,
|
||||||
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, List<Pair<String, String>>>
|
||||||
|
) = command(
|
||||||
|
commandRegex,
|
||||||
|
requireOnlyCommandInMessage = false,
|
||||||
|
initialFilter = initialFilter,
|
||||||
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
|
markerFactory = markerFactory
|
||||||
|
) {
|
||||||
|
val args = it.parseCommandsWithNamedArgs(argsSeparator = argsSeparator, nameArgSeparator = nameArgSeparator).let { commandsWithArgs ->
|
||||||
|
val key = commandsWithArgs.keys.firstOrNull { it.matches(commandRegex) } ?: return@let null
|
||||||
|
commandsWithArgs[key]
|
||||||
|
} ?: emptyList()
|
||||||
|
scenarioReceiver(it, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.commandWithNamedArgs(
|
||||||
|
command: String,
|
||||||
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, List<Pair<String, String>>>
|
||||||
|
) = commandWithNamedArgs(
|
||||||
|
command.toRegex(),
|
||||||
|
initialFilter = initialFilter,
|
||||||
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
|
nameArgSeparator = nameArgSeparator,
|
||||||
|
scenarioReceiver = scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.commandWithNamedArgs(
|
||||||
|
botCommand: BotCommand,
|
||||||
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, List<Pair<String, String>>>
|
||||||
|
) = commandWithNamedArgs(
|
||||||
|
botCommand.command,
|
||||||
|
initialFilter = initialFilter,
|
||||||
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
|
nameArgSeparator = nameArgSeparator,
|
||||||
scenarioReceiver = scenarioReceiver
|
scenarioReceiver = scenarioReceiver
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -172,21 +237,99 @@ suspend fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
|||||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
||||||
): Job = commandWithArgs(commandRegex, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
): Job = commandWithArgs(
|
||||||
|
commandRegex = commandRegex,
|
||||||
|
initialFilter = initialFilter,
|
||||||
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
|
scenarioReceiver = scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
suspend fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
suspend fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
||||||
command: String,
|
command: String,
|
||||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
||||||
): Job = onCommandWithArgs(command.toRegex(), initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
): Job = onCommandWithArgs(
|
||||||
|
commandRegex = command.toRegex(),
|
||||||
|
initialFilter = initialFilter,
|
||||||
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
|
scenarioReceiver = scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
suspend fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
suspend fun <BC : BehaviourContext> BC.onCommandWithArgs(
|
||||||
botCommand: BotCommand,
|
botCommand: BotCommand,
|
||||||
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, Array<String>>
|
||||||
): Job = onCommandWithArgs(botCommand.command, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
): Job = onCommandWithArgs(
|
||||||
|
command = botCommand.command,
|
||||||
|
initialFilter = initialFilter,
|
||||||
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
|
scenarioReceiver = scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onCommandWithNamedArgs(
|
||||||
|
commandRegex: Regex,
|
||||||
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, List<Pair<String, String>>>
|
||||||
|
) = commandWithNamedArgs(
|
||||||
|
commandRegex,
|
||||||
|
initialFilter = initialFilter,
|
||||||
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
|
nameArgSeparator = nameArgSeparator,
|
||||||
|
scenarioReceiver = scenarioReceiver,
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onCommandWithNamedArgs(
|
||||||
|
command: String,
|
||||||
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, List<Pair<String, String>>>
|
||||||
|
) = onCommandWithNamedArgs(
|
||||||
|
command.toRegex(),
|
||||||
|
initialFilter = initialFilter,
|
||||||
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
|
nameArgSeparator = nameArgSeparator,
|
||||||
|
scenarioReceiver = scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onCommandWithNamedArgs(
|
||||||
|
botCommand: BotCommand,
|
||||||
|
initialFilter: CommonMessageFilter<TextContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextMessage, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in TextMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, TextMessage, List<Pair<String, String>>>
|
||||||
|
) = onCommandWithNamedArgs(
|
||||||
|
botCommand.command,
|
||||||
|
initialFilter = initialFilter,
|
||||||
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
|
markerFactory = markerFactory,
|
||||||
|
argsSeparator = argsSeparator,
|
||||||
|
nameArgSeparator = nameArgSeparator,
|
||||||
|
scenarioReceiver = scenarioReceiver
|
||||||
|
)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByC
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||||
import dev.inmo.tgbotapi.extensions.utils.botCommandTextSourceOrNull
|
import dev.inmo.tgbotapi.extensions.utils.botCommandTextSourceOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
@@ -65,7 +65,7 @@ suspend fun <BC : BehaviourContext> BC.unhandledCommandWithArgs(
|
|||||||
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
subcontextUpdatesFilter = subcontextUpdatesFilter,
|
||||||
markerFactory = markerFactory
|
markerFactory = markerFactory
|
||||||
) {
|
) {
|
||||||
val args = it.parseCommandsWithParams().let { commandsWithArgs ->
|
val args = it.parseCommandsWithArgs().let { commandsWithArgs ->
|
||||||
commandsWithArgs
|
commandsWithArgs
|
||||||
}
|
}
|
||||||
scenarioReceiver(it, args)
|
scenarioReceiver(it, args)
|
||||||
|
|||||||
@@ -4,22 +4,18 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.coroutines.*
|
import dev.inmo.micro_utils.coroutines.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitDeepLinks
|
|
||||||
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.filters.MessageFilterByChat
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.RegularTextSource
|
import dev.inmo.tgbotapi.types.message.textsources.RegularTextSource
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import io.ktor.http.decodeURLQueryComponent
|
import io.ktor.http.decodeURLQueryComponent
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.filter
|
|
||||||
|
|
||||||
private val startRegex = Regex("start")
|
private val startRegex = Regex("start")
|
||||||
suspend fun <BC : BehaviourContext> BC.onDeepLink(
|
suspend fun <BC : BehaviourContext> BC.onDeepLink(
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
|
actual var defaultCoroutineScopeProvider: () -> CoroutineScope = { CoroutineScope(Dispatchers.Default) }
|
||||||
@@ -55,6 +55,12 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linuxArm64Main {
|
||||||
|
dependencies {
|
||||||
|
api libs.ktor.client.cio
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mingwX64Main {
|
mingwX64Main {
|
||||||
dependencies {
|
dependencies {
|
||||||
api libs.ktor.client.winhttp
|
api libs.ktor.client.winhttp
|
||||||
|
|||||||
@@ -14,7 +14,18 @@ import kotlinx.serialization.json.Json
|
|||||||
* * On JS, JVM and MingwX64 platforms it is [dev.inmo.tgbotapi.bot.ktor.base.DefaultKtorRequestsExecutor]
|
* * On JS, JVM and MingwX64 platforms it is [dev.inmo.tgbotapi.bot.ktor.base.DefaultKtorRequestsExecutor]
|
||||||
* * On LinuxX64 it is [dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor]
|
* * On LinuxX64 it is [dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor]
|
||||||
*/
|
*/
|
||||||
expect class KtorRequestsExecutor (
|
expect class KtorRequestsExecutor internal constructor(
|
||||||
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
|
client: HttpClient,
|
||||||
|
callsFactories: List<KtorCallFactory>,
|
||||||
|
excludeDefaultFactories: Boolean,
|
||||||
|
requestsLimiter: RequestLimiter,
|
||||||
|
jsonFormatter: Json,
|
||||||
|
pipelineStepsHolder: KtorPipelineStepsHolder,
|
||||||
|
diff: Unit // just a diff property to know where constructor and where calling function with defaults
|
||||||
|
) : BaseRequestsExecutor
|
||||||
|
|
||||||
|
fun KtorRequestsExecutor(
|
||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
client: HttpClient = HttpClient(),
|
client: HttpClient = HttpClient(),
|
||||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||||
@@ -22,4 +33,13 @@ expect class KtorRequestsExecutor (
|
|||||||
requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter,
|
requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter,
|
||||||
jsonFormatter: Json = nonstrictJsonFormat,
|
jsonFormatter: Json = nonstrictJsonFormat,
|
||||||
pipelineStepsHolder: KtorPipelineStepsHolder = KtorPipelineStepsHolder
|
pipelineStepsHolder: KtorPipelineStepsHolder = KtorPipelineStepsHolder
|
||||||
) : BaseRequestsExecutor
|
) = KtorRequestsExecutor(
|
||||||
|
telegramAPIUrlsKeeper = telegramAPIUrlsKeeper,
|
||||||
|
client = client,
|
||||||
|
callsFactories = callsFactories,
|
||||||
|
excludeDefaultFactories = excludeDefaultFactories,
|
||||||
|
requestsLimiter = requestsLimiter,
|
||||||
|
jsonFormatter = jsonFormatter,
|
||||||
|
pipelineStepsHolder = pipelineStepsHolder,
|
||||||
|
diff = kotlin.Unit
|
||||||
|
)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.bot.exceptions.CommonBotException
|
|||||||
import dev.inmo.tgbotapi.bot.exceptions.newRequestException
|
import dev.inmo.tgbotapi.bot.exceptions.newRequestException
|
||||||
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
|
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
|
||||||
import dev.inmo.tgbotapi.bot.ktor.KtorPipelineStepsHolder
|
import dev.inmo.tgbotapi.bot.ktor.KtorPipelineStepsHolder
|
||||||
|
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutor
|
||||||
import dev.inmo.tgbotapi.bot.ktor.createTelegramBotDefaultKtorCallRequestsFactories
|
import dev.inmo.tgbotapi.bot.ktor.createTelegramBotDefaultKtorCallRequestsFactories
|
||||||
import dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter
|
import dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter
|
||||||
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
|
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
|
||||||
@@ -19,14 +20,15 @@ import io.ktor.client.plugins.*
|
|||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
class DefaultKtorRequestsExecutor(
|
class DefaultKtorRequestsExecutor internal constructor(
|
||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
client: HttpClient = HttpClient(),
|
client: HttpClient,
|
||||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
callsFactories: List<KtorCallFactory>,
|
||||||
excludeDefaultFactories: Boolean = false,
|
excludeDefaultFactories: Boolean,
|
||||||
private val requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter,
|
private val requestsLimiter: RequestLimiter,
|
||||||
private val jsonFormatter: Json = nonstrictJsonFormat,
|
private val jsonFormatter: Json,
|
||||||
private val pipelineStepsHolder: KtorPipelineStepsHolder = KtorPipelineStepsHolder
|
private val pipelineStepsHolder: KtorPipelineStepsHolder,
|
||||||
|
diff: Unit
|
||||||
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
||||||
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
||||||
if (!excludeDefaultFactories) {
|
if (!excludeDefaultFactories) {
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
|||||||
import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
|
import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
|
||||||
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
|
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
|
||||||
import dev.inmo.tgbotapi.bot.ktor.KtorPipelineStepsHolder
|
import dev.inmo.tgbotapi.bot.ktor.KtorPipelineStepsHolder
|
||||||
|
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutor
|
||||||
|
import dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter
|
||||||
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
|
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
|
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
@@ -55,7 +58,8 @@ class MultipleClientKtorRequestsExecutor (
|
|||||||
excludeDefaultFactories,
|
excludeDefaultFactories,
|
||||||
requestsLimiter,
|
requestsLimiter,
|
||||||
jsonFormatter,
|
jsonFormatter,
|
||||||
pipelineStepsHolder
|
pipelineStepsHolder,
|
||||||
|
Unit
|
||||||
)
|
)
|
||||||
}.toSet()
|
}.toSet()
|
||||||
private val freeClients = MutableStateFlow<Set<DefaultKtorRequestsExecutor>>(requestExecutors)
|
private val freeClients = MutableStateFlow<Set<DefaultKtorRequestsExecutor>>(requestExecutors)
|
||||||
@@ -68,14 +72,15 @@ class MultipleClientKtorRequestsExecutor (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
internal constructor(
|
||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
client: HttpClient,
|
client: HttpClient,
|
||||||
callsFactories: List<KtorCallFactory>,
|
callsFactories: List<KtorCallFactory>,
|
||||||
excludeDefaultFactories: Boolean,
|
excludeDefaultFactories: Boolean,
|
||||||
requestsLimiter: RequestLimiter,
|
requestsLimiter: RequestLimiter,
|
||||||
jsonFormatter: Json,
|
jsonFormatter: Json,
|
||||||
pipelineStepsHolder: KtorPipelineStepsHolder
|
pipelineStepsHolder: KtorPipelineStepsHolder,
|
||||||
|
diff: Unit
|
||||||
) : this(
|
) : this(
|
||||||
telegramAPIUrlsKeeper,
|
telegramAPIUrlsKeeper,
|
||||||
callsFactories,
|
callsFactories,
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import dev.inmo.tgbotapi.types.MessageId
|
|||||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
import dev.inmo.tgbotapi.types.MessageThreadId
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage
|
||||||
import dev.inmo.tgbotapi.types.stories.Story
|
import dev.inmo.tgbotapi.types.stories.Story
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@@ -25,7 +27,7 @@ data class StoryContent(
|
|||||||
replyToMessageId: MessageId?,
|
replyToMessageId: MessageId?,
|
||||||
allowSendingWithoutReply: Boolean?,
|
allowSendingWithoutReply: Boolean?,
|
||||||
replyMarkup: KeyboardMarkup?
|
replyMarkup: KeyboardMarkup?
|
||||||
): Request<out Message> {
|
): Request<PossiblyForwardedMessage> {
|
||||||
return ForwardMessage(
|
return ForwardMessage(
|
||||||
chat.id,
|
chat.id,
|
||||||
toChatId = chatId,
|
toChatId = chatId,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.types.MessageThreadId
|
|||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.files.VoiceFile
|
import dev.inmo.tgbotapi.types.files.VoiceFile
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
|
import dev.inmo.tgbotapi.types.threadId
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -27,16 +28,16 @@ data class VoiceContent(
|
|||||||
allowSendingWithoutReply: Boolean?,
|
allowSendingWithoutReply: Boolean?,
|
||||||
replyMarkup: KeyboardMarkup?
|
replyMarkup: KeyboardMarkup?
|
||||||
): Request<ContentMessage<VoiceContent>> = SendVoice(
|
): Request<ContentMessage<VoiceContent>> = SendVoice(
|
||||||
chatId,
|
chatId = chatId,
|
||||||
media.fileId,
|
voice = media.fileId,
|
||||||
textSources,
|
entities = textSources,
|
||||||
media.duration,
|
threadId = messageThreadId,
|
||||||
messageThreadId,
|
duration = media.duration,
|
||||||
disableNotification,
|
disableNotification = disableNotification,
|
||||||
protectContent,
|
protectContent = protectContent,
|
||||||
replyToMessageId,
|
replyToMessageId = replyToMessageId,
|
||||||
allowSendingWithoutReply,
|
allowSendingWithoutReply = allowSendingWithoutReply,
|
||||||
replyMarkup
|
replyMarkup = replyMarkup
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun asTelegramMedia(): TelegramMediaAudio = TelegramMediaAudio(
|
override fun asTelegramMedia(): TelegramMediaAudio = TelegramMediaAudio(
|
||||||
|
|||||||
1
tgbotapi.core/src/linuxArm64Main/kotlin/PackageInfo.kt
Normal file
1
tgbotapi.core/src/linuxArm64Main/kotlin/PackageInfo.kt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package dev.inmo.tgbotapi
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.tgbotapi.bot.ktor
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor
|
||||||
|
|
||||||
|
actual typealias KtorRequestsExecutor = MultipleClientKtorRequestsExecutor
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package dev.inmo.tgbotapi.bot.ktor.base
|
||||||
|
|
||||||
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.engine.cio.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
||||||
|
* platforms and MingwX64 should return [client]
|
||||||
|
*
|
||||||
|
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
|
||||||
|
*/
|
||||||
|
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = (client.engineConfig as? CIOEngineConfig) ?.let {
|
||||||
|
lateinit var config: HttpClientConfig<out CIOEngineConfig>
|
||||||
|
client.config {
|
||||||
|
config = this as HttpClientConfig<out CIOEngineConfig>
|
||||||
|
}.close()
|
||||||
|
HttpClient(CIO) {
|
||||||
|
this.plusAssign(config)
|
||||||
|
}
|
||||||
|
} ?: throw IllegalArgumentException("On LinuxX64 TelegramBotAPI currently support only Curl Ktor HttpClient engine")
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package dev.inmo.tgbotapi.requests.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
|
import dev.inmo.micro_utils.ktor.common.input
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.MultipartFile
|
||||||
|
|
||||||
|
actual fun MPPFile.asMultipartFile(): MultipartFile = MultipartFile(this.name) {
|
||||||
|
input()
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import io.ktor.utils.io.ByteReadChannel
|
||||||
|
import io.ktor.utils.io.core.Input
|
||||||
|
import io.ktor.utils.io.readRemaining
|
||||||
|
|
||||||
|
actual suspend fun ByteReadChannel.asInput(): Input = readRemaining()
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
//actual typealias MimeType = MimeType
|
||||||
|
|
||||||
|
@OptIn(RiskFeature::class)
|
||||||
|
@Serializable(MimeTypeSerializer::class)
|
||||||
|
actual data class MimeType(
|
||||||
|
actual val raw: String
|
||||||
|
)
|
||||||
|
internal actual fun createMimeType(raw: String): MimeType = MimeType(raw)
|
||||||
@@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable
|
|||||||
|
|
||||||
//actual typealias MimeType = MimeType
|
//actual typealias MimeType = MimeType
|
||||||
|
|
||||||
|
@OptIn(RiskFeature::class)
|
||||||
@Serializable(MimeTypeSerializer::class)
|
@Serializable(MimeTypeSerializer::class)
|
||||||
actual data class MimeType(
|
actual data class MimeType(
|
||||||
actual val raw: String
|
actual val raw: String
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class TelegramBotAPISymbolProcessor(
|
|||||||
private val outputFile: String = "Output",
|
private val outputFile: String = "Output",
|
||||||
private val outputFolder: String? = null
|
private val outputFolder: String? = null
|
||||||
) : SymbolProcessor {
|
) : SymbolProcessor {
|
||||||
|
@OptIn(RiskFeature::class)
|
||||||
private val classCastsIncludedClassName = ClassCastsIncluded::class.asClassName()
|
private val classCastsIncludedClassName = ClassCastsIncluded::class.asClassName()
|
||||||
@OptIn(KspExperimental::class, RiskFeature::class)
|
@OptIn(KspExperimental::class, RiskFeature::class)
|
||||||
override fun process(resolver: Resolver): List<KSAnnotated> {
|
override fun process(resolver: Resolver): List<KSAnnotated> {
|
||||||
|
|||||||
@@ -0,0 +1,247 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.utils.extensions
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.abstracts.TextedWithTextSources
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
||||||
|
import dev.inmo.tgbotapi.types.message.textsources.TextSource
|
||||||
|
|
||||||
|
object TelegramBotCommandsDefaults {
|
||||||
|
const val defaultArgsSeparator = " "
|
||||||
|
val defaultArgsSeparatorRegex = Regex(defaultArgsSeparator)
|
||||||
|
const val defaultNamesArgsSeparator = "="
|
||||||
|
val defaultNamesArgsSeparatorRegex = Regex(defaultNamesArgsSeparator)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated(message = "Replaced", replaceWith = ReplaceWith("TelegramBotCommandsDefaults.defaultArgsSeparatorRegex", "dev.inmo.tgbotapi.extensions.utils.extensions.TelegramBotCommandsDefaults"))
|
||||||
|
val defaultArgsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||||
|
*/
|
||||||
|
fun List<TextSource>.parseCommandsWithArgs(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex
|
||||||
|
): MutableMap<String, Array<String>> {
|
||||||
|
val result = mutableMapOf<String, Array<String>>()
|
||||||
|
var currentBotCommandSource: BotCommandTextSource? = null
|
||||||
|
var currentArgs = ""
|
||||||
|
|
||||||
|
fun includeCurrent() = currentBotCommandSource?.let {
|
||||||
|
currentArgs = currentArgs.trim()
|
||||||
|
result[it.command] = if (currentArgs.isNotEmpty()) {
|
||||||
|
currentArgs.split(argsSeparator).toTypedArray()
|
||||||
|
} else {
|
||||||
|
emptyArray()
|
||||||
|
}
|
||||||
|
currentArgs = ""
|
||||||
|
currentBotCommandSource = null
|
||||||
|
}
|
||||||
|
|
||||||
|
for (textSource in this) {
|
||||||
|
if (textSource is BotCommandTextSource) {
|
||||||
|
includeCurrent()
|
||||||
|
currentBotCommandSource = textSource
|
||||||
|
} else {
|
||||||
|
currentArgs += textSource.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
includeCurrent()
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||||
|
*/
|
||||||
|
fun TextedWithTextSources.parseCommandsWithArgs(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex
|
||||||
|
) = textSources?.parseCommandsWithArgs(argsSeparator) ?: emptyMap()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||||
|
*/
|
||||||
|
fun ContentMessage<TextContent>.parseCommandsWithArgs(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex
|
||||||
|
) = content.parseCommandsWithArgs(argsSeparator)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||||
|
*/
|
||||||
|
fun List<TextSource>.parseCommandsWithArgs(
|
||||||
|
argsSeparator: String
|
||||||
|
): MutableMap<String, Array<String>> = parseCommandsWithArgs(Regex(argsSeparator))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||||
|
*/
|
||||||
|
fun TextedWithTextSources.parseCommandsWithArgs(
|
||||||
|
argsSeparator: String
|
||||||
|
) = parseCommandsWithArgs(Regex(argsSeparator))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||||
|
*/
|
||||||
|
fun ContentMessage<TextContent>.parseCommandsWithArgs(
|
||||||
|
argsSeparator: String
|
||||||
|
) = parseCommandsWithArgs(Regex(argsSeparator))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithArgs] to create base [argsSeparator] split args for commands and map their as k-v pairs.
|
||||||
|
* Sample:
|
||||||
|
*
|
||||||
|
* ```bash
|
||||||
|
* /command args1=value1 arg2=value2 arg1=value3
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Will produce [Map] with one key `command` and the list of three pairs:
|
||||||
|
*
|
||||||
|
* 1. `args1` to `value1`
|
||||||
|
* 2. `args2` to `value2`
|
||||||
|
* 3. `args1` to `value3`
|
||||||
|
*
|
||||||
|
* @return Array of named arguments
|
||||||
|
*/
|
||||||
|
fun List<TextSource>.parseCommandsWithNamedArgs(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
): Map<String, List<Pair<String, String>>> {
|
||||||
|
val withArgs = parseCommandsWithArgs(argsSeparator)
|
||||||
|
|
||||||
|
return withArgs.mapValues { (k, v) ->
|
||||||
|
v.flatMap {
|
||||||
|
it.split(nameArgSeparator, 2).map { v -> it to v }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithArgs] to create base [argsSeparator] split args for commands and map their as k-v pairs.
|
||||||
|
* Sample:
|
||||||
|
*
|
||||||
|
* ```bash
|
||||||
|
* /command args1=value1 arg2=value2 arg1=value3
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Will produce [Map] with one key `command` and the list of three pairs:
|
||||||
|
*
|
||||||
|
* 1. `args1` to `value1`
|
||||||
|
* 2. `args2` to `value2`
|
||||||
|
* 3. `args1` to `value3`
|
||||||
|
*
|
||||||
|
* @return Array of named arguments
|
||||||
|
*/
|
||||||
|
fun TextedWithTextSources.parseCommandsWithNamedArgs(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
) = textSources?.parseCommandsWithNamedArgs(argsSeparator = argsSeparator, nameArgSeparator = nameArgSeparator) ?: emptyMap()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithArgs] to create base [argsSeparator] split args for commands and map their as k-v pairs.
|
||||||
|
* Sample:
|
||||||
|
*
|
||||||
|
* ```bash
|
||||||
|
* /command args1=value1 arg2=value2 arg1=value3
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Will produce [Map] with one key `command` and the list of three pairs:
|
||||||
|
*
|
||||||
|
* 1. `args1` to `value1`
|
||||||
|
* 2. `args2` to `value2`
|
||||||
|
* 3. `args1` to `value3`
|
||||||
|
*
|
||||||
|
* @return Array of named arguments
|
||||||
|
*/
|
||||||
|
fun ContentMessage<TextContent>.parseCommandsWithNamedArgs(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
) = content.parseCommandsWithNamedArgs(argsSeparator = argsSeparator, nameArgSeparator = nameArgSeparator)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithArgs] to create base [argsSeparator] split args for commands and map their as k-v pairs.
|
||||||
|
* Sample:
|
||||||
|
*
|
||||||
|
* ```bash
|
||||||
|
* /command args1=value1 arg2=value2 arg1=value3
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Will produce [Map] with one key `command` and the list of three pairs:
|
||||||
|
*
|
||||||
|
* 1. `args1` to `value1`
|
||||||
|
* 2. `args2` to `value2`
|
||||||
|
* 3. `args1` to `value3`
|
||||||
|
*
|
||||||
|
* @return Array of named arguments
|
||||||
|
*/
|
||||||
|
fun List<TextSource>.parseCommandsWithNamedArgs(
|
||||||
|
argsSeparator: String,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
): Map<String, List<Pair<String, String>>> = parseCommandsWithNamedArgs(Regex(pattern = argsSeparator), nameArgSeparator)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithArgs] to create base [argsSeparator] split args for commands and map their as k-v pairs.
|
||||||
|
* Sample:
|
||||||
|
*
|
||||||
|
* ```bash
|
||||||
|
* /command args1=value1 arg2=value2 arg1=value3
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Will produce [Map] with one key `command` and the list of three pairs:
|
||||||
|
*
|
||||||
|
* 1. `args1` to `value1`
|
||||||
|
* 2. `args2` to `value2`
|
||||||
|
* 3. `args1` to `value3`
|
||||||
|
*
|
||||||
|
* @return Array of named arguments
|
||||||
|
*/
|
||||||
|
fun TextedWithTextSources.parseCommandsWithNamedArgs(
|
||||||
|
argsSeparator: String,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
) = parseCommandsWithNamedArgs(argsSeparator = Regex(pattern = argsSeparator), nameArgSeparator = nameArgSeparator)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [parseCommandsWithArgs] to create base [argsSeparator] split args for commands and map their as k-v pairs.
|
||||||
|
* Sample:
|
||||||
|
*
|
||||||
|
* ```bash
|
||||||
|
* /command args1=value1 arg2=value2 arg1=value3
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Will produce [Map] with one key `command` and the list of three pairs:
|
||||||
|
*
|
||||||
|
* 1. `args1` to `value1`
|
||||||
|
* 2. `args2` to `value2`
|
||||||
|
* 3. `args1` to `value3`
|
||||||
|
*
|
||||||
|
* @return Array of named arguments
|
||||||
|
*/
|
||||||
|
fun ContentMessage<TextContent>.parseCommandsWithNamedArgs(
|
||||||
|
argsSeparator: String,
|
||||||
|
nameArgSeparator: Regex = TelegramBotCommandsDefaults.defaultNamesArgsSeparatorRegex,
|
||||||
|
) = parseCommandsWithNamedArgs(argsSeparator = Regex(pattern = argsSeparator), nameArgSeparator = nameArgSeparator)
|
||||||
|
|
||||||
|
|
||||||
|
// Deprecations
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||||
|
*/
|
||||||
|
@Deprecated("Renamed", ReplaceWith("parseCommandsWithArgs(argsSeparator)", "dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs"))
|
||||||
|
fun List<TextSource>.parseCommandsWithParams(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex
|
||||||
|
): MutableMap<String, Array<String>> = parseCommandsWithArgs(argsSeparator)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||||
|
*/
|
||||||
|
@Deprecated("Renamed", ReplaceWith("parseCommandsWithArgs(argsSeparator)", "dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs"))
|
||||||
|
fun TextedWithTextSources.parseCommandsWithParams(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex
|
||||||
|
) = parseCommandsWithArgs(argsSeparator)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||||
|
*/
|
||||||
|
@Deprecated("Renamed", ReplaceWith("parseCommandsWithArgs(argsSeparator)", "dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs"))
|
||||||
|
fun ContentMessage<TextContent>.parseCommandsWithParams(
|
||||||
|
argsSeparator: Regex = TelegramBotCommandsDefaults.defaultArgsSeparatorRegex
|
||||||
|
) = parseCommandsWithArgs(argsSeparator)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.utils.extensions
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.abstracts.TextedWithTextSources
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.botCommandTextSourceOrNull
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.ifBotCommandTextSource
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.whenBotCommandTextSource
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
||||||
|
import dev.inmo.tgbotapi.types.message.textsources.TextSource
|
||||||
|
|
||||||
|
// Sources
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse text sources to find commands with their arguments. This method will skip all the text sources __before__
|
||||||
|
* first command and all following text sources until the next command will be guessed as an args of last found command
|
||||||
|
*/
|
||||||
|
fun List<TextSource>.parseCommandsWithArgsSources(): Map<BotCommandTextSource, Array<TextSource>> {
|
||||||
|
var currentCommandTextSource: BotCommandTextSource? = null
|
||||||
|
val currentArgs = mutableListOf<TextSource>()
|
||||||
|
val result = mutableMapOf<BotCommandTextSource, Array<TextSource>>()
|
||||||
|
|
||||||
|
fun addCurrentCommandToResult() {
|
||||||
|
currentCommandTextSource ?.let {
|
||||||
|
result[it] = currentArgs.toTypedArray()
|
||||||
|
currentArgs.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
forEach {
|
||||||
|
it.whenBotCommandTextSource {
|
||||||
|
addCurrentCommandToResult()
|
||||||
|
currentCommandTextSource = it
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
currentArgs.add(it)
|
||||||
|
}
|
||||||
|
addCurrentCommandToResult()
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse text sources to find commands with their arguments. This method will skip all the text sources __before__
|
||||||
|
* first command and all following text sources until the next command will be guessed as an args of last found command
|
||||||
|
*/
|
||||||
|
fun TextedWithTextSources.parseCommandsWithArgsSources() = textSources?.parseCommandsWithArgsSources() ?: emptyMap()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse text sources to find commands with their arguments. This method will skip all the text sources __before__
|
||||||
|
* first command and all following text sources until the next command will be guessed as an args of last found command
|
||||||
|
*/
|
||||||
|
fun ContentMessage<TextContent>.parseCommandsWithArgsSources() = content.parseCommandsWithArgsSources()
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.utils.extensions
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.abstracts.TextedWithTextSources
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.TextSource
|
|
||||||
|
|
||||||
|
|
||||||
val defaultArgsSeparator = Regex(" ")
|
|
||||||
/**
|
|
||||||
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
|
||||||
*/
|
|
||||||
fun List<TextSource>.parseCommandsWithParams(
|
|
||||||
argsSeparator: Regex = defaultArgsSeparator
|
|
||||||
): MutableMap<String, Array<String>> {
|
|
||||||
val result = mutableMapOf<String, Array<String>>()
|
|
||||||
var currentBotCommandSource: BotCommandTextSource? = null
|
|
||||||
var currentArgs = ""
|
|
||||||
fun includeCurrent() = currentBotCommandSource ?.let {
|
|
||||||
currentArgs = currentArgs.trim()
|
|
||||||
result[it.command] = if (currentArgs.isNotEmpty()) {
|
|
||||||
currentArgs.split(argsSeparator).toTypedArray()
|
|
||||||
} else {
|
|
||||||
emptyArray()
|
|
||||||
}
|
|
||||||
currentArgs = ""
|
|
||||||
currentBotCommandSource = null
|
|
||||||
}
|
|
||||||
for (textSource in this) {
|
|
||||||
if (textSource is BotCommandTextSource) {
|
|
||||||
includeCurrent()
|
|
||||||
currentBotCommandSource = textSource
|
|
||||||
} else {
|
|
||||||
currentArgs += textSource.source
|
|
||||||
}
|
|
||||||
}
|
|
||||||
includeCurrent()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
|
||||||
*/
|
|
||||||
fun TextedWithTextSources.parseCommandsWithParams(
|
|
||||||
argsSeparator: Regex = defaultArgsSeparator
|
|
||||||
) = textSources ?.parseCommandsWithParams(argsSeparator) ?: emptyMap()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
|
||||||
*/
|
|
||||||
fun ContentMessage<TextContent>.parseCommandsWithParams(
|
|
||||||
argsSeparator: Regex = defaultArgsSeparator
|
|
||||||
) = content.parseCommandsWithParams(argsSeparator)
|
|
||||||
@@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
|
|||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
||||||
import dev.inmo.tgbotapi.types.update.*
|
import dev.inmo.tgbotapi.types.update.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.*
|
import dev.inmo.tgbotapi.types.update.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage
|
import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,6 +23,7 @@ fun List<Update>.lastUpdateIdentifier(): UpdateIdentifier? {
|
|||||||
* Will convert incoming list of [Update]s to list with [Update]s, which include [dev.inmo.tgbotapi.types.message.abstracts.ContentMessage]s
|
* Will convert incoming list of [Update]s to list with [Update]s, which include [dev.inmo.tgbotapi.types.message.abstracts.ContentMessage]s
|
||||||
* with [dev.inmo.tgbotapi.types.message.content.MediaGroupContent]
|
* with [dev.inmo.tgbotapi.types.message.content.MediaGroupContent]
|
||||||
*/
|
*/
|
||||||
|
@OptIn(RiskFeature::class)
|
||||||
fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
|
fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
|
||||||
val resultUpdates = mutableListOf<Update>()
|
val resultUpdates = mutableListOf<Update>()
|
||||||
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<Pair<BaseSentMessageUpdate, PossiblySentViaBotCommonMessage<MediaGroupPartContent>>>>()
|
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<Pair<BaseSentMessageUpdate, PossiblySentViaBotCommonMessage<MediaGroupPartContent>>>>()
|
||||||
|
|||||||
Reference in New Issue
Block a user