1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-11-17 12:30:20 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
618017c160 add exceptions handling readme 2022-01-11 21:21:31 +06:00
1382 changed files with 13836 additions and 106496 deletions

2
.github/FUNDING.yml vendored
View File

@@ -1,3 +1,3 @@
# These are supported funding model platforms # These are supported funding model platforms
custom: ['https://tonscan.org/address/UQAtuSLJ76Zehc3qP-eRYMR98fPIu_oOp_atcpVX55zxHwTU'] custom: ['https://www.tinkoff.ru/rm/ovsyannikov.aleksey113/ObMJ712472']

View File

@@ -5,9 +5,6 @@ on: [pull_request, issues]
jobs: jobs:
greeting: greeting:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps: steps:
- uses: actions/first-interaction@v1 - uses: actions/first-interaction@v1
with: with:

View File

@@ -10,12 +10,12 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-java@v1 - uses: actions/setup-java@v1
with: with:
java-version: 17 java-version: 1.8
- name: Build - name: Build
run: ./gradlew dokkaHtmlMultiModule run: ./gradlew dokkaHtml
- name: Publish KDocs - name: Publish KDocs
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build/dokka/htmlMultiModule publish_dir: ./docs/build/dokka/html
publish_branch: kdocs publish_branch: kdocs

View File

@@ -7,30 +7,21 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-java@v1 - uses: actions/setup-java@v1
with: with:
java-version: 17 java-version: 1.8
- name: Setup LibCurl - name: Fix android 31.0.0 dx
run: sudo apt update && sudo apt install -y libcurl4-openssl-dev continue-on-error: true
run: cd /usr/local/lib/android/sdk/build-tools/31.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar
- name: Rewrite version - name: Rewrite version
run: | run: |
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`" branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
cat gradle.properties | sed -e "s/^library_version=\([0-9\.]*\)/library_version=\1-branch_$branch-build${{ github.run_number }}/" > gradle.properties.tmp cat gradle.properties | sed -e "s/^library_version=\([0-9\.]*\)/library_version=\1-branch_$branch-build${{ github.run_number }}/" > gradle.properties.tmp
rm gradle.properties rm gradle.properties
mv gradle.properties.tmp gradle.properties mv gradle.properties.tmp gradle.properties
- name: KotlinSymbolProcessing execution
run: ./gradlew kspCommonMainKotlinMetadata
- name: Build - name: Build
run: ./gradlew build run: ./gradlew build
- name: API compatibility check - name: Publish
run: ./gradlew apiCheck
- name: Publish to GithubPackages
continue-on-error: true continue-on-error: true
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication
env: env:
GITHUB_USER: ${{ github.actor }} GITHUBPACKAGES_USER: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to Gitea
continue-on-error: true
run: ./gradlew publishAllPublicationsToInmoNexusRepository
env:
INMONEXUS_USER: ${{ secrets.INMONEXUS_USER }}
INMONEXUS_PASSWORD: ${{ secrets.INMONEXUS_PASSWORD }}

3
.gitignore vendored
View File

@@ -1,5 +1,4 @@
.idea .idea
.kotlin
out/* out/*
*.iml *.iml
target target
@@ -9,9 +8,7 @@ settings.xml
.gradle/ .gradle/
build/ build/
out/ out/
bin/
local.properties local.properties
kotlin-js-store/ kotlin-js-store/
secret.gradle secret.gradle
.aider*

File diff suppressed because it is too large Load Diff

View File

@@ -1,19 +1,8 @@
# TelegramBotAPI [![Maven Central Version](https://img.shields.io/maven-central/v/dev.inmo/tgbotapi)](https://central.sonatype.com/artifact/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-9.1-blue)](https://core.telegram.org/bots/api-changelog#july-3-2025) # TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-5.6-blue)](https://core.telegram.org/bots/api-changelog#december-30-2021)
| Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Mk&message=Docs&color=blue&logo=mkdocs)](https://docs.inmo.dev/tgbotapi/index.html) | | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue)](https://forms.gle/2Hex2ynbHWHhi1KY7) [![Chat in Telegram](https://img.shields.io/static/v1?label=Telegram&message=Chat&color=blue)](https://t.me/InMoTelegramBotAPI) |
|:----------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| |:---:|
| Useful repos | [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![Examples](https://img.shields.io/static/v1?label=Github&message=Examples&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) | | [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![Examples](https://img.shields.io/static/v1?label=Github&message=Examples&color=blue)](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Bookstack&message=Tutorial&color=blue)](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
| Misc | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue&logo=google-sheets)](https://docs.google.com/forms/d/e/1FAIpQLSctdJHT_aEniyYT0-IUAEfo1hsIlezX2owlkEAYX4KPl2V2_A/viewform?usp=sf_link) |
| Platforms | ![JVM](https://img.shields.io/badge/JVM-red?style=plastic&logo=openjdk&logoColor=white) ![Js](https://img.shields.io/badge/JavaScript-323330?style=plastic&logo=javascript&logoColor=F7DF1E) |
| Experimental Platforms | [![Linux x64](https://img.shields.io/badge/LinuxX64-FCC624?style=plastic&logo=linux&logoColor=black)](https://kotlinlang.org/docs/native-target-support.html#tier-1) [![MinGW x64](https://img.shields.io/badge/MinGWX64-black?style=plastic&logo=windows&logoColor=green)](https://kotlinlang.org/docs/native-target-support.html#tier-1) |
<!--- [![Telegram Channel](./resources/tg_channel_qr.jpg)](https://t.me/ktgbotapi) --->
<p align="center">
<a href="https://t.me/ktgbotapi">
<img src="./resources/tg_channel_qr.jpg">
</a>
</p>
Hello! This is a set of libraries for working with Telegram Bot API. Hello! This is a set of libraries for working with Telegram Bot API.
@@ -39,7 +28,7 @@ Other configuration examples:
suspend fun main() { suspend fun main() {
val bot = telegramBot(TOKEN) val bot = telegramBot(TOKEN)
bot.buildBehaviourWithLongPolling { bot.buildBehaviour {
println(getMe()) println(getMe())
onCommand("start") { onCommand("start") {
@@ -80,7 +69,7 @@ and maybe some updates it got after launch)
suspend fun main() { suspend fun main() {
val bot = telegramBot(TOKEN) val bot = telegramBot(TOKEN)
bot.buildBehaviourWithLongPolling { bot.buildBehaviour {
println(getMe()) println(getMe())
val nameReplyMarkup = ReplyKeyboardMarkup( val nameReplyMarkup = ReplyKeyboardMarkup(
@@ -118,22 +107,5 @@ suspend fun main() {
### More examples ### More examples
You may find examples in [this project](https://github.com/InsanusMokrassar/TelegramBotAPI-examples). Besides, you are You may find examples in [this project](https://github.com/InsanusMokrassar/TelegramBotAPI-examples). Besides, you are
always welcome in our [docs](https://docs.inmo.dev/tgbotapi/index.html) and always welcome in our [wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/About-this-project) and
[chat](https://t.me/InMoTelegramBotAPIChat). [chat](https://t.me/InMoTelegramBotAPIChat).
### Bot API Server Notice
Under the hood, default bots realizations will try to use links
([PathedFile](tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt)#filePath) as files each
time you are trying to download file from telegram in any way - via saving to file, use stream or download as byte array.
To let bot correctly download files from bot api server, you must:
* Run bot api server locally
to proxy requests for files to the server where bot api server has been hosted
* In case of local bot api server (shared one host machine) you must ensure that access to bot api server has been
granted for your bot. For example, [aiogram/telegram-bot-api](https://hub.docker.com/r/aiogram/telegram-bot-api) image
use `101` UID/GID in linux for user and group as owners. So, your bot must run under user included in `101` group
(like `systemd-journal`) or be `101` UID user (like `systemd-resolve`)
* **OR** Use some reverse proxy (like nginx). It will allow you to broadcast your bots files without linux rights problems
* Set [TelegramAPIUrlsKeeper](tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt)#fileLinkUrlMapper
to map urls to let bot execute requests to your nginx proxy

View File

@@ -1,48 +1,24 @@
buildscript { buildscript {
repositories { repositories {
mavenLocal()
mavenCentral() mavenCentral()
maven { url "https://plugins.gradle.org/m2/" } maven { url "https://plugins.gradle.org/m2/" }
mavenLocal()
} }
dependencies { dependencies {
classpath libs.kotlin.gradle.plugin classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath libs.kotlin.ksp.plugin classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath libs.kotlin.serialization.plugin classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
classpath libs.kotlin.dokka.plugin
classpath libs.github.release.plugin
} }
} }
plugins { plugins {
alias(libs.plugins.kotlin.dokka) id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version" apply false
alias(libs.plugins.versions) id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" apply false
alias(libs.plugins.validator)
alias(libs.plugins.nmcp.aggregation)
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
nmcpAggregation {
centralPortal {
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')
validationTimeout = Duration.ofSeconds(0)
publishingType = "USER_MANAGED"
}
publishAllProjectsProbablyBreakingProjectIsolation()
}
} }
// temporal crutch until legacy tests will be stabled or legacy target will be removed // temporal crutch until legacy tests will be stabled or legacy target will be removed
allprojects { allprojects {
repositories {
mavenCentral()
google()
maven { url "https://nexus.inmo.dev/repository/maven-releases/" }
mavenLocal()
}
if (it != rootProject.findProject("docs")) { if (it != rootProject.findProject("docs")) {
tasks.whenTaskAdded { task -> tasks.whenTaskAdded { task ->
if(task.name == "jsLegacyBrowserTest" || task.name == "jsLegacyNodeTest") { if(task.name == "jsLegacyBrowserTest" || task.name == "jsLegacyNodeTest") {
@@ -51,7 +27,6 @@ allprojects {
} }
} }
} }
apply from: "./extensions.gradle"
private String getCurrentVersionChangelog() { private String getCurrentVersionChangelog() {
OutputStream changelogDataOS = new ByteArrayOutputStream() OutputStream changelogDataOS = new ByteArrayOutputStream()
@@ -63,28 +38,20 @@ private String getCurrentVersionChangelog() {
return changelogDataOS.toString().trim() return changelogDataOS.toString().trim()
} }
if (new File(projectDir, "secret.gradle").exists()) {
def githubTokenVariableName = "GITHUB_RELEASE_TOKEN" apply from: './secret.gradle'
def githubTokenVariableFromEnv = System.getenv(githubTokenVariableName)
def secretFile = new File(projectDir, "secret.gradle")
if (secretFile.exists() || project.hasProperty(githubTokenVariableName) || (githubTokenVariableFromEnv != "" && githubTokenVariableFromEnv != null)) {
if (secretFile.exists()) {
apply from: './secret.gradle'
}
apply plugin: "com.github.breadmoirai.github-release" apply plugin: "com.github.breadmoirai.github-release"
def githubReleaseToken = project.hasProperty(githubTokenVariableName) ? project.property(githubTokenVariableName).toString() : githubTokenVariableFromEnv
githubRelease { githubRelease {
token githubReleaseToken token "${project.property('GITHUB_RELEASE_TOKEN')}"
owner = "InsanusMokrassar" owner "InsanusMokrassar"
repo = "TelegramBotAPI" repo "TelegramBotAPI"
tagName = "v$library_version" tagName "$library_version"
releaseName = "$library_version" releaseName "$library_version"
targetCommitish = "$library_version" targetCommitish "$library_version"
body = getCurrentVersionChangelog() body getCurrentVersionChangelog()
} }
} }

View File

@@ -1,28 +1,50 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
}
}
plugins { plugins {
id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization" id "org.jetbrains.kotlin.plugin.serialization"
id "org.jetbrains.dokka" id "org.jetbrains.dokka" version "$dokka_version"
} }
project.description = "Full collection of all built-in tgbotapi tools" repositories {
mavenLocal()
apply from: "$mppProjectWithSerialization" mavenCentral()
}
kotlin { kotlin {
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
}
sourceSets { sourceSets {
commonMain { commonMain {
dependencies { dependencies {
api project(":tgbotapi.core") implementation kotlin('stdlib')
api project(":tgbotapi.api")
api project(":tgbotapi.utils") rootProject.subprojects.forEach {
api project(":tgbotapi.behaviour_builder") if (it != project) {
api project(":tgbotapi.behaviour_builder.fsm") api it
api project(":tgbotapi") }
} }
}
jsMain {
dependencies {
api project(":tgbotapi.webapps")
} }
} }
} }
@@ -30,13 +52,12 @@ kotlin {
private List<SourceDirectorySet> findSourcesWithName(String... approximateNames) { private List<SourceDirectorySet> findSourcesWithName(String... approximateNames) {
return parent.subprojects return parent.subprojects
.findAll { it != project && it.hasProperty("kotlin") } .findAll { it != project }
.collectMany { it.kotlin.sourceSets } .collectMany { it.kotlin.sourceSets }
.findAll { sourceSet -> .findAll { sourceSet -> approximateNames.any {
approximateNames.any { nameToFilter -> nameToFilter -> sourceSet.name.contains(nameToFilter)
sourceSet.name.contains(nameToFilter) }
} }.collect { it.kotlin }
}.collect { it.kotlin }
} }
Object callback = { Object callback = {
@@ -54,8 +75,8 @@ Object callback = {
skipDeprecated.set(true) skipDeprecated.set(true)
sourceLink { sourceLink {
localDirectory.set(file("../")) localDirectory.set(file("./"))
remoteUrl.set(new URL("https://github.com/InsanusMokrassar/ktgbotapi")) remoteUrl.set(new URL("https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/"))
remoteLineSuffix.set("#L") remoteLineSuffix.set("#L")
} }
} }
@@ -76,3 +97,8 @@ Object callback = {
tasks.dokkaGfm(callback) tasks.dokkaGfm(callback)
tasks.dokkaHtml(callback) tasks.dokkaHtml(callback)
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -1 +1,3 @@
dokka_version=1.6.0
org.gradle.jvmargs=-Xmx1024m org.gradle.jvmargs=-Xmx1024m

View File

@@ -1,27 +0,0 @@
File templatesFolder = new File("$rootProject.projectDir.absolutePath${File.separatorChar}gradle${File.separatorChar}templates")
Map properties = new HashMap<String, String>()
if (templatesFolder.exists() && templatesFolder.isDirectory()) {
templatesFolder.listFiles().each {
properties[it.name - ".gradle"] = it.absolutePath
}
}
allprojects {
ext {
properties.forEach { k, v ->
it[k] = v
}
}
}
tasks.register("getPublishableModules") {
doLast {
rootProject.subprojects.each { project ->
if (project.plugins.hasPlugin('maven-publish')) {
println(":${project.name}")
}
}
}
}

View File

@@ -5,8 +5,19 @@ kotlin.js.generate.externals=true
kotlin.incremental=true kotlin.incremental=true
kotlin.incremental.js=true kotlin.incremental.js=true
# https://github.com/google/ksp/issues/2491 kotlin_version=1.6.10
ksp.useKSP2=false kotlin_coroutines_version=1.6.0
kotlin_serialisation_runtime_version=1.3.2
klock_version=2.4.10
uuid_version=0.3.1
ktor_version=1.6.7
micro_utils_version=0.9.1
javax_activation_version=1.1.1
library_group=dev.inmo library_group=dev.inmo
library_version=28.0.2 library_version=0.38.2
github_release_plugin_version=2.2.12

View File

@@ -1,90 +0,0 @@
[versions]
kotlin = "2.2.10"
kotlin-serialization = "1.9.0"
kotlin-coroutines = "1.10.2"
javax-activation = "1.1.1"
korlibs = "5.4.0"
uuid = "0.8.4"
ktor = "3.2.3"
ksp = "2.2.10-2.0.2"
kotlin-poet = "2.2.0"
microutils = "0.26.3"
kslog = "1.5.0"
versions = "0.52.0"
github-release-plugin = "2.5.2"
dokka = "2.0.0"
validator = "0.18.1"
nmcp = "1.1.0"
[libraries]
kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutines" }
kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlin-serialization" }
kotlin-serialization-properties = { module = "org.jetbrains.kotlinx:kotlinx-serialization-properties", version.ref = "kotlin-serialization" }
kotlin-test-common = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlin" }
kotlin-test-annotations-common = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" }
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
kotlin-test-js = { module = "org.jetbrains.kotlin:kotlin-test-js", version.ref = "kotlin" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor" }
ktor-client-winhttp = { module = "io.ktor:ktor-client-winhttp", version.ref = "ktor" }
ktor-server = { module = "io.ktor:ktor-server", version.ref = "ktor" }
ktor-server-host-common = { module = "io.ktor:ktor-server-host-common", version.ref = "ktor" }
javax-activation = { module = "javax.activation:activation", version.ref = "javax-activation" }
korlibs-klock = { module = "com.soywiz.korge:korlibs-time", version.ref = "korlibs" }
korlibs-krypto = { module = "com.soywiz.korge:korlibs-crypto", version.ref = "korlibs" }
uuid = { module = "com.benasher44:uuid", version.ref = "uuid" }
microutils-colors-common = { module = "dev.inmo:micro_utils.colors.common", version.ref = "microutils" }
microutils-coroutines = { module = "dev.inmo:micro_utils.coroutines", version.ref = "microutils" }
microutils-serialization-base64 = { module = "dev.inmo:micro_utils.serialization.base64", version.ref = "microutils" }
microutils-serialization-encapsulator = { module = "dev.inmo:micro_utils.serialization.encapsulator", version.ref = "microutils" }
microutils-serialization-typedSerializer = { module = "dev.inmo:micro_utils.serialization.typed_serializer", version.ref = "microutils" }
microutils-serialization-mapper = { module = "dev.inmo:micro_utils.serialization.mapper", version.ref = "microutils" }
microutils-languageCodes = { module = "dev.inmo:micro_utils.language_codes", version.ref = "microutils" }
microutils-ktor-common = { module = "dev.inmo:micro_utils.ktor.common", version.ref = "microutils" }
microutils-fsm-common = { module = "dev.inmo:micro_utils.fsm.common", version.ref = "microutils" }
microutils-ksp-generator = { module = "dev.inmo:micro_utils.ksp.generator", version.ref = "microutils" }
microutils-ksp-sealed = { module = "dev.inmo:micro_utils.ksp.sealed", version.ref = "microutils" }
microutils-ksp-sealed-generator = { module = "dev.inmo:micro_utils.ksp.sealed.generator", version.ref = "microutils" }
microutils-ksp-variations = { module = "dev.inmo:micro_utils.ksp.variations", version.ref = "microutils" }
microutils-ksp-variations-generator = { module = "dev.inmo:micro_utils.ksp.variations.generator", version.ref = "microutils" }
kslog = { module = "dev.inmo:kslog", version.ref = "kslog" }
# ksp dependencies
kotlin-poet = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlin-poet" }
ksp = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
# buildscript classpaths
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-ksp-plugin = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version.ref = "ksp" }
kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
kotlin-dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
github-release-plugin = { module = "com.github.breadmoirai:github-release", version.ref = "github-release-plugin" }
[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
versions = { id = "com.github.ben-manes.versions", version.ref = "versions" }
validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "validator" }
nmcp-aggregation = { id = "com.gradleup.nmcp.aggregation", version.ref = "nmcp" }

View File

@@ -1,34 +0,0 @@
project.version = "$version"
project.group = "$group"
apply from: "$mpp_publish"
kotlin {
compilerOptions {
freeCompilerArgs.add("-Xcontext-parameters")
}
js (IR) {
browser()
nodejs()
}
sourceSets {
commonMain {
dependencies {
implementation libs.kotlin
api libs.kotlin.serialization
}
}
commonTest {
dependencies {
implementation libs.kotlin.test.common
implementation libs.kotlin.test.annotations.common
}
}
jsTest {
dependencies {
implementation libs.kotlin.test.js
}
}
}
}

View File

@@ -1,60 +0,0 @@
project.version = "$library_version"
project.group = "$library_group"
kotlin {
compilerOptions {
freeCompilerArgs.add("-Xcontext-parameters")
}
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "17"
}
}
}
js (IR) {
browser()
nodejs()
}
linuxX64()
mingwX64()
linuxArm64()
sourceSets {
commonMain {
dependencies {
implementation libs.kotlin
api libs.kotlin.serialization
}
}
commonTest {
dependencies {
implementation libs.kotlin.test.common
implementation libs.kotlin.test.annotations.common
}
}
jvmTest {
dependencies {
implementation libs.kotlin.test.junit
}
}
jsTest {
dependencies {
implementation libs.kotlin.test.js
}
}
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 {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

View File

@@ -1,111 +0,0 @@
apply plugin: 'maven-publish'
task javadocsJar(type: Jar) {
archiveClassifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "${project.description}"
name = "${project.name}"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
}
repositories {
if ((project.hasProperty('GITHUB_USER') || System.getenv('GITHUB_USER') != null) && (project.hasProperty('GITHUB_TOKEN') || System.getenv('GITHUB_TOKEN') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/ktgbotapi")
credentials {
username = project.hasProperty('GITHUB_USER') ? project.property('GITHUB_USER') : System.getenv('GITHUB_USER')
password = project.hasProperty('GITHUB_TOKEN') ? project.property('GITHUB_TOKEN') : System.getenv('GITHUB_TOKEN')
}
}
}
if ((project.hasProperty('INMONEXUS_USER') || System.getenv('INMONEXUS_USER') != null) && (project.hasProperty('INMONEXUS_PASSWORD') || System.getenv('INMONEXUS_PASSWORD') != null)) {
maven {
name = "InmoNexus"
url = uri("https://nexus.inmo.dev/repository/maven-releases/")
credentials {
username = project.hasProperty('INMONEXUS_USER') ? project.property('INMONEXUS_USER') : System.getenv('INMONEXUS_USER')
password = project.hasProperty('INMONEXUS_PASSWORD') ? project.property('INMONEXUS_PASSWORD') : System.getenv('INMONEXUS_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/")
credentials {
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')
}
}
}
}
}
if (project.hasProperty("signing.gnupg.keyName")) {
apply plugin: 'signing'
signing {
useGpgCmd()
sign publishing.publications
}
task signAll {
tasks.withType(Sign).forEach {
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)
}
// Workaround to make test tasks use sign
project.getTasks().withType(Sign.class).configureEach { signTask ->
def withoutSign = (signTask.name.startsWith("sign") ? signTask.name.minus("sign") : signTask.name)
def pubName = withoutSign.endsWith("Publication") ? withoutSign.substring(0, withoutSign.length() - "Publication".length()) : withoutSign
// These tasks only exist for native targets, hence findByName() to avoid trying to find them for other targets
// Task ':linkDebugTest<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
def debugTestTask = tasks.findByName("linkDebugTest$pubName")
if (debugTestTask != null) {
signTask.mustRunAfter(debugTestTask)
}
// Task ':compileTestKotlin<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
def testTask = tasks.findByName("compileTestKotlin$pubName")
if (testTask != null) {
signTask.mustRunAfter(testTask)
}
}
}

View File

@@ -1 +0,0 @@
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"${project.description}","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/ktgbotapi","credsType":{"type":"dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository.CredentialsType.UsernameAndPassword","usernameProperty":"GITHUB_USER","passwordProperty":"GITHUB_TOKEN"}},{"name":"InmoNexus","url":"https://nexus.inmo.dev/repository/maven-releases/"},{"name":"sonatype","url":"https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"},"includeCentralSonatypeUploadingScript":false}}

View File

@@ -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-8.13-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip

Binary file not shown.

Before

Width:  |  Height:  |  Size: 448 KiB

View File

@@ -12,10 +12,13 @@ pluginManagement {
} }
include ":tgbotapi.core" include ":tgbotapi.core"
include ":tgbotapi.ksp"
include ":tgbotapi.api" include ":tgbotapi.api"
include ":tgbotapi.utils" include ":tgbotapi.utils"
include ":tgbotapi.behaviour_builder" include ":tgbotapi.behaviour_builder"
include ":tgbotapi.behaviour_builder.fsm" include ":tgbotapi.behaviour_builder.fsm"
include ":tgbotapi.extensions.api"
include ":tgbotapi.extensions.utils"
include ":tgbotapi.extensions.behaviour_builder"
include ":tgbotapi.extensions.behaviour_builder.fsm"
include ":tgbotapi" include ":tgbotapi"
include ":tgbotapi.webapps" include ":docs"

File diff suppressed because it is too large Load Diff

View File

@@ -1,31 +1,55 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}
plugins { plugins {
id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization" id "org.jetbrains.kotlin.plugin.serialization"
id "org.jetbrains.dokka"
id "com.google.devtools.ksp"
} }
project.description = "API extensions with \"Telegram Bot API\"-like extensions for TelegramBot and RequestsExecutor" project.version = "$library_version"
project.group = "$library_group"
apply from: "$mppProjectWithSerialization" apply from: "publish.gradle"
apply from: "$mpp_publish"
repositories {
mavenLocal()
mavenCentral()
}
kotlin { kotlin {
jvm {
compilations.main {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
nodejs()
}
sourceSets { sourceSets {
commonMain { commonMain {
dependencies { dependencies {
implementation kotlin('stdlib')
api project(":tgbotapi.core") api project(":tgbotapi.core")
api libs.microutils.ksp.variations
} }
} }
configureEach {
languageSettings.optIn("kotlinx.serialization.ExperimentalSerializationApi")
}
} }
explicitApi()
} }
dependencies { java {
add("kspCommonMainMetadata", libs.microutils.ksp.variations.generator) sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
} }

View File

@@ -0,0 +1,79 @@
apply plugin: 'maven-publish'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference"
name = "Telegram Bot API Extensions for API"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
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')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
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')
}
}
}
}
}
}
if (project.hasProperty("signing.gnupg.keyName")) {
apply plugin: 'signing'
signing {
useGpgCmd()
sign publishing.publications
}
task signAll {
tasks.withType(Sign).forEach {
dependsOn(it)
}
}
}

View File

@@ -0,0 +1 @@
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Extensions for API","description":"API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}

View File

@@ -12,11 +12,10 @@ import io.ktor.client.engine.*
* @param ktorClientEngine Engine like [io.ktor.client.engine.cio.CIO] * @param ktorClientEngine Engine like [io.ktor.client.engine.cio.CIO]
* @param ktorClientConfig Config block for preconfiguring of bot [HttpClient] * @param ktorClientConfig Config block for preconfiguring of bot [HttpClient]
*/ */
@ConsistentCopyVisibility data class BotBuilder internal constructor(
public data class BotBuilder internal constructor(
var proxy: ProxyConfig? = null, var proxy: ProxyConfig? = null,
var ktorClientEngineFactory: HttpClientEngineFactory<HttpClientEngineConfig>? = null, var ktorClientEngineFactory: HttpClientEngineFactory<HttpClientEngineConfig>? = null,
var ktorClientConfig: (HttpClientConfig<*>.() -> Unit) ? = null, var ktorClientConfig: (HttpClientConfig<*>.() -> Unit) ? = null
) { ) {
internal fun createHttpClient(): HttpClient = ktorClientEngineFactory ?.let { internal fun createHttpClient(): HttpClient = ktorClientEngineFactory ?.let {
HttpClient( HttpClient(
@@ -38,18 +37,11 @@ public data class BotBuilder internal constructor(
* @return Created by [telegramBotWithCustomClientConfig] function [TelegramBot]. This executor will be preconfigured using [token] and * @return Created by [telegramBotWithCustomClientConfig] function [TelegramBot]. This executor will be preconfigured using [token] and
* [block] * [block]
*/ */
public fun buildBot( fun buildBot(
token: String, token: String,
apiUrl: String = telegramBotAPIDefaultUrl, apiUrl: String = telegramBotAPIDefaultUrl,
testServer: Boolean = false,
fileLinkUrlMapper: TelegramAPIUrlsKeeper.(String) -> String = { "${fileBaseUrl}/$it" },
block: BotBuilder.() -> Unit block: BotBuilder.() -> Unit
): TelegramBot = telegramBot( ) = telegramBot(
urlsKeeper = TelegramAPIUrlsKeeper( TelegramAPIUrlsKeeper(token, apiUrl),
token = token, BotBuilder().apply(block).createHttpClient()
testServer = testServer,
hostUrl = apiUrl,
fileLinkUrlMapper = fileLinkUrlMapper
),
client = BotBuilder().apply(block).createHttpClient()
) )

View File

@@ -1,6 +1,6 @@
package dev.inmo.tgbotapi.extensions.api package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.ktor.telegramBot import dev.inmo.tgbotapi.bot.Ktor.telegramBot
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
@@ -11,9 +11,9 @@ import io.ktor.client.engine.*
/** /**
* Allows to create bot using bot [urlsKeeper] and already prepared [client] * Allows to create bot using bot [urlsKeeper] and already prepared [client]
*/ */
public fun telegramBot( fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper, urlsKeeper: TelegramAPIUrlsKeeper,
client: HttpClient = HttpClient() client: HttpClient
): TelegramBot = telegramBot(urlsKeeper) { ): TelegramBot = telegramBot(urlsKeeper) {
this.client = client this.client = client
} }
@@ -23,11 +23,11 @@ public fun telegramBot(
* configure it with [clientConfig] * configure it with [clientConfig]
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
public inline fun <T: HttpClientEngineConfig> telegramBot( inline fun <T: HttpClientEngineConfig> telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper, urlsKeeper: TelegramAPIUrlsKeeper,
clientFactory: HttpClientEngineFactory<T>, clientFactory: HttpClientEngineFactory<T>,
noinline clientConfig: HttpClientConfig<T>.() -> Unit = {} noinline clientConfig: HttpClientConfig<T>.() -> Unit = {}
): TelegramBot = telegramBot( ) = telegramBot(
urlsKeeper, urlsKeeper,
HttpClient(clientFactory, clientConfig) HttpClient(clientFactory, clientConfig)
) )
@@ -37,11 +37,11 @@ public inline fun <T: HttpClientEngineConfig> telegramBot(
* configure [HttpClient] using [clientConfig] * configure [HttpClient] using [clientConfig]
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
public inline fun telegramBot( inline fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper, urlsKeeper: TelegramAPIUrlsKeeper,
clientEngine: HttpClientEngine, clientEngine: HttpClientEngine,
noinline clientConfig: HttpClientConfig<*>.() -> Unit = {} noinline clientConfig: HttpClientConfig<*>.() -> Unit = {}
): TelegramBot = telegramBot( ) = telegramBot(
urlsKeeper, urlsKeeper,
HttpClient(clientEngine, clientConfig) HttpClient(clientEngine, clientConfig)
) )
@@ -51,10 +51,10 @@ public inline fun telegramBot(
* [clientConfig] * [clientConfig]
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
public inline fun telegramBot( inline fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper, urlsKeeper: TelegramAPIUrlsKeeper,
noinline clientConfig: HttpClientConfig<*>.() -> Unit noinline clientConfig: HttpClientConfig<*>.() -> Unit
): TelegramBot = telegramBot( ) = telegramBot(
urlsKeeper, urlsKeeper,
HttpClient(clientConfig) HttpClient(clientConfig)
) )
@@ -63,24 +63,20 @@ public inline fun telegramBot(
* Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client] * Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client]
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
public fun telegramBot( inline fun telegramBot(
token: String, token: String,
apiUrl: String = telegramBotAPIDefaultUrl, apiUrl: String = telegramBotAPIDefaultUrl,
testServer: Boolean = false, client: HttpClient
fileLinkUrlMapper: TelegramAPIUrlsKeeper.(String) -> String = { "${fileBaseUrl}/$it" }, ): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client)
client: HttpClient = HttpClient()
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, testServer, apiUrl, fileLinkUrlMapper), client)
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
public fun <T: HttpClientEngineConfig> telegramBot( inline fun <T: HttpClientEngineConfig> telegramBot(
token: String, token: String,
clientFactory: HttpClientEngineFactory<T>, clientFactory: HttpClientEngineFactory<T>,
apiUrl: String = telegramBotAPIDefaultUrl, apiUrl: String = telegramBotAPIDefaultUrl,
testServer: Boolean = false, noinline clientConfig: HttpClientConfig<T>.() -> Unit = {}
fileLinkUrlMapper: TelegramAPIUrlsKeeper.(String) -> String = { "${fileBaseUrl}/$it" }, ) = telegramBot(
clientConfig: HttpClientConfig<T>.() -> Unit = {} TelegramAPIUrlsKeeper(token, apiUrl),
): TelegramBot = telegramBot(
TelegramAPIUrlsKeeper(token, testServer, apiUrl, fileLinkUrlMapper),
clientFactory, clientFactory,
clientConfig clientConfig
) )
@@ -89,15 +85,14 @@ public fun <T: HttpClientEngineConfig> telegramBot(
* Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally * Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
* configure [HttpClient] using [clientConfig] * configure [HttpClient] using [clientConfig]
*/ */
public fun telegramBot( @Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
token: String, token: String,
clientEngine: HttpClientEngine, clientEngine: HttpClientEngine,
apiUrl: String = telegramBotAPIDefaultUrl, apiUrl: String = telegramBotAPIDefaultUrl,
testServer: Boolean = false, noinline clientConfig: HttpClientConfig<*>.() -> Unit = {}
fileLinkUrlMapper: TelegramAPIUrlsKeeper.(String) -> String = { "${fileBaseUrl}/$it" }, ) = telegramBot(
clientConfig: HttpClientConfig<*>.() -> Unit = {} TelegramAPIUrlsKeeper(token, apiUrl),
): TelegramBot = telegramBot(
TelegramAPIUrlsKeeper(token, testServer, apiUrl, fileLinkUrlMapper),
clientEngine, clientEngine,
clientConfig clientConfig
) )
@@ -106,13 +101,12 @@ public fun telegramBot(
* Allows to create bot using bot [token] and [apiUrl] and specify [HttpClientEngine] by configuring [HttpClient] using * Allows to create bot using bot [token] and [apiUrl] and specify [HttpClientEngine] by configuring [HttpClient] using
* [clientConfig] * [clientConfig]
*/ */
public fun telegramBot( @Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
token: String, token: String,
apiUrl: String = telegramBotAPIDefaultUrl, apiUrl: String = telegramBotAPIDefaultUrl,
testServer: Boolean = false, noinline clientConfig: HttpClientConfig<*>.() -> Unit
fileLinkUrlMapper: TelegramAPIUrlsKeeper.(String) -> String = { "${fileBaseUrl}/$it" }, ) = telegramBot(
clientConfig: HttpClientConfig<*>.() -> Unit TelegramAPIUrlsKeeper(token, apiUrl),
): TelegramBot = telegramBot(
TelegramAPIUrlsKeeper(token, testServer, apiUrl, fileLinkUrlMapper),
clientConfig clientConfig
) )

View File

@@ -3,4 +3,5 @@ package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.local.Close import dev.inmo.tgbotapi.requests.local.Close
public suspend inline fun TelegramBot.executeClose(): Boolean = execute(Close) @Suppress("unused")
suspend inline fun TelegramBot.close() = execute(Close)

View File

@@ -3,51 +3,26 @@ package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.DeleteMessage import dev.inmo.tgbotapi.requests.DeleteMessage
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.content.MediaGroupCollectionContent
public suspend fun TelegramBot.deleteMessage( suspend fun TelegramBot.deleteMessage(
chatId: ChatIdentifier, chatId: ChatIdentifier,
messageId: MessageId messageId: MessageIdentifier
): Boolean = execute( ) = execute(
DeleteMessage(chatId, messageId) DeleteMessage(chatId, messageId)
) )
public suspend fun TelegramBot.deleteMessage( suspend fun TelegramBot.deleteMessage(
chat: Chat, chat: Chat,
messageId: MessageId messageId: MessageIdentifier
): Boolean = deleteMessage(chat.id, messageId) ) = deleteMessage(chat.id, messageId)
public suspend fun TelegramBot.deleteMessage( suspend fun TelegramBot.deleteMessage(
message: AccessibleMessage message: Message
): Boolean { ) = deleteMessage(message.chat, message.messageId)
val mediaGroupContent = ((message as? ContentMessage<*>) ?.content as? MediaGroupCollectionContent<*>)
if (mediaGroupContent == null) {
return deleteMessage(message.chat, message.messageId)
} else {
return mediaGroupContent.group.map {
deleteMessage(it.sourceMessage)
}.all { it }
}
}
public suspend fun TelegramBot.delete( suspend fun Message.delete(
chatId: ChatIdentifier,
messageId: MessageId
): Boolean = deleteMessage(chatId, messageId)
public suspend fun TelegramBot.delete(
chat: Chat,
messageId: MessageId
): Boolean = deleteMessage(chat, messageId)
public suspend fun TelegramBot.delete(
message: AccessibleMessage
): Boolean = deleteMessage(message)
public suspend fun AccessibleMessage.delete(
requestsExecutor: TelegramBot requestsExecutor: TelegramBot
): Boolean = requestsExecutor.deleteMessage(this) ) = requestsExecutor.deleteMessage(this)

View File

@@ -1,61 +0,0 @@
package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.DeleteMessages
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import kotlin.jvm.JvmName
public suspend fun TelegramBot.deleteMessages(
chatId: ChatIdentifier,
messageIds: List<MessageId>
): Boolean = messageIds.chunked(deleteMessagesLimit.last).map {
execute(
DeleteMessages(
chatId = chatId,
messageIds = it
)
)
}.all { it }
public suspend fun TelegramBot.deleteMessages(
chatId: ChatIdentifier,
messageIds: Array<MessageId>
): Boolean = deleteMessages(
chatId = chatId,
messageIds = messageIds.toList()
)
public suspend fun TelegramBot.deleteMessages(
messagesMetas: List<Message.MetaInfo>
): Boolean = messagesMetas.groupBy { it.chatId }.map { (chatId, messages) ->
deleteMessages(
chatId = chatId,
messageIds = messages.map { it.messageId }
)
}.all { it }
@JvmName("deleteMessagesWithMessages")
public suspend fun TelegramBot.deleteMessages(
messages: List<AccessibleMessage>
): Boolean = deleteMessages(messages.map { it.metaInfo })
public suspend fun TelegramBot.delete(
chatId: ChatIdentifier,
messageIds: List<MessageId>
): Boolean = deleteMessages(chatId = chatId, messageIds = messageIds)
public suspend fun TelegramBot.delete(
chatId: ChatIdentifier,
messageIds: Array<MessageId>
): Boolean = deleteMessages(chatId = chatId, messageIds = messageIds)
public suspend fun TelegramBot.delete(
messagesMetas: List<Message.MetaInfo>
): Boolean = deleteMessages(messagesMetas)
@JvmName("deleteWithMessages")
public suspend fun TelegramBot.delete(
messages: List<AccessibleMessage>
): Boolean = deleteMessages(messages)

View File

@@ -3,70 +3,54 @@ package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.ForwardMessage import dev.inmo.tgbotapi.requests.ForwardMessage
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.Seconds import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage
import dev.inmo.tgbotapi.types.threadId
public suspend fun TelegramBot.forwardMessage( suspend fun TelegramBot.forwardMessage(
fromChatId: ChatIdentifier, fromChatId: ChatIdentifier,
toChatId: ChatIdentifier, toChatId: ChatIdentifier,
messageId: MessageId, messageId: MessageIdentifier,
threadId: MessageThreadId? = toChatId.threadId,
startTimestamp: Seconds? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false protectContent: Boolean = false
): PossiblyForwardedMessage = execute( ) = execute(
ForwardMessage(fromChatId, toChatId, messageId, threadId, startTimestamp, disableNotification, protectContent) ForwardMessage(fromChatId, toChatId, messageId, disableNotification, protectContent)
) )
public suspend fun TelegramBot.forwardMessage( suspend fun TelegramBot.forwardMessage(
fromChat: Chat, fromChat: Chat,
toChatId: ChatIdentifier, toChatId: ChatIdentifier,
messageId: MessageId, messageId: MessageIdentifier,
threadId: MessageThreadId? = toChatId.threadId,
startTimestamp: Seconds? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false protectContent: Boolean = false
): PossiblyForwardedMessage = forwardMessage(fromChat.id, toChatId, messageId, threadId, startTimestamp, disableNotification, protectContent) ) = forwardMessage(fromChat.id, toChatId, messageId, disableNotification, protectContent)
public suspend fun TelegramBot.forwardMessage( suspend fun TelegramBot.forwardMessage(
fromChatId: ChatIdentifier, fromChatId: ChatIdentifier,
toChat: Chat, toChat: Chat,
messageId: MessageId, messageId: MessageIdentifier,
threadId: MessageThreadId? = toChat.id.threadId,
startTimestamp: Seconds? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false protectContent: Boolean = false
): PossiblyForwardedMessage = forwardMessage(fromChatId, toChat.id, messageId, threadId, startTimestamp, disableNotification, protectContent) ) = forwardMessage(fromChatId, toChat.id, messageId, disableNotification, protectContent)
public suspend fun TelegramBot.forwardMessage( suspend fun TelegramBot.forwardMessage(
fromChat: Chat, fromChat: Chat,
toChat: Chat, toChat: Chat,
messageId: MessageId, messageId: MessageIdentifier,
threadId: MessageThreadId? = toChat.id.threadId,
startTimestamp: Seconds? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false protectContent: Boolean = false
): PossiblyForwardedMessage = forwardMessage(fromChat.id, toChat.id, messageId, threadId, startTimestamp, disableNotification, protectContent) ) = forwardMessage(fromChat.id, toChat.id, messageId, disableNotification, protectContent)
public suspend fun TelegramBot.forwardMessage( suspend fun TelegramBot.forwardMessage(
toChatId: ChatIdentifier, toChatId: ChatIdentifier,
message: AccessibleMessage, message: Message,
threadId: MessageThreadId? = toChatId.threadId,
startTimestamp: Seconds? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false protectContent: Boolean = false
): PossiblyForwardedMessage = forwardMessage(message.chat, toChatId, message.messageId, threadId, startTimestamp, disableNotification, protectContent) ) = forwardMessage(message.chat, toChatId, message.messageId, disableNotification, protectContent)
public suspend fun TelegramBot.forwardMessage( suspend fun TelegramBot.forwardMessage(
toChat: Chat, toChat: Chat,
message: AccessibleMessage, message: Message,
threadId: MessageThreadId? = toChat.id.threadId,
startTimestamp: Seconds? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false protectContent: Boolean = false
): PossiblyForwardedMessage = forwardMessage(message.chat, toChat, message.messageId, threadId, startTimestamp, disableNotification, protectContent) ) = forwardMessage(message.chat, toChat, message.messageId, disableNotification, protectContent)

View File

@@ -1,154 +0,0 @@
package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.send.copyMessages
import dev.inmo.tgbotapi.requests.ForwardMessages
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import kotlin.jvm.JvmName
public suspend fun TelegramBot.forwardMessages(
toChatId: ChatIdentifier,
fromChatId: ChatIdentifier,
messageIds: List<MessageId>,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
): List<MessageId> = messageIds.chunked(forwardMessagesLimit.last).flatMap {
execute(
ForwardMessages(
toChatId = toChatId,
fromChatId = fromChatId,
messageIds = it,
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)
)
}
public suspend fun TelegramBot.forwardMessages(
toChatId: ChatIdentifier,
fromChatId: ChatIdentifier,
messageIds: Array<MessageId>,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
): List<MessageId> = forwardMessages(
toChatId = toChatId,
fromChatId = fromChatId,
messageIds = messageIds.toList(),
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)
public suspend fun TelegramBot.forwardMessages(
toChatId: ChatIdentifier,
messagesMetas: List<Message.MetaInfo>,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
): List<MessageId> = messagesMetas.groupBy { it.chatId }.flatMap { (chatId, messages) ->
forwardMessages(
toChatId = toChatId,
fromChatId = chatId,
messageIds = messages.map { it.messageId },
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)
}
@JvmName("forwardMessagesWithMessages")
public suspend fun TelegramBot.forwardMessages(
toChatId: ChatIdentifier,
messages: List<AccessibleMessage>,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
): List<MessageId> = forwardMessages(
toChatId = toChatId,
messagesMetas = messages.map { it.metaInfo },
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)
public suspend fun TelegramBot.forward(
toChatId: ChatIdentifier,
fromChatId: ChatIdentifier,
messageIds: List<MessageId>,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
): List<MessageId> = forwardMessages(
toChatId = toChatId,
fromChatId = fromChatId,
messageIds = messageIds,
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)
public suspend fun TelegramBot.forward(
toChatId: ChatIdentifier,
fromChatId: ChatIdentifier,
messageIds: Array<MessageId>,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
): List<MessageId> = forwardMessages(
toChatId = toChatId,
fromChatId = fromChatId,
messageIds = messageIds,
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)
public suspend fun TelegramBot.forward(
toChatId: ChatIdentifier,
messagesMetas: List<Message.MetaInfo>,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
): List<MessageId> = forwardMessages(
toChatId = toChatId,
messagesMetas = messagesMetas,
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)
@JvmName("forwardWithMessages")
public suspend fun TelegramBot.forward(
toChatId: ChatIdentifier,
messages: List<AccessibleMessage>,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
): List<MessageId> = forwardMessages(
toChatId = toChatId,
messages = messages,
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)

View File

@@ -5,22 +5,22 @@ import dev.inmo.tgbotapi.requests.GetUpdates
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.Update
public suspend fun TelegramBot.getUpdates( suspend fun TelegramBot.getUpdates(
offset: UpdateId? = null, offset: UpdateIdentifier? = null,
limit: Int = getUpdatesLimit.last, limit: Int = getUpdatesLimit.last,
timeout: Seconds? = null, timeout: Seconds? = null,
allowed_updates: List<String>? = ALL_UPDATES_LIST allowed_updates: List<String>? = ALL_UPDATES_LIST
): List<Update> = execute( ) = execute(
GetUpdates( GetUpdates(
offset, limit, timeout, allowed_updates offset, limit, timeout, allowed_updates
) )
) )
public suspend fun TelegramBot.getUpdates( suspend fun TelegramBot.getUpdates(
lastUpdate: Update, lastUpdate: Update,
limit: Int = getUpdatesLimit.last, limit: Int = getUpdatesLimit.last,
timeout: Seconds? = null, timeout: Seconds? = null,
allowed_updates: List<String>? = ALL_UPDATES_LIST allowed_updates: List<String>? = ALL_UPDATES_LIST
): List<Update> = getUpdates( ) = getUpdates(
lastUpdate.updateId + 1, limit, timeout, allowed_updates lastUpdate.updateId + 1, limit, timeout, allowed_updates
) )

View File

@@ -1,27 +0,0 @@
package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.GetUpdatesRaw
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.update.abstracts.Update
import kotlinx.serialization.json.JsonArray
public suspend fun TelegramBot.getRawUpdates(
offset: UpdateId? = null,
limit: Int = getUpdatesLimit.last,
timeout: Seconds? = null,
allowed_updates: List<String>? = ALL_UPDATES_LIST
): JsonArray = execute(
GetUpdatesRaw(
offset, limit, timeout, allowed_updates
)
)
public suspend fun TelegramBot.getRawUpdates(
lastUpdate: Update,
limit: Int = getUpdatesLimit.last,
timeout: Seconds? = null,
allowed_updates: List<String>? = ALL_UPDATES_LIST
): JsonArray = getRawUpdates(
lastUpdate.updateId + 1, limit, timeout, allowed_updates
)

View File

@@ -1,52 +1,70 @@
package dev.inmo.tgbotapi.extensions.api.InternalUtils package dev.inmo.tgbotapi.extensions.api.InternalUtils
import dev.inmo.tgbotapi.types.MediaGroupId import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.*
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.*
import dev.inmo.tgbotapi.types.update.abstracts.* import dev.inmo.tgbotapi.types.update.abstracts.*
import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage
/** internal fun Update.lastUpdateIdentifier(): UpdateIdentifier {
* Will convert incoming list of updates to list with [MediaGroupUpdate]s return if (this is SentMediaGroupUpdate) {
*/ origins.last().updateId
} else {
updateId
}
}
internal fun List<Update>.lastUpdateIdentifier(): UpdateIdentifier? {
return maxByOrNull { it.updateId } ?.lastUpdateIdentifier()
}
internal fun List<Update>.convertWithMediaGroupUpdates(): List<Update> { internal fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
val resultUpdates = mutableListOf<Update>() val resultUpdates = mutableListOf<Update>()
val mediaGroups = mutableMapOf<MediaGroupId, MutableList<Pair<BaseSentMessageUpdate, PossiblySentViaBotCommonMessage<MediaGroupPartContent>>>>() val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseSentMessageUpdate>>()
for (update in this) { for (update in this) {
val message = (update.data as? PossiblySentViaBotCommonMessage<*>) ?.let { val data = (update.data as? MediaGroupMessage<*>)
if (it.content is MediaGroupPartContent) { if (data == null) {
@Suppress("UNCHECKED_CAST")
it as PossiblySentViaBotCommonMessage<MediaGroupPartContent>
} else {
null
}
}
val mediaGroupId = message ?.mediaGroupId
if (message == null || mediaGroupId == null) {
resultUpdates.add(update) resultUpdates.add(update)
continue continue
} }
when (update) { when (update) {
is BaseEditMessageUpdate -> resultUpdates.add(
update.toEditMediaGroupUpdate()
)
is BaseSentMessageUpdate -> { is BaseSentMessageUpdate -> {
mediaGroups.getOrPut(mediaGroupId) { mediaGroups.getOrPut(data.mediaGroupId) {
mutableListOf() mutableListOf()
}.add(update to message) }.add(update)
} }
else -> resultUpdates.add(update) else -> resultUpdates.add(update)
} }
} }
mediaGroups.values.map {
mediaGroups.map { (_, updatesWithMessages) -> it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate ->
val update = updatesWithMessages.maxBy { it.first.updateId }.first resultUpdates.add(mediaGroupUpdate)
resultUpdates.add( }
update.copy(updatesWithMessages.map { it.second }.asMediaGroupMessage())
)
} }
resultUpdates.sortBy { it.updateId } resultUpdates.sortBy { it.updateId }
return resultUpdates return resultUpdates
} }
internal fun BaseEditMessageUpdate.toEditMediaGroupUpdate(): BaseEditMessageUpdate = this internal fun List<BaseSentMessageUpdate>.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let {
if (isEmpty()) {
return@let null
}
val resultList = sortedBy { it.updateId }
when (first()) {
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList)
else -> null
}
}
internal fun BaseEditMessageUpdate.toEditMediaGroupUpdate(): EditMediaGroupUpdate = (this as? EditMediaGroupUpdate) ?: let {
when (this) {
is EditMessageUpdate -> EditMessageMediaGroupUpdate(this)
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this)
else -> error("Unsupported type of ${BaseEditMessageUpdate::class.simpleName}")
}
}

View File

@@ -1,197 +0,0 @@
package dev.inmo.tgbotapi.extensions.api
import dev.inmo.micro_utils.coroutines.LinkedSupervisorScope
import dev.inmo.tgbotapi.abstracts.Headed
import dev.inmo.tgbotapi.abstracts.HorizontallyAccured
import dev.inmo.tgbotapi.abstracts.Locationed
import dev.inmo.tgbotapi.abstracts.ProximityAlertable
import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.edit.edit
import dev.inmo.tgbotapi.extensions.api.send.send
import dev.inmo.tgbotapi.extensions.api.send.sendLiveLocation
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.location.LiveLocation
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
import dev.inmo.tgbotapi.types.message.content.LocationContent
import dev.inmo.tgbotapi.utils.launchWithBotLogger
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.isActive
import kotlinx.serialization.Serializable
import kotlin.js.JsName
import kotlin.jvm.JvmName
import kotlin.math.ceil
@Serializable
public data class EditLiveLocationInfo(
override val latitude: Double,
override val longitude: Double,
override val horizontalAccuracy: Meters? = null,
override val heading: Degrees? = null,
override val proximityAlertRadius: Meters? = null,
override val replyMarkup: InlineKeyboardMarkup? = null
) : Locationed, HorizontallyAccured, ProximityAlertable, Headed, WithReplyMarkup
/**
* Will [sendLiveLocation] with the first [EditLiveLocationInfo] data and update than. Each [liveTimeMillis] passing,
* the message will be sent again and new edits will be applied to the new message
*/
public suspend fun TelegramBot.handleLiveLocation(
chatId: ChatIdentifier,
locationsFlow: Flow<EditLiveLocationInfo>,
liveTimeMillis: Long = defaultLivePeriodDelayMillis,
threadId: MessageThreadId? = chatId.threadId,
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowPaidBroadcast: Boolean = false,
effectId: EffectId? = null,
replyParameters: ReplyParameters? = null,
sentMessageFlow: FlowCollector<ContentMessage<LiveLocationContent>>? = null
) {
var currentLiveLocationMessage: ContentMessage<LiveLocationContent>? = null
val updateMessageJob = if (liveTimeMillis == indefiniteLivePeriodDelayMillis) { // do not launch refreshing of message for indefinite live locations
null
} else {
val scope = currentCoroutineContext().LinkedSupervisorScope()
scope.launchWithBotLogger(start = CoroutineStart.LAZY) {
while (scope.isActive) {
delay(liveTimeMillis)
// Remove previous location message info to resend live location message
currentLiveLocationMessage = null
}
}
}
locationsFlow.collect {
val capturedLiveLocationMessage = currentLiveLocationMessage
if (capturedLiveLocationMessage == null) {
updateMessageJob ?.start()
currentLiveLocationMessage = send(
chatId,
it.latitude,
it.longitude,
if (liveTimeMillis == indefiniteLivePeriodDelayMillis) {
LiveLocation.INDEFINITE_LIVE_PERIOD
} else {
ceil(liveTimeMillis.toDouble() / 1000).toInt()
},
it.horizontalAccuracy,
it.heading,
it.proximityAlertRadius,
threadId,
businessConnectionId,
disableNotification,
protectContent,
allowPaidBroadcast,
effectId,
replyParameters,
it.replyMarkup
).also {
sentMessageFlow ?.emit(it)
}
} else {
edit(
message = capturedLiveLocationMessage,
latitude = it.latitude,
longitude = it.longitude,
horizontalAccuracy = it.horizontalAccuracy,
heading = it.heading,
proximityAlertRadius = it.proximityAlertRadius,
replyMarkup = it.replyMarkup
).also {
sentMessageFlow ?.emit(it)
}
}
}
}
/**
* Will apply [Flow.map] to the [locationsFlow] to create [EditLiveLocationInfo] and pass the result flow to the
* [handleLiveLocation] with [Flow] typed by [EditLiveLocationInfo]
*/
@JvmName("handleLiveLocationWithLocation")
@JsName("handleLiveLocationWithLocation")
public suspend fun TelegramBot.handleLiveLocation(
chatId: ChatIdentifier,
locationsFlow: Flow<Location>,
liveTimeMillis: Long = defaultLivePeriodDelayMillis,
threadId: MessageThreadId? = chatId.threadId,
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowPaidBroadcast: Boolean = false,
effectId: EffectId? = null,
replyParameters: ReplyParameters? = null,
sentMessageFlow: FlowCollector<ContentMessage<LiveLocationContent>>? = null
) {
handleLiveLocation(
chatId = chatId,
locationsFlow = locationsFlow.map {
EditLiveLocationInfo(
it.latitude,
it.longitude,
it.horizontalAccuracy,
(it as? LiveLocation) ?.heading,
(it as? LiveLocation) ?.proximityAlertRadius,
(it as? WithReplyMarkup) ?.replyMarkup as? InlineKeyboardMarkup
)
},
liveTimeMillis = liveTimeMillis,
threadId = threadId,
businessConnectionId = businessConnectionId,
disableNotification = disableNotification,
protectContent = protectContent,
allowPaidBroadcast = allowPaidBroadcast,
effectId = effectId,
replyParameters = replyParameters,
sentMessageFlow = sentMessageFlow
)
}
/**
* Will apply [Flow.map] to the [locationsFlow] to create [EditLiveLocationInfo] and pass the result flow to the
* [handleLiveLocation] with [Flow] typed by [EditLiveLocationInfo]
*/
@JvmName("handleLiveLocationWithLatLong")
@JsName("handleLiveLocationWithLatLong")
public suspend fun TelegramBot.handleLiveLocation(
chatId: ChatIdentifier,
locationsFlow: Flow<Pair<Double, Double>>,
liveTimeMillis: Long = defaultLivePeriodDelayMillis,
threadId: MessageThreadId? = chatId.threadId,
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowPaidBroadcast: Boolean = false,
effectId: EffectId? = null,
replyParameters: ReplyParameters? = null,
sentMessageFlow: FlowCollector<ContentMessage<LiveLocationContent>>? = null
) {
handleLiveLocation(
chatId = chatId,
locationsFlow = locationsFlow.map { (lat, long) ->
EditLiveLocationInfo(
lat,
long
)
},
liveTimeMillis = liveTimeMillis,
threadId = threadId,
businessConnectionId = businessConnectionId,
disableNotification = disableNotification,
protectContent = protectContent,
allowPaidBroadcast = allowPaidBroadcast,
effectId = effectId,
replyParameters = replyParameters,
sentMessageFlow = sentMessageFlow
)
}

View File

@@ -1,35 +1,31 @@
package dev.inmo.tgbotapi.extensions.api package dev.inmo.tgbotapi.extensions.api
import korlibs.time.DateTime import com.soywiz.klock.DateTime
import korlibs.time.TimeSpan import com.soywiz.klock.TimeSpan
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation import dev.inmo.tgbotapi.extensions.api.edit.LiveLocation.editLiveLocation
import dev.inmo.tgbotapi.extensions.api.edit.location.live.stopLiveLocation import dev.inmo.tgbotapi.extensions.api.edit.LiveLocation.stopLiveLocation
import dev.inmo.tgbotapi.requests.send.SendLiveLocation import dev.inmo.tgbotapi.requests.send.SendLiveLocation
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
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.abstracts.Chat
import dev.inmo.tgbotapi.types.location.LiveLocation import dev.inmo.tgbotapi.types.location.LiveLocation
import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.location.StaticLocation
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.LocationContent import dev.inmo.tgbotapi.types.message.content.LocationContent
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
import io.ktor.utils.io.core.Closeable import io.ktor.utils.io.core.Closeable
import korlibs.time.millisecondsLong
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlin.math.ceil import kotlin.math.ceil
public const val indefiniteLivePeriodDelayMillis: Long = LiveLocation.INDEFINITE_LIVE_PERIOD * 1000L val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L
public const val defaultLivePeriodDelayMillis: Long = indefiniteLivePeriodDelayMillis
/** /**
* @see startLiveLocation * @see startLiveLocation
*/ */
public class LiveLocationProvider internal constructor( class LiveLocationProvider internal constructor(
private val requestsExecutor: TelegramBot, private val requestsExecutor: TelegramBot,
scope: CoroutineScope, scope: CoroutineScope,
autoCloseTimeDelay: Double, autoCloseTimeDelay: Double,
@@ -41,23 +37,22 @@ public class LiveLocationProvider internal constructor(
} }
} }
private val autoCloseTime = DateTime.now() + TimeSpan(autoCloseTimeDelay) private val autoCloseTime = DateTime.now() + TimeSpan(autoCloseTimeDelay)
public val leftUntilCloseMillis: TimeSpan val leftUntilCloseMillis: TimeSpan
get() = autoCloseTime - DateTime.now() get() = autoCloseTime - DateTime.now()
public var isClosed: Boolean = false var isClosed: Boolean = false
private set private set
get() = field || leftUntilCloseMillis.millisecondsLong < 0L get() = field || leftUntilCloseMillis.millisecondsLong < 0L
public var message: ContentMessage<LocationContent> = initMessage private var message: ContentMessage<LocationContent> = initMessage
private set val lastLocation: LiveLocation
public val lastLocation: LiveLocation
get() = message.content.location as LiveLocation get() = message.content.location as LiveLocation
/** /**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] * @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that * as a builder for that
*/ */
public suspend fun updateLocation( suspend fun updateLocation(
location: LiveLocation, location: LiveLocation,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
): LiveLocation { ): LiveLocation {
@@ -65,7 +60,7 @@ public class LiveLocationProvider internal constructor(
message = requestsExecutor.editLiveLocation( message = requestsExecutor.editLiveLocation(
message, message,
location, location,
replyMarkup = replyMarkup replyMarkup
) )
return lastLocation return lastLocation
} else { } else {
@@ -86,7 +81,7 @@ public class LiveLocationProvider internal constructor(
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/ */
public suspend fun TelegramBot.startLiveLocation( suspend fun TelegramBot.startLiveLocation(
scope: CoroutineScope, scope: CoroutineScope,
chatId: ChatIdentifier, chatId: ChatIdentifier,
latitude: Double, latitude: Double,
@@ -95,33 +90,27 @@ public suspend fun TelegramBot.startLiveLocation(
initHorizontalAccuracy: Meters? = null, initHorizontalAccuracy: Meters? = null,
initHeading: Degrees? = null, initHeading: Degrees? = null,
initProximityAlertRadius: Meters? = null, initProximityAlertRadius: Meters? = null,
threadId: MessageThreadId? = chatId.threadId,
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowPaidBroadcast: Boolean = false, replyToMessageId: MessageIdentifier? = null,
effectId: EffectId? = null, allowSendingWithoutReply: Boolean? = null,
replyParameters: ReplyParameters? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocationProvider { ): LiveLocationProvider {
val liveTimeAsDouble = liveTimeMillis.toDouble() val liveTimeAsDouble = liveTimeMillis.toDouble()
val locationMessage = execute( val locationMessage = execute(
SendLiveLocation( SendLiveLocation(
chatId = chatId, chatId,
latitude = latitude, latitude,
longitude = longitude, longitude,
livePeriod = ceil(liveTimeAsDouble / 1000).toInt(), ceil(liveTimeAsDouble / 1000).toInt(),
horizontalAccuracy = initHorizontalAccuracy, initHorizontalAccuracy,
heading = initHeading, initHeading,
proximityAlertRadius = initProximityAlertRadius, initProximityAlertRadius,
threadId = threadId, disableNotification,
businessConnectionId = businessConnectionId, protectContent,
disableNotification = disableNotification, replyToMessageId,
protectContent = protectContent, allowSendingWithoutReply,
allowPaidBroadcast = allowPaidBroadcast, replyMarkup
effectId = effectId,
replyParameters = replyParameters,
replyMarkup = replyMarkup
) )
) )
@@ -137,7 +126,7 @@ public suspend fun TelegramBot.startLiveLocation(
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/ */
public suspend fun TelegramBot.startLiveLocation( suspend fun TelegramBot.startLiveLocation(
scope: CoroutineScope, scope: CoroutineScope,
chat: Chat, chat: Chat,
latitude: Double, latitude: Double,
@@ -146,77 +135,65 @@ public suspend fun TelegramBot.startLiveLocation(
initHorizontalAccuracy: Meters? = null, initHorizontalAccuracy: Meters? = null,
initHeading: Degrees? = null, initHeading: Degrees? = null,
initProximityAlertRadius: Meters? = null, initProximityAlertRadius: Meters? = null,
threadId: MessageThreadId? = chat.id.threadId,
businessConnectionId: BusinessConnectionId? = chat.id.businessConnectionId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowPaidBroadcast: Boolean = false, replyToMessageId: MessageIdentifier? = null,
effectId: EffectId? = null, allowSendingWithoutReply: Boolean? = null,
replyParameters: ReplyParameters? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocationProvider = startLiveLocation( ): LiveLocationProvider = startLiveLocation(
scope = scope, scope,
chatId = chat.id, chat.id,
latitude = latitude, latitude,
longitude = longitude, longitude,
liveTimeMillis = liveTimeMillis, liveTimeMillis,
initHorizontalAccuracy = initHorizontalAccuracy, initHorizontalAccuracy,
initHeading = initHeading, initHeading,
initProximityAlertRadius = initProximityAlertRadius, initProximityAlertRadius,
threadId = threadId, disableNotification,
businessConnectionId = businessConnectionId, protectContent,
disableNotification = disableNotification, replyToMessageId,
protectContent = protectContent, allowSendingWithoutReply,
allowPaidBroadcast = allowPaidBroadcast, replyMarkup
effectId = effectId,
replyParameters = replyParameters,
replyMarkup = replyMarkup
) )
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/ */
public suspend fun TelegramBot.startLiveLocation( suspend fun TelegramBot.startLiveLocation(
scope: CoroutineScope, scope: CoroutineScope,
chatId: IdChatIdentifier, chatId: ChatId,
location: StaticLocation, location: StaticLocation,
liveTimeMillis: Long = defaultLivePeriodDelayMillis, liveTimeMillis: Long = defaultLivePeriodDelayMillis,
initHorizontalAccuracy: Meters? = null, initHorizontalAccuracy: Meters? = null,
initHeading: Degrees? = null, initHeading: Degrees? = null,
initProximityAlertRadius: Meters? = null, initProximityAlertRadius: Meters? = null,
threadId: MessageThreadId? = chatId.threadId,
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowPaidBroadcast: Boolean = false, replyToMessageId: MessageIdentifier? = null,
effectId: EffectId? = null, allowSendingWithoutReply: Boolean? = null,
replyParameters: ReplyParameters? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocationProvider = startLiveLocation( ): LiveLocationProvider = startLiveLocation(
scope = scope, scope,
chatId = chatId, chatId,
latitude = location.latitude, location.latitude,
longitude = location.longitude, location.longitude,
liveTimeMillis = liveTimeMillis, liveTimeMillis,
initHorizontalAccuracy = initHorizontalAccuracy, initHorizontalAccuracy,
initHeading = initHeading, initHeading,
initProximityAlertRadius = initProximityAlertRadius, initProximityAlertRadius,
threadId = threadId, disableNotification,
businessConnectionId = businessConnectionId, protectContent,
disableNotification = disableNotification, replyToMessageId,
protectContent = protectContent, allowSendingWithoutReply,
allowPaidBroadcast = allowPaidBroadcast, replyMarkup
effectId = effectId,
replyParameters = replyParameters,
replyMarkup = replyMarkup
) )
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/ */
public suspend fun TelegramBot.startLiveLocation( suspend fun TelegramBot.startLiveLocation(
scope: CoroutineScope, scope: CoroutineScope,
chat: Chat, chat: Chat,
location: StaticLocation, location: StaticLocation,
@@ -224,39 +201,33 @@ public suspend fun TelegramBot.startLiveLocation(
initHorizontalAccuracy: Meters? = null, initHorizontalAccuracy: Meters? = null,
initHeading: Degrees? = null, initHeading: Degrees? = null,
initProximityAlertRadius: Meters? = null, initProximityAlertRadius: Meters? = null,
threadId: MessageThreadId? = chat.id.threadId,
businessConnectionId: BusinessConnectionId? = chat.id.businessConnectionId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowPaidBroadcast: Boolean = false, replyToMessageId: MessageIdentifier? = null,
effectId: EffectId? = null, allowSendingWithoutReply: Boolean? = null,
replyParameters: ReplyParameters? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocationProvider = startLiveLocation( ): LiveLocationProvider = startLiveLocation(
scope = scope, scope,
chatId = chat.id, chat.id,
latitude = location.latitude, location.latitude,
longitude = location.longitude, location.longitude,
liveTimeMillis = liveTimeMillis, liveTimeMillis,
initHorizontalAccuracy = initHorizontalAccuracy, initHorizontalAccuracy,
initHeading = initHeading, initHeading,
initProximityAlertRadius = initProximityAlertRadius, initProximityAlertRadius,
threadId = threadId, disableNotification,
businessConnectionId = businessConnectionId, protectContent,
disableNotification = disableNotification, replyToMessageId,
protectContent = protectContent, allowSendingWithoutReply,
allowPaidBroadcast = allowPaidBroadcast, replyMarkup
effectId = effectId,
replyParameters = replyParameters,
replyMarkup = replyMarkup
) )
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/ */
public suspend inline fun TelegramBot.replyWithLiveLocation( suspend inline fun TelegramBot.replyWithLiveLocation(
to: AccessibleMessage, to: Message,
scope: CoroutineScope, scope: CoroutineScope,
latitude: Double, latitude: Double,
longitude: Double, longitude: Double,
@@ -264,67 +235,53 @@ public suspend inline fun TelegramBot.replyWithLiveLocation(
initHorizontalAccuracy: Meters? = null, initHorizontalAccuracy: Meters? = null,
initHeading: Degrees? = null, initHeading: Degrees? = null,
initProximityAlertRadius: Meters? = null, initProximityAlertRadius: Meters? = null,
threadId: MessageThreadId? = to.threadIdOrNull,
businessConnectionId: BusinessConnectionId? = to.businessConnectionId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowPaidBroadcast: Boolean = false,
effectId: EffectId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocationProvider = startLiveLocation( ) = startLiveLocation(
scope = scope, scope,
chat = to.chat, to.chat,
latitude = latitude, latitude,
longitude = longitude, longitude,
liveTimeMillis = liveTimeMillis, liveTimeMillis,
initHorizontalAccuracy = initHorizontalAccuracy, initHorizontalAccuracy,
initHeading = initHeading, initHeading,
initProximityAlertRadius = initProximityAlertRadius, initProximityAlertRadius,
threadId = threadId, disableNotification,
businessConnectionId = businessConnectionId, protectContent,
disableNotification = disableNotification, to.messageId,
protectContent = protectContent, allowSendingWithoutReply,
allowPaidBroadcast = allowPaidBroadcast, replyMarkup
effectId = effectId,
replyParameters = ReplyParameters(to.metaInfo, allowSendingWithoutReply = allowSendingWithoutReply),
replyMarkup = replyMarkup
) )
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param * [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/ */
public suspend inline fun TelegramBot.replyWithLiveLocation( suspend inline fun TelegramBot.replyWithLiveLocation(
to: AccessibleMessage, to: Message,
scope: CoroutineScope, scope: CoroutineScope,
location: StaticLocation, location: StaticLocation,
liveTimeMillis: Long = defaultLivePeriodDelayMillis, liveTimeMillis: Long = defaultLivePeriodDelayMillis,
initHorizontalAccuracy: Meters? = null, initHorizontalAccuracy: Meters? = null,
initHeading: Degrees? = null, initHeading: Degrees? = null,
initProximityAlertRadius: Meters? = null, initProximityAlertRadius: Meters? = null,
threadId: MessageThreadId? = to.threadIdOrNull,
businessConnectionId: BusinessConnectionId? = to.businessConnectionId,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowPaidBroadcast: Boolean = false,
effectId: EffectId? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocationProvider = startLiveLocation( ) = startLiveLocation(
scope = scope, scope,
chat = to.chat, to.chat,
location = location, location,
liveTimeMillis = liveTimeMillis, liveTimeMillis,
initHorizontalAccuracy = initHorizontalAccuracy, initHorizontalAccuracy,
initHeading = initHeading, initHeading,
initProximityAlertRadius = initProximityAlertRadius, initProximityAlertRadius,
threadId = threadId, disableNotification,
businessConnectionId = businessConnectionId, protectContent,
disableNotification = disableNotification, to.messageId,
protectContent = protectContent, allowSendingWithoutReply,
allowPaidBroadcast = allowPaidBroadcast, replyMarkup
effectId = effectId,
replyParameters = ReplyParameters(to.metaInfo, allowSendingWithoutReply = allowSendingWithoutReply),
replyMarkup = replyMarkup
) )

View File

@@ -3,4 +3,4 @@ package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.local.LogOut import dev.inmo.tgbotapi.requests.local.LogOut
public suspend inline fun TelegramBot.logOut(): Boolean = execute(LogOut) suspend inline fun TelegramBot.logOut() = execute(LogOut)

View File

@@ -3,54 +3,48 @@ package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.StopPoll import dev.inmo.tgbotapi.requests.StopPoll
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.polls.Poll
/** /**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] * @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that * as a builder for that
*/ */
public suspend fun TelegramBot.stopPoll( suspend fun TelegramBot.stopPoll(
chatId: ChatIdentifier, chatId: ChatIdentifier,
messageId: MessageId, messageId: MessageIdentifier,
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
): Poll = execute( ) = execute(
StopPoll(chatId, messageId, businessConnectionId, replyMarkup) StopPoll(chatId, messageId, replyMarkup)
) )
/** /**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] * @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that * as a builder for that
*/ */
public suspend fun TelegramBot.stopPoll( suspend fun TelegramBot.stopPoll(
chat: Chat, chat: Chat,
messageId: MessageId, messageId: MessageIdentifier,
businessConnectionId: BusinessConnectionId? = chat.id.businessConnectionId,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
): Poll = stopPoll(chat.id, messageId, businessConnectionId, replyMarkup) ) = stopPoll(chat.id, messageId, replyMarkup)
/** /**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] * @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that * as a builder for that
*/ */
public suspend fun TelegramBot.stopPoll( suspend fun TelegramBot.stopPoll(
chatId: IdChatIdentifier, chatId: ChatId,
message: AccessibleMessage, message: Message,
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
): Poll = stopPoll(chatId, message.messageId, businessConnectionId, replyMarkup) ) = stopPoll(chatId, message.messageId, replyMarkup)
/** /**
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] * @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
* as a builder for that * as a builder for that
*/ */
public suspend fun TelegramBot.stopPoll( suspend fun TelegramBot.stopPoll(
chat: Chat, chat: Chat,
message: AccessibleMessage, message: Message,
businessConnectionId: BusinessConnectionId? = chat.id.businessConnectionId,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
): Poll = stopPoll(chat.id, message.messageId, businessConnectionId, replyMarkup) ) = stopPoll(chat.id, message.messageId, replyMarkup)

View File

@@ -2,29 +2,29 @@ package dev.inmo.tgbotapi.extensions.api.answers
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.answers.AnswerCallbackQuery import dev.inmo.tgbotapi.requests.answers.AnswerCallbackQuery
import dev.inmo.tgbotapi.types.queries.callback.CallbackQuery import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery
import dev.inmo.tgbotapi.types.CallbackQueryId import dev.inmo.tgbotapi.types.CallbackQueryIdentifier
public suspend fun TelegramBot.answerCallbackQuery( suspend fun TelegramBot.answerCallbackQuery(
callbackQueryId: CallbackQueryId, callbackQueryId: CallbackQueryIdentifier,
text: String? = null, text: String? = null,
showAlert: Boolean? = null, showAlert: Boolean? = null,
url: String? = null, url: String? = null,
cachedTimeSeconds: Int? = null cachedTimeSeconds: Int? = null
): Boolean = execute(AnswerCallbackQuery(callbackQueryId, text, showAlert, url, cachedTimeSeconds)) ) = execute(AnswerCallbackQuery(callbackQueryId, text, showAlert, url, cachedTimeSeconds))
public suspend fun TelegramBot.answerCallbackQuery( suspend fun TelegramBot.answerCallbackQuery(
callbackQuery: CallbackQuery, callbackQuery: CallbackQuery,
text: String? = null, text: String? = null,
showAlert: Boolean? = null, showAlert: Boolean? = null,
url: String? = null, url: String? = null,
cachedTimeSeconds: Int? = null cachedTimeSeconds: Int? = null
): Boolean = answerCallbackQuery(callbackQuery.id, text, showAlert, url, cachedTimeSeconds) ) = answerCallbackQuery(callbackQuery.id, text, showAlert, url, cachedTimeSeconds)
public suspend fun TelegramBot.answer( suspend fun TelegramBot.answer(
callbackQuery: CallbackQuery, callbackQuery: CallbackQuery,
text: String? = null, text: String? = null,
showAlert: Boolean? = null, showAlert: Boolean? = null,
url: String? = null, url: String? = null,
cachedTimeSeconds: Int? = null cachedTimeSeconds: Int? = null
): Boolean = answerCallbackQuery(callbackQuery.id, text, showAlert, url, cachedTimeSeconds) ) = answerCallbackQuery(callbackQuery.id, text, showAlert, url, cachedTimeSeconds)

View File

@@ -2,68 +2,38 @@ package dev.inmo.tgbotapi.extensions.api.answers
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.answers.AnswerInlineQuery import dev.inmo.tgbotapi.requests.answers.AnswerInlineQuery
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
import dev.inmo.tgbotapi.types.InlineQueryId import dev.inmo.tgbotapi.types.InlineQueryIdentifier
public suspend fun TelegramBot.answerInlineQuery( suspend fun TelegramBot.answerInlineQuery(
inlineQueryID: InlineQueryId, inlineQueryID: InlineQueryIdentifier,
results: List<InlineQueryResult> = emptyList(), results: List<InlineQueryResult> = emptyList(),
cachedTime: Int? = null, cachedTime: Int? = null,
isPersonal: Boolean? = null, isPersonal: Boolean? = null,
nextOffset: String? = null, nextOffset: String? = null,
button: InlineQueryResultsButton? = null switchPmText: String? = null,
): Boolean = execute( switchPmParameter: String? = null
AnswerInlineQuery(inlineQueryID, results, cachedTime, isPersonal, nextOffset, button) ) = execute(
)
public suspend fun TelegramBot.answerInlineQuery(
inlineQuery: InlineQuery,
results: List<InlineQueryResult> = emptyList(),
cachedTime: Int? = null,
isPersonal: Boolean? = null,
nextOffset: String? = null,
button: InlineQueryResultsButton? = null
): Boolean = answerInlineQuery(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, button)
public suspend fun TelegramBot.answer(
inlineQuery: InlineQuery,
results: List<InlineQueryResult> = emptyList(),
cachedTime: Int? = null,
isPersonal: Boolean? = null,
nextOffset: String? = null,
button: InlineQueryResultsButton? = null
): Boolean = answerInlineQuery(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, button)
public suspend fun TelegramBot.answerInlineQuery(
inlineQueryID: InlineQueryId,
results: List<InlineQueryResult> = emptyList(),
cachedTime: Int? = null,
isPersonal: Boolean? = null,
nextOffset: String? = null,
switchPmText: String?,
switchPmParameter: String?
): Boolean = execute(
AnswerInlineQuery(inlineQueryID, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter) AnswerInlineQuery(inlineQueryID, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter)
) )
public suspend fun TelegramBot.answerInlineQuery( suspend fun TelegramBot.answerInlineQuery(
inlineQuery: InlineQuery, inlineQuery: InlineQuery,
results: List<InlineQueryResult> = emptyList(), results: List<InlineQueryResult> = emptyList(),
cachedTime: Int? = null, cachedTime: Int? = null,
isPersonal: Boolean? = null, isPersonal: Boolean? = null,
nextOffset: String? = null, nextOffset: String? = null,
switchPmText: String?, switchPmText: String? = null,
switchPmParameter: String? switchPmParameter: String? = null
): Boolean = answerInlineQuery(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter) ) = answerInlineQuery(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter)
public suspend fun TelegramBot.answer( suspend fun TelegramBot.answer(
inlineQuery: InlineQuery, inlineQuery: InlineQuery,
results: List<InlineQueryResult> = emptyList(), results: List<InlineQueryResult> = emptyList(),
cachedTime: Int? = null, cachedTime: Int? = null,
isPersonal: Boolean? = null, isPersonal: Boolean? = null,
nextOffset: String? = null, nextOffset: String? = null,
switchPmText: String?, switchPmText: String? = null,
switchPmParameter: String? switchPmParameter: String? = null
): Boolean = answerInlineQuery(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter) ) = answerInlineQuery(inlineQuery.id, results, cachedTime, isPersonal, nextOffset, switchPmText, switchPmParameter)

View File

@@ -1,17 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.answers
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.answers.AnswerWebAppQuery
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
import dev.inmo.tgbotapi.types.WebAppQueryId
import dev.inmo.tgbotapi.types.webapps.query.SentWebAppMessage
public suspend fun TelegramBot.answerWebAppQuery(
webAppQueryId: WebAppQueryId,
result: InlineQueryResult
): SentWebAppMessage = execute(AnswerWebAppQuery(webAppQueryId, result))
public suspend fun TelegramBot.answer(
webAppQueryId: WebAppQueryId,
result: InlineQueryResult
): SentWebAppMessage = execute(AnswerWebAppQuery(webAppQueryId, result))

View File

@@ -6,18 +6,18 @@ import dev.inmo.tgbotapi.requests.answers.payments.AnswerPreCheckoutQueryOk
import dev.inmo.tgbotapi.types.PreCheckoutQueryId import dev.inmo.tgbotapi.types.PreCheckoutQueryId
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
public suspend fun TelegramBot.answerPreCheckoutQueryOk( suspend fun TelegramBot.answerPreCheckoutQueryOk(
id: PreCheckoutQueryId id: PreCheckoutQueryId
): Boolean = execute(AnswerPreCheckoutQueryOk(id)) ) = execute(AnswerPreCheckoutQueryOk(id))
public suspend fun TelegramBot.answerPreCheckoutQueryOk( suspend fun TelegramBot.answerPreCheckoutQueryOk(
preCheckoutQuery: PreCheckoutQuery preCheckoutQuery: PreCheckoutQuery
): Boolean = answerPreCheckoutQueryOk(preCheckoutQuery.id) ) = answerPreCheckoutQueryOk(preCheckoutQuery.id)
public suspend fun TelegramBot.answerPreCheckoutQueryError( suspend fun TelegramBot.answerPreCheckoutQueryError(
id: PreCheckoutQueryId, id: PreCheckoutQueryId,
error: String error: String
): Boolean = execute(AnswerPreCheckoutQueryError(id, error)) ) = execute(AnswerPreCheckoutQueryError(id, error))
public suspend fun TelegramBot.answerPreCheckoutQueryError( suspend fun TelegramBot.answerPreCheckoutQueryError(
preCheckoutQuery: PreCheckoutQuery, preCheckoutQuery: PreCheckoutQuery,
error: String error: String
): Boolean = answerPreCheckoutQueryError(preCheckoutQuery.id, error) ) = answerPreCheckoutQueryError(preCheckoutQuery.id, error)

View File

@@ -3,26 +3,26 @@ package dev.inmo.tgbotapi.extensions.api.answers.payments
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.answers.payments.AnswerShippingQueryError import dev.inmo.tgbotapi.requests.answers.payments.AnswerShippingQueryError
import dev.inmo.tgbotapi.requests.answers.payments.AnswerShippingQueryOk import dev.inmo.tgbotapi.requests.answers.payments.AnswerShippingQueryOk
import dev.inmo.tgbotapi.types.ShippingQueryId import dev.inmo.tgbotapi.types.ShippingQueryIdentifier
import dev.inmo.tgbotapi.types.payments.ShippingOption import dev.inmo.tgbotapi.types.payments.ShippingOption
import dev.inmo.tgbotapi.types.payments.ShippingQuery import dev.inmo.tgbotapi.types.payments.ShippingQuery
public suspend fun TelegramBot.answerShippingQueryOk( suspend fun TelegramBot.answerShippingQueryOk(
id: ShippingQueryId, id: ShippingQueryIdentifier,
shippingOptions: List<ShippingOption> shippingOptions: List<ShippingOption>
): Boolean = execute(AnswerShippingQueryOk(id, shippingOptions)) ) = execute(AnswerShippingQueryOk(id, shippingOptions))
public suspend fun TelegramBot.answerShippingQueryOk( suspend fun TelegramBot.answerShippingQueryOk(
shippingQuery: ShippingQuery, shippingQuery: ShippingQuery,
shippingOptions: List<ShippingOption> shippingOptions: List<ShippingOption>
): Boolean = answerShippingQueryOk(shippingQuery.id, shippingOptions) ) = answerShippingQueryOk(shippingQuery.id, shippingOptions)
public suspend fun TelegramBot.answerShippingQueryError( suspend fun TelegramBot.answerShippingQueryError(
id: ShippingQueryId, id: ShippingQueryIdentifier,
error: String error: String
): Boolean = execute(AnswerShippingQueryError(id, error)) ) = execute(AnswerShippingQueryError(id, error))
public suspend fun TelegramBot.answerShippingQueryError( suspend fun TelegramBot.answerShippingQueryError(
shippingQuery: ShippingQuery, shippingQuery: ShippingQuery,
error: String error: String
): Boolean = answerShippingQueryError(shippingQuery.id, error) ) = answerShippingQueryError(shippingQuery.id, error)

View File

@@ -1,12 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.ClearMyDefaultAdministratorRights
public suspend fun TelegramBot.clearMyDefaultAdministratorRights(
forChannels: Boolean? = null
): Boolean = execute(ClearMyDefaultAdministratorRights(forChannels))
public suspend fun TelegramBot.clearMyDefaultAdministratorRightsForChannels(): Boolean = clearMyDefaultAdministratorRights(forChannels = true)
public suspend fun TelegramBot.clearMyDefaultAdministratorRightsForGroupsAndSupergroups(): Boolean = clearMyDefaultAdministratorRights(forChannels = false)

View File

@@ -1,17 +1,17 @@
package dev.inmo.tgbotapi.extensions.api.bot package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.micro_utils.language_codes.IetfLang import dev.inmo.micro_utils.language_codes.IetfLanguageCode
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.DeleteMyCommands import dev.inmo.tgbotapi.requests.bot.DeleteMyCommands
import dev.inmo.tgbotapi.types.commands.BotCommandScope import dev.inmo.tgbotapi.types.commands.BotCommandScope
import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault
public suspend fun TelegramBot.deleteMyCommands( suspend fun TelegramBot.deleteMyCommands(
scope: BotCommandScope = BotCommandScopeDefault, scope: BotCommandScope = BotCommandScopeDefault,
languageCode: IetfLang? languageCode: IetfLanguageCode?
): Boolean = execute(DeleteMyCommands(scope, languageCode)) ) = execute(DeleteMyCommands(scope, languageCode))
public suspend fun TelegramBot.deleteMyCommands( suspend fun TelegramBot.deleteMyCommands(
scope: BotCommandScope = BotCommandScopeDefault, scope: BotCommandScope = BotCommandScopeDefault,
languageCode: String? = null languageCode: String? = null
): Boolean = deleteMyCommands(scope, languageCode ?.let(::IetfLang)) ) = deleteMyCommands(scope, languageCode ?.let(::IetfLanguageCode))

View File

@@ -2,6 +2,5 @@ package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMe import dev.inmo.tgbotapi.requests.bot.GetMe
import dev.inmo.tgbotapi.types.chat.ExtendedBot
public suspend fun TelegramBot.getMe(): ExtendedBot = execute(GetMe) suspend fun TelegramBot.getMe() = execute(GetMe)

View File

@@ -1,18 +1,17 @@
package dev.inmo.tgbotapi.extensions.api.bot package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.micro_utils.language_codes.IetfLang import dev.inmo.micro_utils.language_codes.IetfLanguageCode
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMyCommands import dev.inmo.tgbotapi.requests.bot.GetMyCommands
import dev.inmo.tgbotapi.types.BotCommand
import dev.inmo.tgbotapi.types.commands.BotCommandScope import dev.inmo.tgbotapi.types.commands.BotCommandScope
import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault
public suspend fun TelegramBot.getMyCommands( suspend fun TelegramBot.getMyCommands(
scope: BotCommandScope = BotCommandScopeDefault, scope: BotCommandScope = BotCommandScopeDefault,
languageCode: IetfLang? = null languageCode: IetfLanguageCode? = null
): List<BotCommand> = execute(GetMyCommands(scope, languageCode)) ) = execute(GetMyCommands(scope, languageCode))
public suspend fun TelegramBot.getMyCommands( suspend fun TelegramBot.getMyCommands(
scope: BotCommandScope = BotCommandScopeDefault, scope: BotCommandScope = BotCommandScopeDefault,
languageCode: String? languageCode: String?
): List<BotCommand> = getMyCommands(scope, languageCode ?.let(::IetfLang)) ) = getMyCommands(scope, languageCode ?.let(::IetfLanguageCode))

View File

@@ -1,13 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMyDefaultAdministratorRights
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
public suspend fun TelegramBot.getMyDefaultAdministratorRights(
forChannels: Boolean? = null
): AdministratorChatMember = execute(GetMyDefaultAdministratorRights(forChannels))
public suspend fun TelegramBot.getMyDefaultAdministratorRightsForChannels(): AdministratorChatMember = getMyDefaultAdministratorRights(forChannels = true)
public suspend fun TelegramBot.getMyDefaultAdministratorRightsForGroupsAndSupergroups(): AdministratorChatMember = getMyDefaultAdministratorRights(forChannels = false)

View File

@@ -1,14 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMyDescription
import dev.inmo.tgbotapi.types.BotDescription
public suspend fun TelegramBot.getMyDescription(
languageCode: IetfLang? = null
): BotDescription = execute(GetMyDescription(languageCode))
public suspend fun TelegramBot.getMyDescription(
languageCode: String?
): BotDescription = getMyDescription(languageCode ?.let(::IetfLang))

View File

@@ -1,14 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMyName
import dev.inmo.tgbotapi.types.BotName
public suspend fun TelegramBot.getMyName(
languageCode: IetfLang? = null
): BotName = execute(GetMyName(languageCode))
public suspend fun TelegramBot.getMyName(
languageCode: String?
): BotName = getMyName(languageCode ?.let(::IetfLang))

View File

@@ -1,17 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMyCommands
import dev.inmo.tgbotapi.requests.bot.GetMyShortDescription
import dev.inmo.tgbotapi.types.BotShortDescription
import dev.inmo.tgbotapi.types.commands.BotCommandScope
import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault
public suspend fun TelegramBot.getMyShortDescription(
languageCode: IetfLang? = null
): BotShortDescription = execute(GetMyShortDescription(languageCode))
public suspend fun TelegramBot.getMyShortDescription(
languageCode: String?
): BotShortDescription = getMyShortDescription(languageCode ?.let(::IetfLang))

View File

@@ -1,9 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMe
import dev.inmo.tgbotapi.requests.bot.GetMyStarBalance
import dev.inmo.tgbotapi.types.chat.ExtendedBot
import dev.inmo.tgbotapi.types.payments.stars.StarAmount
public suspend fun TelegramBot.getMyStarBalance(): StarAmount = execute(GetMyStarBalance)

View File

@@ -1,32 +1,32 @@
package dev.inmo.tgbotapi.extensions.api.bot package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.micro_utils.language_codes.IetfLang import dev.inmo.micro_utils.language_codes.IetfLanguageCode
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.SetMyCommands import dev.inmo.tgbotapi.requests.bot.SetMyCommands
import dev.inmo.tgbotapi.types.BotCommand import dev.inmo.tgbotapi.types.BotCommand
import dev.inmo.tgbotapi.types.commands.BotCommandScope import dev.inmo.tgbotapi.types.commands.BotCommandScope
import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault
public suspend fun TelegramBot.setMyCommands( suspend fun TelegramBot.setMyCommands(
commands: List<BotCommand>, commands: List<BotCommand>,
scope: BotCommandScope = BotCommandScopeDefault, scope: BotCommandScope = BotCommandScopeDefault,
languageCode: IetfLang? languageCode: IetfLanguageCode?
): Boolean = execute(SetMyCommands(commands, scope, languageCode)) ) = execute(SetMyCommands(commands, scope, languageCode))
public suspend fun TelegramBot.setMyCommands( suspend fun TelegramBot.setMyCommands(
vararg commands: BotCommand, vararg commands: BotCommand,
scope: BotCommandScope = BotCommandScopeDefault, scope: BotCommandScope = BotCommandScopeDefault,
languageCode: IetfLang? languageCode: IetfLanguageCode?
): Boolean = setMyCommands(commands.toList(), scope, languageCode) ) = setMyCommands(commands.toList(), scope, languageCode)
public suspend fun TelegramBot.setMyCommands( suspend fun TelegramBot.setMyCommands(
commands: List<BotCommand>, commands: List<BotCommand>,
scope: BotCommandScope = BotCommandScopeDefault, scope: BotCommandScope = BotCommandScopeDefault,
languageCode: String? = null languageCode: String? = null
): Boolean = setMyCommands(commands, scope, languageCode ?.let(::IetfLang)) ) = setMyCommands(commands, scope, languageCode ?.let(::IetfLanguageCode))
public suspend fun TelegramBot.setMyCommands( suspend fun TelegramBot.setMyCommands(
vararg commands: BotCommand, vararg commands: BotCommand,
scope: BotCommandScope = BotCommandScopeDefault, scope: BotCommandScope = BotCommandScopeDefault,
languageCode: String? = null languageCode: String? = null
): Boolean = setMyCommands(commands.toList(), scope, languageCode) ) = setMyCommands(commands.toList(), scope, languageCode)

View File

@@ -1,18 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.SetMyDefaultAdministratorRights
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
public suspend fun TelegramBot.setMyDefaultAdministratorRights(
rights: ChatCommonAdministratorRights,
forChannels: Boolean? = null
): Boolean = execute(SetMyDefaultAdministratorRights(rights, forChannels))
public suspend fun TelegramBot.setMyDefaultAdministratorRightsForChannels(
rights: ChatCommonAdministratorRights
): Boolean = setMyDefaultAdministratorRights(rights, forChannels = true)
public suspend fun TelegramBot.setMyDefaultAdministratorRightsForGroupsAndSupergroups(
rights: ChatCommonAdministratorRights
): Boolean = setMyDefaultAdministratorRights(rights, forChannels = false)

View File

@@ -1,19 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMyCommands
import dev.inmo.tgbotapi.requests.bot.GetMyDescription
import dev.inmo.tgbotapi.requests.bot.SetMyDescription
import dev.inmo.tgbotapi.types.commands.BotCommandScope
import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault
public suspend fun TelegramBot.setMyDescription(
description: String? = null,
languageCode: IetfLang? = null
): Boolean = execute(SetMyDescription(description, languageCode))
public suspend fun TelegramBot.setMyDescription(
description: String?,
languageCode: String?
): Boolean = setMyDescription(description, languageCode ?.let(::IetfLang))

View File

@@ -1,19 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMyCommands
import dev.inmo.tgbotapi.requests.bot.GetMyName
import dev.inmo.tgbotapi.requests.bot.SetMyName
import dev.inmo.tgbotapi.types.commands.BotCommandScope
import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault
public suspend fun TelegramBot.setMyName(
name: String? = null,
languageCode: IetfLang? = null
): Boolean = execute(SetMyName(name, languageCode))
public suspend fun TelegramBot.setMyName(
name: String?,
languageCode: String?
): Boolean = setMyName(name, languageCode ?.let(::IetfLang))

View File

@@ -1,15 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.SetMyShortDescription
public suspend fun TelegramBot.setMyShortDescription(
shortDescription: String? = null,
languageCode: IetfLang? = null
): Boolean = execute(SetMyShortDescription(shortDescription, languageCode))
public suspend fun TelegramBot.setMyShortDescription(
shortDescription: String?,
languageCode: String?
): Boolean = setMyShortDescription(shortDescription, languageCode ?.let(::IetfLang))

View File

@@ -1,25 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.micro_utils.ksp.variations.GenerateVariations
import dev.inmo.micro_utils.ksp.variations.GenerationVariant
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.ConvertGiftToStars
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.GiftId
import dev.inmo.tgbotapi.types.gifts.Gift
public suspend fun TelegramBot.convertGiftToStars(
businessConnectionId: BusinessConnectionId,
ownedGiftId: GiftId
): Boolean = execute(
ConvertGiftToStars(businessConnectionId, ownedGiftId)
)
public suspend fun TelegramBot.convertGiftToStars(
businessConnectionId: BusinessConnectionId,
gift: Gift.Regular
): Boolean = convertGiftToStars(
businessConnectionId = businessConnectionId,
ownedGiftId = with(gift) {id}
)

View File

@@ -1,20 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.micro_utils.ksp.variations.GenerateVariations
import dev.inmo.micro_utils.ksp.variations.GenerationVariant
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.DeleteBusinessMessages
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
@GenerateVariations
public suspend fun TelegramBot.deleteBusinessMessages(
businessConnectionId: BusinessConnectionId,
@GenerationVariant(List::class, "messages.map { it.messageId }", "messages", AccessibleMessage::class)
messageIds: List<MessageId>
): Boolean = execute(
DeleteBusinessMessages(businessConnectionId, messageIds)
)

View File

@@ -1,16 +0,0 @@
// THIS CODE HAVE BEEN GENERATED AUTOMATICALLY
// TO REGENERATE IT JUST DELETE FILE
// ORIGINAL FILE: DeleteBusinessMessages.kt
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import kotlin.Boolean
import kotlin.collections.List
public suspend fun TelegramBot.deleteBusinessMessages(businessConnectionId: BusinessConnectionId,
messages: List<AccessibleMessage>): Boolean = deleteBusinessMessages(
businessConnectionId = businessConnectionId, messageIds = with(messages) {messages.map {
it.messageId }}
)

View File

@@ -1,94 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.GetBusinessAccountGifts
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.OwnedGifts
import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceived
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlin.runCatching
public suspend fun TelegramBot.getBusinessAccountGifts(
businessConnectionId: BusinessConnectionId,
excludeUnsaved: Boolean = false,
excludeSaved: Boolean = false,
excludeUnlimited: Boolean = false,
excludeLimited: Boolean = false,
excludeUnique: Boolean = false,
sortByPrice: Boolean = false,
offset: String? = null,
limit: Int? = null
): OwnedGifts<GiftSentOrReceived.ReceivedInBusinessAccount> = execute(
GetBusinessAccountGifts(
businessConnectionId,
excludeUnsaved,
excludeSaved,
excludeUnlimited,
excludeLimited,
excludeUnique,
sortByPrice,
offset,
limit
)
)
/**
* Creates a flow that emits business account gifts in a paginated manner.
*
* This function will automatically handle pagination by using the `nextOffset` from each response
* to fetch the next page of gifts until there are no more gifts to fetch.
*
* @param businessConnectionId The ID of the business connection
* @param excludeUnsaved Whether to exclude unsaved gifts
* @param excludeSaved Whether to exclude saved gifts
* @param excludeUnlimited Whether to exclude unlimited gifts
* @param excludeLimited Whether to exclude limited gifts
* @param excludeUnique Whether to exclude unique gifts
* @param sortByPrice Whether to sort gifts by price
* @param initialOffset The initial offset to start fetching from. If null, starts from the beginning
* @param limit The maximum number of gifts to fetch per request
* @param onErrorContinueChecker A function that determines whether to continue fetching on error.
* Returns true to continue, false to stop. Default is to stop on any error.
* @return A flow that emits [OwnedGifts] containing the fetched gifts
*/
public fun TelegramBot.getBusinessAccountGiftsFlow(
businessConnectionId: BusinessConnectionId,
excludeUnsaved: Boolean = false,
excludeSaved: Boolean = false,
excludeUnlimited: Boolean = false,
excludeLimited: Boolean = false,
excludeUnique: Boolean = false,
sortByPrice: Boolean = false,
initialOffset: String? = null,
limit: Int? = null,
onErrorContinueChecker: suspend (Throwable?) -> Boolean = { false }
): Flow<OwnedGifts<GiftSentOrReceived.ReceivedInBusinessAccount>> = flow {
var currentOffset = initialOffset
do {
val response = runCatching {
getBusinessAccountGifts(
businessConnectionId,
excludeUnsaved,
excludeSaved,
excludeUnlimited,
excludeLimited,
excludeUnique,
sortByPrice,
currentOffset,
limit
)
}
if (response.isSuccess) {
val result = response.getOrThrow()
emit(result)
currentOffset = result.nextOffset
} else {
if (onErrorContinueChecker(response.exceptionOrNull())) {
continue
} else {
break
}
}
} while (currentOffset != null)
}

View File

@@ -1,12 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.GetBusinessAccountStarBalance
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.payments.stars.StarAmount
public suspend fun TelegramBot.getBusinessAccountStarBalance(
businessConnectionId: BusinessConnectionId
): StarAmount = execute(
GetBusinessAccountStarBalance(businessConnectionId)
)

View File

@@ -1,27 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.micro_utils.ksp.variations.GenerateVariations
import dev.inmo.micro_utils.ksp.variations.GenerationVariant
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.ReadBusinessMessage
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.toChatId
@GenerateVariations
public suspend fun TelegramBot.readBusinessMessage(
businessConnectionId: BusinessConnectionId,
@GenerationVariant(Chat::class, "chat.id.toChatId()", "chat")
chatId: ChatId,
messageId: MessageId
): Boolean = execute(
ReadBusinessMessage(businessConnectionId, chatId, messageId)
)
public suspend fun TelegramBot.readBusinessMessage(
businessConnectionId: BusinessConnectionId,
message: AccessibleMessage
): Boolean = readBusinessMessage(businessConnectionId, message.chat.id.toChatId(), message.messageId)

View File

@@ -1,20 +0,0 @@
// THIS CODE HAVE BEEN GENERATED AUTOMATICALLY
// TO REGENERATE IT JUST DELETE FILE
// ORIGINAL FILE: ReadBusinessMessage.kt
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.toChatId
import kotlin.Boolean
public suspend fun TelegramBot.readBusinessMessage(
businessConnectionId: BusinessConnectionId,
chat: Chat,
messageId: MessageId,
): Boolean = readBusinessMessage(
businessConnectionId = businessConnectionId, chatId = with(chat) {chat.id.toChatId()}, messageId
= messageId
)

View File

@@ -1,12 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.RemoveBusinessAccountProfilePhoto
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
public suspend fun TelegramBot.removeBusinessAccountProfilePhoto(
businessConnectionId: BusinessConnectionId,
isPublic: Boolean = false
): Boolean = execute(
RemoveBusinessAccountProfilePhoto(businessConnectionId = businessConnectionId, isPublic = isPublic)
)

View File

@@ -1,12 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.SetBusinessAccountBio
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
public suspend fun TelegramBot.setBusinessAccountBio(
businessConnectionId: BusinessConnectionId,
bio: String
): Boolean = execute(
SetBusinessAccountBio(businessConnectionId, bio)
)

View File

@@ -1,35 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.SetBusinessAccountGiftSettings
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.gifts.AcceptedGiftTypes
import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage
/**
* Sets the gift settings for a business account
*/
public suspend fun TelegramBot.setBusinessAccountGiftSettings(
businessConnectionId: BusinessConnectionId,
showGiftButton: Boolean,
acceptedGiftTypes: AcceptedGiftTypes
): Boolean = execute(
SetBusinessAccountGiftSettings(
businessConnectionId = businessConnectionId,
showGiftButton = showGiftButton,
acceptedGiftTypes = acceptedGiftTypes
)
)
/**
* Sets the gift settings for a business account using business message context
*/
public suspend fun TelegramBot.setBusinessAccountGiftSettings(
message: BusinessContentMessage<*>,
showGiftButton: Boolean,
acceptedGiftTypes: AcceptedGiftTypes
): Boolean = setBusinessAccountGiftSettings(
businessConnectionId = message.businessConnectionId,
showGiftButton = showGiftButton,
acceptedGiftTypes = acceptedGiftTypes
)

View File

@@ -1,13 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.SetBusinessAccountName
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
public suspend fun TelegramBot.setBusinessAccountName(
businessConnectionId: BusinessConnectionId,
firstName: String,
lastName: String? = null
): Boolean = execute(
SetBusinessAccountName(businessConnectionId, firstName, lastName)
)

View File

@@ -1,14 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.InputProfilePhoto
import dev.inmo.tgbotapi.requests.business_connection.SetBusinessAccountProfilePhoto
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
public suspend fun TelegramBot.setBusinessAccountProfilePhoto(
businessConnectionId: BusinessConnectionId,
photo: InputProfilePhoto,
isPublic: Boolean = false
): Boolean = execute(
SetBusinessAccountProfilePhoto(businessConnectionId, photo, isPublic)
)

View File

@@ -1,17 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.micro_utils.ksp.variations.GenerateVariations
import dev.inmo.micro_utils.ksp.variations.GenerationVariant
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.SetBusinessAccountUsername
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.Username
@GenerateVariations
public suspend fun TelegramBot.setBusinessAccountUsername(
businessConnectionId: BusinessConnectionId,
@GenerationVariant(String::class, "Username(username)", "username")
username: Username
): Boolean = execute(
SetBusinessAccountUsername(businessConnectionId, username)
)

View File

@@ -1,16 +0,0 @@
// THIS CODE HAVE BEEN GENERATED AUTOMATICALLY
// TO REGENERATE IT JUST DELETE FILE
// ORIGINAL FILE: SetBusinessAccountUsername.kt
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.types.Username
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import kotlin.Boolean
import kotlin.String
public suspend
fun TelegramBot.setBusinessAccountUsername(businessConnectionId: BusinessConnectionId,
username: String): Boolean = setBusinessAccountUsername(
businessConnectionId = businessConnectionId, username = with(username) { Username.prepare(username) }
)

View File

@@ -1,12 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.TransferBusinessAccountStars
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
public suspend fun TelegramBot.transferBusinessAccountStars(
businessConnectionId: BusinessConnectionId,
amount: Int
): Boolean = execute(
TransferBusinessAccountStars(businessConnectionId, amount)
)

View File

@@ -1,43 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.micro_utils.ksp.variations.GenerateVariations
import dev.inmo.micro_utils.ksp.variations.GenerationVariant
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.ConvertGiftToStars
import dev.inmo.tgbotapi.requests.business_connection.TransferGift
import dev.inmo.tgbotapi.requests.business_connection.UpgradeGift
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.GiftId
import dev.inmo.tgbotapi.types.businessConnectionIdField
import dev.inmo.tgbotapi.types.gifts.Gift
import dev.inmo.tgbotapi.types.keepOriginalDetailsField
import dev.inmo.tgbotapi.types.ownedGiftIdField
import dev.inmo.tgbotapi.types.starCountField
import kotlinx.serialization.SerialName
public suspend fun TelegramBot.transferGift(
businessConnectionId: BusinessConnectionId,
ownedGiftId: GiftId,
newOwnerChatId: ChatId,
transferPaymentStarCount: Int? = null,
): Boolean = execute(
TransferGift(
businessConnectionId = businessConnectionId,
ownedGiftId = ownedGiftId,
newOwnerChatId = newOwnerChatId,
transferPaymentStarCount = transferPaymentStarCount
)
)
public suspend fun TelegramBot.transferGift(
businessConnectionId: BusinessConnectionId,
gift: Gift.Regular,
newOwnerChatId: ChatId,
transferPaymentStarCount: Int? = null,
): Boolean = transferGift(
businessConnectionId = businessConnectionId,
ownedGiftId = gift.id,
newOwnerChatId = newOwnerChatId,
transferPaymentStarCount = transferPaymentStarCount
)

View File

@@ -1,42 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.business
import dev.inmo.micro_utils.ksp.variations.GenerateVariations
import dev.inmo.micro_utils.ksp.variations.GenerationVariant
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.business_connection.ConvertGiftToStars
import dev.inmo.tgbotapi.requests.business_connection.UpgradeGift
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
import dev.inmo.tgbotapi.types.GiftId
import dev.inmo.tgbotapi.types.businessConnectionIdField
import dev.inmo.tgbotapi.types.gifts.Gift
import dev.inmo.tgbotapi.types.keepOriginalDetailsField
import dev.inmo.tgbotapi.types.ownedGiftIdField
import dev.inmo.tgbotapi.types.starCountField
import kotlinx.serialization.SerialName
public suspend fun TelegramBot.convertGiftToStars(
businessConnectionId: BusinessConnectionId,
ownedGiftId: GiftId,
keepOriginalDetails: Boolean = false,
starCount: Int? = null
): Boolean = execute(
UpgradeGift(
businessConnectionId = businessConnectionId,
ownedGiftId = ownedGiftId,
keepOriginalDetails = keepOriginalDetails,
starCount = starCount
)
)
public suspend fun TelegramBot.convertGiftToStars(
businessConnectionId: BusinessConnectionId,
gift: Gift.Regular,
keepOriginalDetails: Boolean = false,
): Boolean = execute(
UpgradeGift(
businessConnectionId = businessConnectionId,
ownedGiftId = gift.id,
keepOriginalDetails = keepOriginalDetails,
starCount = gift.upgradeStarCount
)
)

View File

@@ -3,12 +3,12 @@ package dev.inmo.tgbotapi.extensions.api.chat
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.ExportChatInviteLink import dev.inmo.tgbotapi.requests.chat.ExportChatInviteLink
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.chat.PublicChat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
public suspend fun TelegramBot.exportChatInviteLink( suspend fun TelegramBot.exportChatInviteLink(
chatId: ChatIdentifier chatId: ChatIdentifier
): String = execute(ExportChatInviteLink(chatId)) ) = execute(ExportChatInviteLink(chatId))
public suspend fun TelegramBot.exportChatInviteLink( suspend fun TelegramBot.exportChatInviteLink(
chat: PublicChat chat: PublicChat
): String = exportChatInviteLink(chat.id) ) = exportChatInviteLink(chat.id)

View File

@@ -3,12 +3,12 @@ package dev.inmo.tgbotapi.extensions.api.chat
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.LeaveChat import dev.inmo.tgbotapi.requests.chat.LeaveChat
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.chat.PublicChat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
public suspend fun TelegramBot.leaveChat( suspend fun TelegramBot.leaveChat(
chatId: ChatIdentifier chatId: ChatIdentifier
): Boolean = execute(LeaveChat(chatId)) ) = execute(LeaveChat(chatId))
public suspend fun TelegramBot.leaveChat( suspend fun TelegramBot.leaveChat(
chat: PublicChat chat: PublicChat
): Boolean = leaveChat(chat.id) ) = leaveChat(chat.id)

View File

@@ -1,28 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.closeForumTopic(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId
): Boolean = execute(
CloseForumTopic(
chatId,
messageThreadId
)
)
public suspend fun TelegramBot.closeForumTopic(
chat: Chat,
messageThreadId: MessageThreadId
): Boolean = closeForumTopic(chat.id, messageThreadId)
public suspend fun TelegramBot.closeForumTopic(
chat: Chat,
forumTopic: ForumTopic
): Boolean = closeForumTopic(chat.id, forumTopic.messageThreadId)

View File

@@ -1,19 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.CloseGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.closeGeneralForumTopic(
chatId: ChatIdentifier
): Boolean = execute(
CloseGeneralForumTopic(chatId)
)
public suspend fun TelegramBot.closeGeneralForumTopic(
chat: Chat
): Boolean = closeGeneralForumTopic(chat.id)

View File

@@ -1,30 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.CreateForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.CustomEmojiId
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.utils.RGBColor
public suspend fun TelegramBot.createForumTopic(
chatId: ChatIdentifier,
name: String,
color: RGBColor,
iconEmojiId: CustomEmojiId? = null
): ForumTopic = execute(
CreateForumTopic(
chatId,
name,
color,
iconEmojiId
)
)
public suspend fun TelegramBot.createForumTopic(
chat: Chat,
name: String,
color: RGBColor,
iconEmojiId: CustomEmojiId? = null
): ForumTopic = createForumTopic(chat.id, name, color, iconEmojiId)

View File

@@ -1,33 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.DeleteForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.deleteForumTopic(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId
): Boolean = execute(
DeleteForumTopic(
chatId,
messageThreadId
)
)
public suspend fun TelegramBot.deleteForumTopic(
chatId: ChatIdentifier,
forumTopic: ForumTopic
): Boolean = deleteForumTopic(chatId, forumTopic.messageThreadId)
public suspend fun TelegramBot.deleteForumTopic(
chat: Chat,
messageThreadId: MessageThreadId
): Boolean = deleteForumTopic(chat.id, messageThreadId)
public suspend fun TelegramBot.deleteForumTopic(
chat: Chat,
forumTopic: ForumTopic
): Boolean = deleteForumTopic(chat.id, forumTopic.messageThreadId)

View File

@@ -1,36 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.EditForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.CustomEmojiId
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.editForumTopic(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId,
name: String? = null,
iconEmojiId: CustomEmojiId? = null
): Boolean = execute(
EditForumTopic(
chatId,
messageThreadId,
name,
iconEmojiId
)
)
public suspend fun TelegramBot.editForumTopic(
chat: Chat,
messageThreadId: MessageThreadId,
name: String? = null,
iconEmojiId: CustomEmojiId? = null
): Boolean = editForumTopic(chat.id, messageThreadId, name, iconEmojiId)
public suspend fun TelegramBot.editForumTopic(
chatIdentifier: ChatIdentifier,
forumTopic: ForumTopic,
iconEmojiId: CustomEmojiId? = forumTopic.iconEmojiId
): Boolean = editForumTopic(chatIdentifier, forumTopic.messageThreadId, forumTopic.name, iconEmojiId)

View File

@@ -1,30 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.EditForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.EditGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.CustomEmojiId
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.editGeneralForumTopic(
chatId: ChatIdentifier,
name: String
): Boolean = execute(
EditGeneralForumTopic(
chatId,
name
)
)
public suspend fun TelegramBot.editGeneralForumTopic(
chat: Chat,
name: String
): Boolean = editGeneralForumTopic(chat.id, name)
public suspend fun TelegramBot.editGeneralForumTopic(
chatIdentifier: ChatIdentifier,
forumTopic: ForumTopic,
): Boolean = editGeneralForumTopic(chatIdentifier, forumTopic.name)

View File

@@ -1,20 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.CloseGeneralForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.HideGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.hideGeneralForumTopic(
chatId: ChatIdentifier
): Boolean = execute(
HideGeneralForumTopic(chatId)
)
public suspend fun TelegramBot.hideGeneralForumTopic(
chat: Chat
): Boolean = hideGeneralForumTopic(chat.id)

View File

@@ -1,28 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.ReopenForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.reopenForumTopic(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId
): Boolean = execute(
ReopenForumTopic(
chatId,
messageThreadId
)
)
public suspend fun TelegramBot.reopenForumTopic(
chat: Chat,
messageThreadId: MessageThreadId
): Boolean = reopenForumTopic(chat.id, messageThreadId)
public suspend fun TelegramBot.reopenForumTopic(
chat: Chat,
forumTopic: ForumTopic
): Boolean = reopenForumTopic(chat.id, forumTopic.messageThreadId)

View File

@@ -1,19 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.ReopenForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.ReopenGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.reopenGeneralForumTopic(
chatId: ChatIdentifier
): Boolean = execute(
ReopenGeneralForumTopic(chatId)
)
public suspend fun TelegramBot.reopenGeneralForumTopic(
chat: Chat
): Boolean = reopenGeneralForumTopic(chat.id)

View File

@@ -1,21 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.CloseGeneralForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.HideGeneralForumTopic
import dev.inmo.tgbotapi.requests.chat.forum.UnhideGeneralForumTopic
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.unhideGeneralForumTopic(
chatId: ChatIdentifier
): Boolean = execute(
UnhideGeneralForumTopic(chatId)
)
public suspend fun TelegramBot.unhideGeneralForumTopic(
chat: Chat
): Boolean = unhideGeneralForumTopic(chat.id)

View File

@@ -1,28 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.UnpinAllForumTopicMessages
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.unpinAllForumTopicMessages(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId
): Boolean = execute(
UnpinAllForumTopicMessages(
chatId,
messageThreadId
)
)
public suspend fun TelegramBot.unpinAllForumTopicMessages(
chat: Chat,
messageThreadId: MessageThreadId
): Boolean = unpinAllForumTopicMessages(chat.id, messageThreadId)
public suspend fun TelegramBot.unpinAllForumTopicMessages(
chat: Chat,
forumTopic: ForumTopic
): Boolean = unpinAllForumTopicMessages(chat.id, forumTopic.messageThreadId)

View File

@@ -1,21 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.forum
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.forum.UnpinAllForumTopicMessages
import dev.inmo.tgbotapi.requests.chat.forum.UnpinAllGeneralForumTopicMessages
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ForumTopic
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.chat.Chat
public suspend fun TelegramBot.unpinAllGeneralForumTopicMessages(
chatId: ChatIdentifier
): Boolean = execute(
UnpinAllGeneralForumTopicMessages(
chatId
)
)
public suspend fun TelegramBot.unpinAllGeneralForumTopicMessages(
chat: Chat
): Boolean = unpinAllGeneralForumTopicMessages(chat.id)

View File

@@ -2,128 +2,131 @@ package dev.inmo.tgbotapi.extensions.api.chat.get
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.get.GetChat import dev.inmo.tgbotapi.requests.chat.get.GetChat
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.* import dev.inmo.tgbotapi.types.chat.*
import dev.inmo.tgbotapi.types.chat.abstracts.*
import dev.inmo.tgbotapi.types.chat.abstracts.extended.*
import dev.inmo.tgbotapi.types.chat.extended.*
import dev.inmo.tgbotapi.utils.PreviewFeature import dev.inmo.tgbotapi.utils.PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chatId: ChatIdentifier chatId: ChatIdentifier
): ExtendedChat = execute(GetChat(chatId)) ) = execute(GetChat(chatId))
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: Chat chat: Chat
): ExtendedChat = getChat(chat.id) ) = getChat(chat.id)
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedPublicChat] with unsafe operator "as" * [ExtendedPublicChat] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: PublicChat chat: PublicChat
): ExtendedPublicChat = getChat(chat.id) as ExtendedPublicChat ) = getChat(chat.id) as ExtendedPublicChat
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedChannelChat] with unsafe operator "as" * [ExtendedChannelChat] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: ChannelChat chat: ChannelChat
): ExtendedChannelChat = getChat(chat.id) as ExtendedChannelChat ) = getChat(chat.id) as ExtendedChannelChat
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedChannelChatImpl] with unsafe operator "as" * [ExtendedChannelChatImpl] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: ChannelChatImpl chat: ChannelChatImpl
): ExtendedChannelChatImpl = getChat(chat.id) as ExtendedChannelChatImpl ) = getChat(chat.id) as ExtendedChannelChatImpl
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedGroupChat] with unsafe operator "as" * [ExtendedGroupChat] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: GroupChat chat: GroupChat
): ExtendedGroupChat = getChat(chat.id) as ExtendedGroupChat ) = getChat(chat.id) as ExtendedGroupChat
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedGroupChatImpl] with unsafe operator "as" * [ExtendedGroupChatImpl] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: GroupChatImpl chat: GroupChatImpl
): ExtendedGroupChatImpl = getChat(chat.id) as ExtendedGroupChatImpl ) = getChat(chat.id) as ExtendedGroupChatImpl
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedSupergroupChat] with unsafe operator "as" * [ExtendedSupergroupChat] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: SupergroupChat chat: SupergroupChat
): ExtendedSupergroupChat = getChat(chat.id) as ExtendedSupergroupChat ) = getChat(chat.id) as ExtendedSupergroupChat
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedSupergroupChatImpl] with unsafe operator "as" * [ExtendedSupergroupChatImpl] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: SupergroupChatImpl chat: SupergroupChatImpl
): ExtendedSupergroupChatImpl = getChat(chat.id) as ExtendedSupergroupChatImpl ) = getChat(chat.id) as ExtendedSupergroupChatImpl
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedPrivateChat] with unsafe operator "as" * [ExtendedPrivateChat] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: PrivateChat chat: PrivateChat
): ExtendedPrivateChat = getChat(chat.id) as ExtendedPrivateChat ) = getChat(chat.id) as ExtendedPrivateChat
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedPrivateChatImpl] with unsafe operator "as" * [ExtendedPrivateChatImpl] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: PrivateChatImpl chat: PrivateChatImpl
): ExtendedPrivateChatImpl = getChat(chat.id) as ExtendedPrivateChatImpl ) = getChat(chat.id) as ExtendedPrivateChatImpl
/** /**
* Will cast incoming [dev.inmo.tgbotapi.types.chat.ExtendedChat] to a * Will cast incoming [dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat] to a
* [ExtendedUser] with unsafe operator "as" * [ExtendedUser] with unsafe operator "as"
* *
* @throws ClassCastException * @throws ClassCastException
*/ */
@PreviewFeature @PreviewFeature
public suspend fun TelegramBot.getChat( suspend fun TelegramBot.getChat(
chat: CommonUser chat: CommonUser
): ExtendedUser = getChat(chat.id) as ExtendedUser ) = getChat(chat.id) as ExtendedUser

View File

@@ -3,13 +3,12 @@ package dev.inmo.tgbotapi.extensions.api.chat.get
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.get.GetChatAdministrators import dev.inmo.tgbotapi.requests.chat.get.GetChatAdministrators
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.chat.PublicChat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
public suspend fun TelegramBot.getChatAdministrators( suspend fun TelegramBot.getChatAdministrators(
chatId: ChatIdentifier chatId: ChatIdentifier
): List<AdministratorChatMember> = execute(GetChatAdministrators(chatId)) ) = execute(GetChatAdministrators(chatId))
public suspend fun TelegramBot.getChatAdministrators( suspend fun TelegramBot.getChatAdministrators(
chat: PublicChat chat: PublicChat
): List<AdministratorChatMember> = getChatAdministrators(chat.id) ) = getChatAdministrators(chat.id)

View File

@@ -3,12 +3,12 @@ package dev.inmo.tgbotapi.extensions.api.chat.get
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.get.GetChatMemberCount import dev.inmo.tgbotapi.requests.chat.get.GetChatMemberCount
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.chat.PublicChat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
public suspend fun TelegramBot.getChatMemberCount( suspend fun TelegramBot.getChatMemberCount(
chatId: ChatIdentifier chatId: ChatIdentifier
): Int = execute(GetChatMemberCount(chatId)) ) = execute(GetChatMemberCount(chatId))
public suspend fun TelegramBot.getChatMemberCount( suspend fun TelegramBot.getChatMemberCount(
chat: PublicChat chat: PublicChat
): Int = getChatMemberCount(chat.id) ) = getChatMemberCount(chat.id)

View File

@@ -1,15 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.get
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.get.GetChatMenuButton
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.MenuButton
import dev.inmo.tgbotapi.types.chat.PrivateChat
public suspend fun TelegramBot.getChatMenuButton(
chatId: IdChatIdentifier
): MenuButton = execute(GetChatMenuButton(chatId))
public suspend fun TelegramBot.getChatMenuButton(
chat: PrivateChat
): MenuButton = getChatMenuButton(chat.id)

View File

@@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.get
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.get.GetDefaultChatMenuButton
import dev.inmo.tgbotapi.types.MenuButton
public suspend fun TelegramBot.getDefaultChatMenuButton(): MenuButton = execute(GetDefaultChatMenuButton)

View File

@@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.chat.get
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.get.GetForumTopicIconStickers
import dev.inmo.tgbotapi.types.files.Sticker
public suspend fun TelegramBot.getForumTopicIconStickers(): List<Sticker> = execute(GetForumTopicIconStickers)

View File

@@ -2,41 +2,38 @@ package dev.inmo.tgbotapi.extensions.api.chat.invite_links
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.invite_links.ApproveChatJoinRequest import dev.inmo.tgbotapi.requests.chat.invite_links.ApproveChatJoinRequest
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
import dev.inmo.tgbotapi.types.chat.PublicChat
import dev.inmo.tgbotapi.types.chat.User
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
public suspend fun TelegramBot.approveChatJoinRequest( suspend fun TelegramBot.approveChatJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
userId: UserId userId: UserId
): Boolean = execute(ApproveChatJoinRequest(chatId, userId)) ) = execute(ApproveChatJoinRequest(chatId, userId))
public suspend fun TelegramBot.approveChatJoinRequest( suspend fun TelegramBot.approveChatJoinRequest(
chat: PublicChat, chat: PublicChat,
userId: UserId userId: UserId
): Boolean = approveChatJoinRequest(chat.id, userId) ) = approveChatJoinRequest(chat.id, userId)
public suspend fun TelegramBot.approveChatJoinRequest( suspend fun TelegramBot.approveChatJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
user: User user: User
): Boolean = approveChatJoinRequest(chatId, user.id) ) = approveChatJoinRequest(chatId, user.id)
public suspend fun TelegramBot.approveChatJoinRequest( suspend fun TelegramBot.approveChatJoinRequest(
chat: PublicChat, chat: PublicChat,
user: User user: User
): Boolean = approveChatJoinRequest(chat.id, user.id) ) = approveChatJoinRequest(chat.id, user.id)
public suspend fun TelegramBot.approveChatJoinRequest( suspend fun TelegramBot.approveChatJoinRequest(
chatJoinRequest: ChatJoinRequest chatJoinRequest: ChatJoinRequest
): Boolean = approveChatJoinRequest(chatJoinRequest.chat, chatJoinRequest.user) ) = approveChatJoinRequest(chatJoinRequest.chat, chatJoinRequest.user)
public suspend fun TelegramBot.approve( suspend fun TelegramBot.approve(
chatJoinRequest: ChatJoinRequest chatJoinRequest: ChatJoinRequest
): Boolean = approveChatJoinRequest(chatJoinRequest) ) = approveChatJoinRequest(chatJoinRequest)
public suspend fun TelegramBot.approveChatJoinRequest( suspend fun TelegramBot.approveChatJoinRequest(
chatJoinRequestUpdate: ChatJoinRequestUpdate chatJoinRequestUpdate: ChatJoinRequestUpdate
): Boolean = approveChatJoinRequest(chatJoinRequestUpdate.data) ) = approveChatJoinRequest(chatJoinRequestUpdate.data)

View File

@@ -1,153 +1,83 @@
package dev.inmo.tgbotapi.extensions.api.chat.invite_links package dev.inmo.tgbotapi.extensions.api.chat.invite_links
import korlibs.time.DateTime import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.PublicChat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import korlibs.time.TimeSpan
import korlibs.time.days
public suspend fun TelegramBot.createChatInviteLinkUnlimited( suspend fun TelegramBot.createChatInviteLinkUnlimited(
chatId: ChatIdentifier, chatId: ChatIdentifier,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null expiration: TelegramDate? = null
): ChatInviteLinkUnlimited = execute(CreateChatInviteLink.unlimited(chatId, name, expiration)) ) = execute(CreateChatInviteLink.unlimited(chatId, name, expiration))
public suspend fun TelegramBot.createChatInviteLinkUnlimited( suspend fun TelegramBot.createChatInviteLinkUnlimited(
chat: PublicChat, chat: PublicChat,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null, expiration: TelegramDate? = null,
): ChatInviteLinkUnlimited = createChatInviteLinkUnlimited(chat.id, name, expiration) ) = createChatInviteLinkUnlimited(chat.id, name, expiration)
public suspend fun TelegramBot.createChatInviteLinkUnlimited( suspend fun TelegramBot.createChatInviteLinkUnlimited(
chatId: ChatIdentifier, chatId: ChatIdentifier,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkUnlimited = createChatInviteLinkUnlimited(chatId, name, expiration.toTelegramDate()) ) = createChatInviteLinkUnlimited(chatId, name, expiration.toTelegramDate())
public suspend fun TelegramBot.createChatInviteLinkUnlimited( suspend fun TelegramBot.createChatInviteLinkUnlimited(
chat: PublicChat, chat: PublicChat,
expiration: DateTime, expiration: DateTime,
name: String? = null name: String? = null
): ChatInviteLinkUnlimited = createChatInviteLinkUnlimited(chat.id, name, expiration.toTelegramDate()) ) = createChatInviteLinkUnlimited(chat.id, name, expiration.toTelegramDate())
public suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier, chatId: ChatIdentifier,
membersLimit: MembersLimit, membersLimit: MembersLimit,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null expiration: TelegramDate? = null
): ChatInviteLinkWithLimitedMembers = execute(CreateChatInviteLink.withLimitedMembers(chatId, membersLimit, name, expiration)) ) = execute(CreateChatInviteLink.withLimitedMembers(chatId, membersLimit, name, expiration))
public suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
chat: PublicChat, chat: PublicChat,
membersLimit: MembersLimit, membersLimit: MembersLimit,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null, expiration: TelegramDate? = null,
): ChatInviteLinkWithLimitedMembers = createChatInviteLinkWithLimitedMembers(chat.id, membersLimit, name, expiration) ) = createChatInviteLinkWithLimitedMembers(chat.id, membersLimit, name, expiration)
public suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier, chatId: ChatIdentifier,
membersLimit: MembersLimit, membersLimit: MembersLimit,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithLimitedMembers = createChatInviteLinkWithLimitedMembers(chatId, membersLimit, name, expiration.toTelegramDate()) ) = createChatInviteLinkWithLimitedMembers(chatId, membersLimit, name, expiration.toTelegramDate())
public suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
chat: PublicChat, chat: PublicChat,
membersLimit: MembersLimit, membersLimit: MembersLimit,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithLimitedMembers = createChatInviteLinkWithLimitedMembers(chat.id, membersLimit, name, expiration.toTelegramDate()) ) = createChatInviteLinkWithLimitedMembers(chat.id, membersLimit, name, expiration.toTelegramDate())
public suspend fun TelegramBot.createChatInviteLinkWithJoinRequest( suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null expiration: TelegramDate? = null
): ChatInviteLinkWithJoinRequest = execute(CreateChatInviteLink.withJoinRequest(chatId, name, expiration)) ) = execute(CreateChatInviteLink.withJoinRequest(chatId, name, expiration))
public suspend fun TelegramBot.createChatInviteLinkWithJoinRequest( suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
chat: PublicChat, chat: PublicChat,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null, expiration: TelegramDate? = null,
): ChatInviteLinkWithJoinRequest = createChatInviteLinkWithJoinRequest(chat.id, name, expiration) ) = createChatInviteLinkWithJoinRequest(chat.id, name, expiration)
public suspend fun TelegramBot.createChatInviteLinkWithJoinRequest( suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithJoinRequest = createChatInviteLinkWithJoinRequest(chatId, name, expiration.toTelegramDate()) ) = createChatInviteLinkWithJoinRequest(chatId, name, expiration.toTelegramDate())
public suspend fun TelegramBot.createChatInviteLinkWithJoinRequest( suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
chat: PublicChat, chat: PublicChat,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithJoinRequest = createChatInviteLinkWithJoinRequest(chat.id, name, expiration.toTelegramDate()) ) = createChatInviteLinkWithJoinRequest(chat.id, name, expiration.toTelegramDate())
// Subscriptions
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
chatId: ChatIdentifier,
subscriptionPrice: UInt,
subscriptionPeriod: TimeSpan = 30.days,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
): ChatInviteLinkUnlimited = execute(CreateChatInviteLink.subscription(chatId, subscriptionPrice, subscriptionPeriod, name, expirationUnixTimeStamp))
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
chat: PublicChat,
subscriptionPrice: UInt,
subscriptionPeriod: TimeSpan = 30.days,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chat.id, subscriptionPrice, subscriptionPeriod, name, expirationUnixTimeStamp)
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
chatId: ChatIdentifier,
subscriptionPrice: UInt,
subscriptionPeriod: TimeSpan = 30.days,
name: String? = null,
expirationUnixTimeStamp: DateTime,
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chatId, subscriptionPrice, subscriptionPeriod, name, expirationUnixTimeStamp.toTelegramDate())
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
chat: PublicChat,
subscriptionPrice: UInt,
subscriptionPeriod: TimeSpan = 30.days,
name: String? = null,
expirationUnixTimeStamp: DateTime,
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chat.id, subscriptionPrice, subscriptionPeriod, name, expirationUnixTimeStamp)
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
chatId: ChatIdentifier,
subscriptionPrice: Int,
subscriptionPeriod: TimeSpan = 30.days,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chatId, subscriptionPrice.toUInt(), subscriptionPeriod, name, expirationUnixTimeStamp)
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
chat: PublicChat,
subscriptionPrice: Int,
subscriptionPeriod: TimeSpan = 30.days,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chat, subscriptionPrice.toUInt(), subscriptionPeriod, name, expirationUnixTimeStamp)
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
chatId: ChatIdentifier,
subscriptionPrice: Int,
subscriptionPeriod: TimeSpan = 30.days,
name: String? = null,
expirationUnixTimeStamp: DateTime,
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chatId, subscriptionPrice.toUInt(), subscriptionPeriod, name, expirationUnixTimeStamp)
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
chat: PublicChat,
subscriptionPrice: Int,
subscriptionPeriod: TimeSpan = 30.days,
name: String? = null,
expirationUnixTimeStamp: DateTime,
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chat, subscriptionPrice.toUInt(), subscriptionPeriod, name, expirationUnixTimeStamp)

View File

@@ -1,42 +1,40 @@
package dev.inmo.tgbotapi.extensions.api.chat.invite_links package dev.inmo.tgbotapi.extensions.api.chat.invite_links
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.invite_links.ApproveChatJoinRequest
import dev.inmo.tgbotapi.requests.chat.invite_links.DeclineChatJoinRequest import dev.inmo.tgbotapi.requests.chat.invite_links.DeclineChatJoinRequest
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
import dev.inmo.tgbotapi.types.chat.PublicChat
import dev.inmo.tgbotapi.types.chat.User
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
public suspend fun TelegramBot.declineChatJoinRequest( suspend fun TelegramBot.declineChatJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
userId: UserId userId: UserId
): Boolean = execute(DeclineChatJoinRequest(chatId, userId)) ) = execute(DeclineChatJoinRequest(chatId, userId))
public suspend fun TelegramBot.declineChatJoinRequest( suspend fun TelegramBot.declineChatJoinRequest(
chat: PublicChat, chat: PublicChat,
userId: UserId userId: UserId
): Boolean = declineChatJoinRequest(chat.id, userId) ) = declineChatJoinRequest(chat.id, userId)
public suspend fun TelegramBot.declineChatJoinRequest( suspend fun TelegramBot.declineChatJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
user: User user: User
): Boolean = declineChatJoinRequest(chatId, user.id) ) = declineChatJoinRequest(chatId, user.id)
public suspend fun TelegramBot.declineChatJoinRequest( suspend fun TelegramBot.declineChatJoinRequest(
chat: PublicChat, chat: PublicChat,
user: User user: User
): Boolean = declineChatJoinRequest(chat.id, user.id) ) = declineChatJoinRequest(chat.id, user.id)
public suspend fun TelegramBot.declineChatJoinRequest( suspend fun TelegramBot.declineChatJoinRequest(
chatJoinRequest: ChatJoinRequest chatJoinRequest: ChatJoinRequest
): Boolean = declineChatJoinRequest(chatJoinRequest.chat, chatJoinRequest.user) ) = declineChatJoinRequest(chatJoinRequest.chat, chatJoinRequest.user)
public suspend fun TelegramBot.decline( suspend fun TelegramBot.decline(
chatJoinRequest: ChatJoinRequest chatJoinRequest: ChatJoinRequest
): Boolean = declineChatJoinRequest(chatJoinRequest) ) = declineChatJoinRequest(chatJoinRequest)
public suspend fun TelegramBot.declineChatJoinRequest( suspend fun TelegramBot.declineChatJoinRequest(
chatJoinRequestUpdate: ChatJoinRequestUpdate chatJoinRequestUpdate: ChatJoinRequestUpdate
): Boolean = declineChatJoinRequest(chatJoinRequestUpdate.data) ) = declineChatJoinRequest(chatJoinRequestUpdate.data)

View File

@@ -1,210 +1,183 @@
package dev.inmo.tgbotapi.extensions.api.chat.invite_links package dev.inmo.tgbotapi.extensions.api.chat.invite_links
import korlibs.time.DateTime import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.invite_links.EditChatInviteLink import dev.inmo.tgbotapi.requests.chat.invite_links.EditChatInviteLink
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.PublicChat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
public suspend fun TelegramBot.editChatInviteLinkUnlimited( suspend fun TelegramBot.editChatInviteLinkUnlimited(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: String, previousLink: String,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null expiration: TelegramDate? = null
): ChatInviteLinkUnlimited = execute(EditChatInviteLink.unlimited(chatId, previousLink, name, expiration)) ) = execute(EditChatInviteLink.unlimited(chatId, previousLink, name, expiration))
public suspend fun TelegramBot.editChatInviteLinkUnlimited( suspend fun TelegramBot.editChatInviteLinkUnlimited(
chat: PublicChat, chat: PublicChat,
previousLink: String, previousLink: String,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null, expiration: TelegramDate? = null,
): ChatInviteLinkUnlimited = editChatInviteLinkUnlimited(chat.id, previousLink, name, expiration) ) = editChatInviteLinkUnlimited(chat.id, previousLink, name, expiration)
public suspend fun TelegramBot.editChatInviteLinkUnlimited( suspend fun TelegramBot.editChatInviteLinkUnlimited(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: String, previousLink: String,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkUnlimited = editChatInviteLinkUnlimited(chatId, previousLink, name , expiration.toTelegramDate()) ) = editChatInviteLinkUnlimited(chatId, previousLink, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkUnlimited( suspend fun TelegramBot.editChatInviteLinkUnlimited(
chat: PublicChat, chat: PublicChat,
previousLink: String, previousLink: String,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkUnlimited = editChatInviteLinkUnlimited(chat.id, previousLink, name , expiration.toTelegramDate()) ) = editChatInviteLinkUnlimited(chat.id, previousLink, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: String, previousLink: String,
membersLimit: MembersLimit, membersLimit: MembersLimit,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null expiration: TelegramDate? = null
): ChatInviteLinkWithLimitedMembers = execute(EditChatInviteLink.withLimitedMembers(chatId, previousLink, membersLimit, name, expiration)) ) = execute(EditChatInviteLink.withLimitedMembers(chatId, previousLink, membersLimit, name, expiration))
public suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chat: PublicChat, chat: PublicChat,
previousLink: String, previousLink: String,
membersLimit: MembersLimit, membersLimit: MembersLimit,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null, expiration: TelegramDate? = null,
): ChatInviteLinkWithLimitedMembers = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name, expiration) ) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name, expiration)
public suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: String, previousLink: String,
membersLimit: MembersLimit, membersLimit: MembersLimit,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithLimitedMembers = editChatInviteLinkWithLimitedMembers(chatId, previousLink, membersLimit, name , expiration.toTelegramDate()) ) = editChatInviteLinkWithLimitedMembers(chatId, previousLink, membersLimit, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chat: PublicChat, chat: PublicChat,
previousLink: String, previousLink: String,
membersLimit: MembersLimit, membersLimit: MembersLimit,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithLimitedMembers = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name , expiration.toTelegramDate()) ) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkWithJoinRequest( suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: String, previousLink: String,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null expiration: TelegramDate? = null
): ChatInviteLinkWithJoinRequest = execute(EditChatInviteLink.withJoinRequest(chatId, previousLink, name, expiration)) ) = execute(EditChatInviteLink.withJoinRequest(chatId, previousLink, name, expiration))
public suspend fun TelegramBot.editChatInviteLinkWithJoinRequest( suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chat: PublicChat, chat: PublicChat,
previousLink: String, previousLink: String,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null, expiration: TelegramDate? = null,
): ChatInviteLinkWithJoinRequest = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name, expiration) ) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name, expiration)
public suspend fun TelegramBot.editChatInviteLinkWithJoinRequest( suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: String, previousLink: String,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithJoinRequest = editChatInviteLinkWithJoinRequest(chatId, previousLink, name , expiration.toTelegramDate()) ) = editChatInviteLinkWithJoinRequest(chatId, previousLink, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkWithJoinRequest( suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chat: PublicChat, chat: PublicChat,
previousLink: String, previousLink: String,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithJoinRequest = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name , expiration.toTelegramDate()) ) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkUnlimited( suspend fun TelegramBot.editChatInviteLinkUnlimited(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null expiration: TelegramDate? = null
): ChatInviteLinkUnlimited = editChatInviteLinkUnlimited(chatId, previousLink.inviteLink, name, expiration) ) = editChatInviteLinkUnlimited(chatId, previousLink.inviteLink, name, expiration)
public suspend fun TelegramBot.editChatInviteLinkUnlimited( suspend fun TelegramBot.editChatInviteLinkUnlimited(
chat: PublicChat, chat: PublicChat,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null, expiration: TelegramDate? = null,
): ChatInviteLinkUnlimited = editChatInviteLinkUnlimited(chat.id, previousLink, name, expiration) ) = editChatInviteLinkUnlimited(chat.id, previousLink, name, expiration)
public suspend fun TelegramBot.editChatInviteLinkUnlimited( suspend fun TelegramBot.editChatInviteLinkUnlimited(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkUnlimited = editChatInviteLinkUnlimited(chatId, previousLink, name, expiration.toTelegramDate()) ) = editChatInviteLinkUnlimited(chatId, previousLink, name, expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkUnlimited( suspend fun TelegramBot.editChatInviteLinkUnlimited(
chat: PublicChat, chat: PublicChat,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkUnlimited = editChatInviteLinkUnlimited(chat.id, previousLink, name , expiration.toTelegramDate()) ) = editChatInviteLinkUnlimited(chat.id, previousLink, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
membersLimit: MembersLimit, membersLimit: MembersLimit,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null expiration: TelegramDate? = null
): ChatInviteLinkWithLimitedMembers = editChatInviteLinkWithLimitedMembers(chatId, previousLink.inviteLink, membersLimit, name, expiration) ) = editChatInviteLinkWithLimitedMembers(chatId, previousLink.inviteLink, membersLimit, name, expiration)
public suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chat: PublicChat, chat: PublicChat,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
membersLimit: MembersLimit, membersLimit: MembersLimit,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null, expiration: TelegramDate? = null,
): ChatInviteLinkWithLimitedMembers = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name, expiration) ) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name, expiration)
public suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
membersLimit: MembersLimit, membersLimit: MembersLimit,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithLimitedMembers = editChatInviteLinkWithLimitedMembers(chatId, previousLink, membersLimit, name , expiration.toTelegramDate()) ) = editChatInviteLinkWithLimitedMembers(chatId, previousLink, membersLimit, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers( suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
chat: PublicChat, chat: PublicChat,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
membersLimit: MembersLimit, membersLimit: MembersLimit,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithLimitedMembers = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name , expiration.toTelegramDate()) ) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkWithJoinRequest( suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null expiration: TelegramDate? = null
): ChatInviteLinkWithJoinRequest = editChatInviteLinkWithJoinRequest(chatId, previousLink.inviteLink, name, expiration) ) = editChatInviteLinkWithJoinRequest(chatId, previousLink.inviteLink, name, expiration)
public suspend fun TelegramBot.editChatInviteLinkWithJoinRequest( suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chat: PublicChat, chat: PublicChat,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
name: String? = null, name: String? = null,
expiration: TelegramDate? = null, expiration: TelegramDate? = null,
): ChatInviteLinkWithJoinRequest = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name, expiration) ) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name, expiration)
public suspend fun TelegramBot.editChatInviteLinkWithJoinRequest( suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithJoinRequest = editChatInviteLinkWithJoinRequest(chatId, previousLink, name , expiration.toTelegramDate()) ) = editChatInviteLinkWithJoinRequest(chatId, previousLink, name , expiration.toTelegramDate())
public suspend fun TelegramBot.editChatInviteLinkWithJoinRequest( suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
chat: PublicChat, chat: PublicChat,
previousLink: ChatInviteLink, previousLink: ChatInviteLink,
expiration: DateTime, expiration: DateTime,
name: String? = null, name: String? = null,
): ChatInviteLinkWithJoinRequest = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name , expiration.toTelegramDate()) ) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name , expiration.toTelegramDate())
// Subscriptions
public suspend fun TelegramBot.editChatSubscriptionInviteLink(
chatId: ChatIdentifier,
previousLink: String,
name: String,
): ChatInviteLinkUnlimited = execute(EditChatInviteLink.subscription(chatId, previousLink, name))
public suspend fun TelegramBot.editChatSubscriptionInviteLink(
chatId: ChatIdentifier,
previousLink: ChatInviteLink,
name: String,
): ChatInviteLinkUnlimited = editChatSubscriptionInviteLink(chatId, previousLink.inviteLink, name)
public suspend fun TelegramBot.editChatSubscriptionInviteLink(
chat: PublicChat,
previousLink: String,
name: String,
): ChatInviteLinkUnlimited = editChatSubscriptionInviteLink(chat.id, previousLink, name)
public suspend fun TelegramBot.editChatSubscriptionInviteLink(
chat: PublicChat,
previousLink: ChatInviteLink,
name: String,
): ChatInviteLinkUnlimited = editChatSubscriptionInviteLink(chat.id, previousLink, name)

View File

@@ -4,25 +4,24 @@ import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.invite_links.RevokeChatInviteLink import dev.inmo.tgbotapi.requests.chat.invite_links.RevokeChatInviteLink
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.ChatInviteLink import dev.inmo.tgbotapi.types.ChatInviteLink
import dev.inmo.tgbotapi.types.SecondaryChatInviteLink import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.chat.PublicChat
public suspend fun TelegramBot.revokeChatInviteLink( suspend fun TelegramBot.revokeChatInviteLink(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: String previousLink: String
): SecondaryChatInviteLink = execute(RevokeChatInviteLink(chatId, previousLink)) ) = execute(RevokeChatInviteLink(chatId, previousLink))
public suspend fun TelegramBot.revokeChatInviteLink( suspend fun TelegramBot.revokeChatInviteLink(
chat: PublicChat, chat: PublicChat,
previousLink: String previousLink: String
): SecondaryChatInviteLink = revokeChatInviteLink(chat.id, previousLink) ) = revokeChatInviteLink(chat.id, previousLink)
public suspend fun TelegramBot.revokeChatInviteLink( suspend fun TelegramBot.revokeChatInviteLink(
chatId: ChatIdentifier, chatId: ChatIdentifier,
previousLink: ChatInviteLink previousLink: ChatInviteLink
): SecondaryChatInviteLink = revokeChatInviteLink(chatId, previousLink.inviteLink) ) = revokeChatInviteLink(chatId, previousLink.inviteLink)
public suspend fun TelegramBot.revokeChatInviteLink( suspend fun TelegramBot.revokeChatInviteLink(
chat: PublicChat, chat: PublicChat,
previousLink: ChatInviteLink previousLink: ChatInviteLink
): SecondaryChatInviteLink = revokeChatInviteLink(chat, previousLink.inviteLink) ) = revokeChatInviteLink(chat, previousLink.inviteLink)

View File

@@ -2,37 +2,33 @@ package dev.inmo.tgbotapi.extensions.api.chat.members
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.members.BanChatMember import dev.inmo.tgbotapi.requests.chat.members.BanChatMember
import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.TelegramDate
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.chat.PublicChat
import dev.inmo.tgbotapi.types.chat.User
public suspend fun TelegramBot.banChatMember( suspend fun TelegramBot.banChatMember(
chatId: ChatIdentifier, chatId: ChatIdentifier,
userId: UserId, userId: UserId,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
revokeMessages: Boolean? = null revokeMessages: Boolean? = null
): Boolean = execute(BanChatMember(chatId, userId, untilDate, revokeMessages)) ) = execute(BanChatMember(chatId, userId, untilDate, revokeMessages))
public suspend fun TelegramBot.banChatMember( suspend fun TelegramBot.banChatMember(
chat: PublicChat, chat: PublicChat,
userId: UserId, userId: UserId,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
revokeMessages: Boolean? = null revokeMessages: Boolean? = null
): Boolean = banChatMember(chat.id, userId, untilDate, revokeMessages) ) = banChatMember(chat.id, userId, untilDate, revokeMessages)
public suspend fun TelegramBot.banChatMember( suspend fun TelegramBot.banChatMember(
chatId: IdChatIdentifier, chatId: ChatId,
user: User, user: User,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
revokeMessages: Boolean? = null revokeMessages: Boolean? = null
): Boolean = banChatMember(chatId, user.id, untilDate, revokeMessages) ) = banChatMember(chatId, user.id, untilDate, revokeMessages)
public suspend fun TelegramBot.banChatMember( suspend fun TelegramBot.banChatMember(
chat: PublicChat, chat: PublicChat,
user: User, user: User,
untilDate: TelegramDate? = null, untilDate: TelegramDate? = null,
revokeMessages: Boolean? = null revokeMessages: Boolean? = null
): Boolean = banChatMember(chat.id, user.id, untilDate, revokeMessages) ) = banChatMember(chat.id, user.id, untilDate, revokeMessages)

Some files were not shown because too many files have changed in this diff Show More