mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
migration
This commit is contained in:
parent
24d11d2c2b
commit
f3fc0769ef
@ -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:
|
||||||
|
63
build.gradle
63
build.gradle
@ -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.19.0-kmpp-migration"
|
||||||
|
project.group = "com.github.insanusmokrassar"
|
||||||
|
|
||||||
apply from: "publish.gradle"
|
apply from: "publish.gradle"
|
||||||
|
|
||||||
@ -28,17 +29,49 @@ repositories {
|
|||||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvm()
|
||||||
|
// js()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation kotlin('stdlib')
|
||||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
||||||
api "com.soywiz.korlibs.klock:klock:$klock_version"
|
api "com.soywiz.korlibs.klock:klock:$klock_version"
|
||||||
|
|
||||||
api "io.ktor:ktor-client:$ktor_version"
|
api "io.ktor:ktor-client-core:$ktor_version"
|
||||||
api "io.ktor:ktor-client-cio:$ktor_version"
|
}
|
||||||
|
}
|
||||||
api "io.ktor:ktor-server:$ktor_version"
|
commonTest {
|
||||||
api "io.ktor:ktor-server-host-common:$ktor_version"
|
dependencies {
|
||||||
|
implementation kotlin('test-common')
|
||||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
|
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"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,55 +1,51 @@
|
|||||||
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'
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
afterEvaluate {
|
||||||
publications {
|
project.publishing.publications.all {
|
||||||
maven(MavenPublication) {
|
// rename artifacts
|
||||||
from components.java
|
|
||||||
groupId "${project.group}"
|
groupId "${project.group}"
|
||||||
artifactId "${project.name}"
|
if (it.name.contains('kotlinMultiplatform')) {
|
||||||
version "${project.version}"
|
artifactId = "${project.name}"
|
||||||
|
} else {
|
||||||
|
artifactId = "${project.name}-$name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
artifact sourcesJar
|
publishing {
|
||||||
artifact javadocJar
|
publications.all {
|
||||||
|
artifact javadocsJar
|
||||||
|
|
||||||
pom.withXml {
|
pom.withXml {
|
||||||
asNode().children().last() + {
|
asNode().children().last() + {
|
||||||
resolveStrategy = Closure.DELEGATE_FIRST
|
resolveStrategy = Closure.DELEGATE_FIRST
|
||||||
name "${project_public_name}"
|
|
||||||
description "${project_public_description}"
|
description "Library for Object-Oriented and type-safe work with Telegram Bot API"
|
||||||
url "https://insanusmokrassar.github.io/${project.name}"
|
name "Telegram Bot API"
|
||||||
|
url "https://insanusmokrassar.github.io/TelegramBotAPI"
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
1
mpp_publish_template.json
Normal file
1
mpp_publish_template.json
Normal 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"}]}}
|
@ -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
|
@ -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 {
|
@ -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
|
||||||
}
|
}
|
@ -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
|
||||||
)
|
)
|
||||||
|
|
@ -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,
|
@ -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(
|
@ -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
Loading…
Reference in New Issue
Block a user