1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-23 02:28:45 +00:00

Merge pull request #46 from InsanusMokrassar/0.20.0

0.20.0
This commit is contained in:
InsanusMokrassar 2019-12-06 16:28:29 +06:00 committed by GitHub
commit 0ef4341baf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
451 changed files with 335 additions and 208 deletions

View File

@ -1,5 +1,13 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 0.20.0 MPP Migration
* Time library change: `joda-time` -> `com.soywiz.korlibs.klock:klock`
* `Currencied` now using as `currency` value with type `String`
* For `Java` there is `Currencied#javaCurrency` extension function, which will give an old currency work way
* `User` now have no field `userLocale`
* For `Java` there is `User#javaLocale` extension function, which will give an old locale work way
## 0.19.0 ImplicitReflection removing ## 0.19.0 ImplicitReflection removing
* Total rework of serialization for requests. Now all `SimpleRequest` children have: * Total rework of serialization for requests. Now all `SimpleRequest` children have:

View File

@ -25,8 +25,30 @@ like inserting of additional libraries (like `kotlin stdlib`). In the examples w
[![Download](https://api.bintray.com/packages/insanusmokrassar/StandardRepository/TelegramBotAPI/images/download.svg) ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion) [![Download](https://api.bintray.com/packages/insanusmokrassar/StandardRepository/TelegramBotAPI/images/download.svg) ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion)
Currently, last versions of library are not included into the Maven repository (for the reason difficult in publishing
of signed artifacts in Bintray). You can:
* Use earlier version (available version you can find
[here](https://mvnrepository.com/artifact/com.github.insanusmokrassar/TelegramBotAPI))
* Add `jCenter` repository in build config
### Maven ### Maven
To use last versions you will need to add several lines in repositories block of your pom.xml:
```xml
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
```
Dependency config presented here:
```xml ```xml
<dependency> <dependency>
<groupId>com.github.insanusmokrassar</groupId> <groupId>com.github.insanusmokrassar</groupId>
@ -37,14 +59,22 @@ like inserting of additional libraries (like `kotlin stdlib`). In the examples w
### Gradle ### Gradle
To use last versions you will need to add one line in repositories block of your build.gradle:
```groovy ```groovy
implementation "com.github.insanusmokrassar:TelegramBotAPI:${telegrambotapi.version}" jcenter()
``` ```
### Gradle (old) And add next line to your dependencies block:
```groovy ```groovy
compile "com.github.insanusmokrassar:TelegramBotAPI:${telegrambotapi.version}" implementation "com.github.insanusmokrassar:TelegramBotAPI:$telegrambotapi_version"
```
or for old gradle:
```groovy
compile "com.github.insanusmokrassar:TelegramBotAPI:$telegrambotapi_version"
``` ```
## How to work with library? ## How to work with library?

View File

@ -1,6 +1,3 @@
project.version = "0.19.0"
project.group = "com.github.insanusmokrassar"
buildscript { buildscript {
repositories { repositories {
mavenLocal() mavenLocal()
@ -15,9 +12,13 @@ buildscript {
} }
} }
apply plugin: 'java-library' plugins {
apply plugin: 'kotlin' id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
apply plugin: 'kotlinx-serialization' id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
}
project.version = "0.20.0"
project.group = "com.github.insanusmokrassar"
apply from: "publish.gradle" apply from: "publish.gradle"
@ -28,17 +29,53 @@ repositories {
maven { url "https://kotlin.bintray.com/kotlinx" } maven { url "https://kotlin.bintray.com/kotlinx" }
} }
dependencies { kotlin {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" jvm()
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version" js()
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
api "joda-time:joda-time:$joda_time_version"
api "io.ktor:ktor-client:$ktor_version" sourceSets {
api "io.ktor:ktor-client-cio:$ktor_version" commonMain {
dependencies {
implementation kotlin('stdlib')
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version"
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
api "io.ktor:ktor-server:$ktor_version" api "com.soywiz.korlibs.klock:klock:$klock_version"
api "io.ktor:ktor-server-host-common:$ktor_version" api "com.benasher44:uuid:$uuid_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" api "io.ktor:ktor-client-core:$ktor_version"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
jvmMain {
dependencies {
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
api "io.ktor:ktor-client:$ktor_version"
api "io.ktor:ktor-server:$ktor_version"
api "io.ktor:ktor-server-host-common:$ktor_version"
api "io.ktor:ktor-client-cio:$ktor_version"
}
}
jvmTest {
dependencies {
implementation kotlin('test-junit')
}
}
jsMain {
dependencies {
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version"
api "io.ktor:ktor-client-js:$ktor_version"
}
}
}
} }

View File

@ -2,7 +2,8 @@ kotlin.code.style=official
kotlin_version=1.3.61 kotlin_version=1.3.61
kotlin_coroutines_version=1.3.2 kotlin_coroutines_version=1.3.2
kotlin_serialisation_runtime_version=0.14.0 kotlin_serialisation_runtime_version=0.14.0
joda_time_version=2.10.5 klock_version=1.8.0
uuid_version=0.0.6
ktor_version=1.2.6 ktor_version=1.2.6
gradle_bintray_plugin_version=1.8.4 gradle_bintray_plugin_version=1.8.4

View File

@ -1,56 +1,52 @@
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
apply plugin: 'signing' apply plugin: 'signing'
task sourcesJar(type: Jar) { task javadocsJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc' classifier = 'javadoc'
} }
afterEvaluate {
project.publishing.publications.all {
// rename artifacts
groupId "${project.group}"
if (it.name.contains('kotlinMultiplatform')) {
artifactId = "${project.name}"
} else {
artifactId = "${project.name}-$name"
}
}
}
publishing { publishing {
publications { publications.all {
maven(MavenPublication) { artifact javadocsJar
from components.java
groupId "${project.group}"
artifactId "${project.name}"
version "${project.version}"
artifact sourcesJar pom.withXml {
artifact javadocJar asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
pom.withXml { description "Library for Object-Oriented and type-safe work with Telegram Bot API"
asNode().children().last() + { name "Telegram Bot API"
resolveStrategy = Closure.DELEGATE_FIRST url "https://insanusmokrassar.github.io/TelegramBotAPI"
name "${project_public_name}"
description "${project_public_description}"
url "https://insanusmokrassar.github.io/${project.name}"
scm { scm {
connection "scm:git:git://github.com/insanusmokrassar/${project.name}.git" developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/${project.name}.git[push=]ssh:git@github.com:insanusmokrassar/${project.name}.git" url "https://github.com/insanusmokrassar/TelegramBotAPI.git"
url "https://github.com/insanusmokrassar/${project.name}" }
} developers {
developers {
developer { developer {
id "InsanusMokrassar" id "InsanusMokrassar"
name "Ovsyannikov Alexey" name "Ovsiannikov Aleksei"
email "ovsyannikov.alexey95@gmail.com" email "ovsyannikov.alexey95@gmail.com"
} }
} }
licenses { licenses {
license { license {
name 'The Apache Software License, Version 2.0' name "Apache Software License 2.0"
url 'https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE' url "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
distribution 'repo'
} }
}
} }
} }
} }
@ -59,5 +55,5 @@ publishing {
signing { signing {
useGpgCmd() useGpgCmd()
sign publishing.publications.maven sign(publishing.publications)
} }

View File

@ -0,0 +1 @@
{"bintrayConfig":{"repo":"StandardRepository","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI"},"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","description":"Library for Object-Oriented and type-safe work with Telegram Bot API","url":"https://insanusmokrassar.github.io/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}

View File

@ -1,33 +1,27 @@
apply plugin: 'com.jfrog.bintray' apply plugin: 'com.jfrog.bintray'
ext { apply from: "maven.publish.gradle"
projectBintrayDir = "${project.group}/".replace(".", "/") + "${project.name}/${project.version}"
}
bintray { bintray {
user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER') user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY') key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
publications = ["maven"]
filesSpec {
into "$projectBintrayDir"
from("build/libs") {
include "**/*.asc"
}
from("build/publications/maven") {
rename 'pom-default.xml(.*)', "${project.name}-${project.version}.pom\$1"
}
}
pkg { pkg {
repo = 'StandardRepository' repo = "StandardRepository"
name = "${project.name}" name = "${project.name}"
vcsUrl = "https://github.com/InsanusMokrassar/${project.name}" vcsUrl = "https://github.com/InsanusMokrassar/TelegramBotAPI"
licenses = ['Apache-2.0'] licenses = ["Apache-2.0"]
version { version {
name = "${project.version}" name = "${project.version}"
released = new Date() released = new Date()
vcsTag = name vcsTag = "${project.version}"
} }
} }
} }
apply from: "maven.publish.gradle" bintrayUpload.doFirst {
publications = publishing.publications.collect {
it.name
}
}
bintrayUpload.dependsOn publishToMavenLocal

View File

@ -12,8 +12,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.call.HttpClientCall import io.ktor.client.call.HttpClientCall
import io.ktor.client.engine.HttpClientEngine import io.ktor.client.call.receive
import io.ktor.util.cio.toByteArray
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
@ -49,9 +48,7 @@ class KtorRequestsExecutor(
if (call == null) { if (call == null) {
throw IllegalArgumentException("Can't execute request: $request") throw IllegalArgumentException("Can't execute request: $request")
} }
val content = call.response.use { val content = call.response.receive<String>()
it.content.toByteArray().toString(Charsets.UTF_8)
}
val responseObject = jsonFormatter.parse(Response.serializer(), content) val responseObject = jsonFormatter.parse(Response.serializer(), content)
(responseObject.result ?.let { (responseObject.result ?.let {

View File

@ -5,10 +5,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.call.HttpClientCall import io.ktor.client.call.HttpClientCall
import io.ktor.client.call.call import io.ktor.client.call.call
import io.ktor.client.request.accept import io.ktor.client.request.*
import io.ktor.client.request.url import io.ktor.http.*
import io.ktor.http.ContentType
import io.ktor.http.HttpMethod
abstract class AbstractRequestCallFactory : KtorCallFactory { abstract class AbstractRequestCallFactory : KtorCallFactory {
private val methodsCache: MutableMap<String, String> = mutableMapOf() private val methodsCache: MutableMap<String, String> = mutableMapOf()

View File

@ -21,14 +21,15 @@ class MultipartRequestCallFactory : AbstractRequestCallFactory() {
val params = castedRequest.paramsJson.mapWithCommonValues() val params = castedRequest.paramsJson.mapWithCommonValues()
for ((key, value) in castedRequest.mediaMap + params) { for ((key, value) in castedRequest.mediaMap + params) {
when (value) { when (value) {
is MultipartFile -> append( is MultipartFile -> appendInput(
key, key,
value.file.asInput().readBytes(),
Headers.build { Headers.build {
append(HttpHeaders.ContentType, value.mimeType) append(HttpHeaders.ContentType, value.mimeType)
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}") append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
} }
) ) {
value.file.asInput()
}
is FileId -> append(key, value.fileId) is FileId -> append(key, value.fileId)
else -> append(key, value.toString()) else -> append(key, value.toString())
} }

View File

@ -1,10 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot package com.github.insanusmokrassar.TelegramBotAPI.bot
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import kotlinx.io.core.Closeable import kotlinx.io.core.Closeable
interface RequestsExecutor : Closeable { interface RequestsExecutor : Closeable {
@Throws(RequestException::class) /**
* @throws com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
*/
suspend fun <T : Any> execute(request: Request<T>): T suspend fun <T : Any> execute(request: Request<T>): T
} }

View File

@ -1,7 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions
import com.github.insanusmokrassar.TelegramBotAPI.types.Response import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import java.io.IOException import kotlinx.io.errors.IOException
fun newRequestException( fun newRequestException(
response: Response, response: Response,
@ -20,7 +20,7 @@ sealed class RequestException constructor(
message: String? = null, message: String? = null,
cause: Throwable? = null cause: Throwable? = null
) : IOException( ) : IOException(
message, message ?: "Something went wrong",
cause cause
) )

View File

@ -1,9 +1,10 @@
package com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters package com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters
import com.soywiz.klock.DateTime
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
private fun now(): Long = System.currentTimeMillis() private fun now(): Long = DateTime.nowUnixLong()
class CommonLimiter( class CommonLimiter(
private val lockCount: Int = 10, private val lockCount: Int = 10,

View File

@ -4,8 +4,8 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient import kotlinx.serialization.Transient
import java.util.concurrent.Executors
import kotlin.coroutines.* import kotlin.coroutines.*
import kotlin.math.pow
private sealed class RequestEvent private sealed class RequestEvent
private class AddRequest( private class AddRequest(
@ -21,9 +21,7 @@ data class PowLimiter(
private val powK: Double = 0.0016 private val powK: Double = 0.0016
) : RequestLimiter { ) : RequestLimiter {
@Transient @Transient
private val scope = CoroutineScope( private val scope = CoroutineScope(Dispatchers.Default)
Executors.newFixedThreadPool(3).asCoroutineDispatcher()
)
@Transient @Transient
private val eventsChannel = Channel<RequestEvent>(Channel.UNLIMITED) private val eventsChannel = Channel<RequestEvent>(Channel.UNLIMITED)
@Transient @Transient
@ -35,7 +33,7 @@ data class PowLimiter(
for (event in eventsChannel) { for (event in eventsChannel) {
when (event) { when (event) {
is AddRequest -> { is AddRequest -> {
val awaitTime = ((Math.pow(requestsInWork, powValue) * powK) * 1000L).toLong() val awaitTime = (((requestsInWork.pow(powValue) * powK) * 1000L).toLong())
requestsInWork++ requestsInWork++
event.continuation.resume( event.continuation.resume(

View File

@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor import kotlinx.serialization.internal.StringDescriptor
import java.io.File
@Serializable(InputFileSerializer::class) @Serializable(InputFileSerializer::class)
sealed class InputFile { sealed class InputFile {
@ -40,7 +39,3 @@ data class MultipartFile (
) : InputFile() { ) : InputFile() {
override val fileId: String = file.generateCustomName() override val fileId: String = file.generateCustomName()
} }
fun File.toInputFile(): InputFile = MultipartFile(
StorageFile(this)
)

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