1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

migration

This commit is contained in:
InsanusMokrassar 2019-12-03 11:07:25 +06:00
parent 24d11d2c2b
commit f3fc0769ef
449 changed files with 265 additions and 178 deletions

View File

@ -1,5 +1,13 @@
# 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
* Total rework of serialization for requests. Now all `SimpleRequest` children have:

View File

@ -1,6 +1,3 @@
project.version = "0.19.0"
project.group = "com.github.insanusmokrassar"
buildscript {
repositories {
mavenLocal()
@ -15,9 +12,13 @@ buildscript {
}
}
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'kotlinx-serialization'
plugins {
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
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"
@ -28,17 +29,49 @@ repositories {
maven { url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
api "com.soywiz.korlibs.klock:klock:$klock_version"
kotlin {
jvm()
// js()
api "io.ktor:ktor-client:$ktor_version"
api "io.ktor:ktor-client-cio:$ktor_version"
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib')
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
api "com.soywiz.korlibs.klock:klock:$klock_version"
api "io.ktor:ktor-server:$ktor_version"
api "io.ktor:ktor-server-host-common:$ktor_version"
api "io.ktor:ktor-client-core:$ktor_version"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
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"
// }
// }
}
}

View File

@ -1,56 +1,52 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
task javadocsJar(type: Jar) {
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 {
publications {
maven(MavenPublication) {
from components.java
groupId "${project.group}"
artifactId "${project.name}"
version "${project.version}"
publications.all {
artifact javadocsJar
artifact sourcesJar
artifact javadocJar
pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
name "${project_public_name}"
description "${project_public_description}"
url "https://insanusmokrassar.github.io/${project.name}"
pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
scm {
connection "scm:git:git://github.com/insanusmokrassar/${project.name}.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/${project.name}"
description "Library for Object-Oriented and type-safe work with Telegram Bot API"
name "Telegram Bot API"
url "https://insanusmokrassar.github.io/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 {
developers {
developer {
id "InsanusMokrassar"
name "Ovsyannikov Alexey"
name "Ovsiannikov Aleksei"
email "ovsyannikov.alexey95@gmail.com"
}
}
}
licenses {
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE'
distribution 'repo'
name "Apache Software License 2.0"
url "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
}
}
@ -59,5 +55,5 @@ publishing {
signing {
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'
ext {
projectBintrayDir = "${project.group}/".replace(".", "/") + "${project.name}/${project.version}"
}
apply from: "maven.publish.gradle"
bintray {
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')
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 {
repo = 'StandardRepository'
repo = "StandardRepository"
name = "${project.name}"
vcsUrl = "https://github.com/InsanusMokrassar/${project.name}"
licenses = ['Apache-2.0']
vcsUrl = "https://github.com/InsanusMokrassar/TelegramBotAPI"
licenses = ["Apache-2.0"]
version {
name = "${project.version}"
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 io.ktor.client.HttpClient
import io.ktor.client.call.HttpClientCall
import io.ktor.client.engine.HttpClientEngine
import io.ktor.util.cio.toByteArray
import io.ktor.client.call.receive
import kotlinx.coroutines.delay
import kotlinx.serialization.json.Json
@ -49,9 +48,7 @@ class KtorRequestsExecutor(
if (call == null) {
throw IllegalArgumentException("Can't execute request: $request")
}
val content = call.response.use {
it.content.toByteArray().toString(Charsets.UTF_8)
}
val content = call.response.receive<String>()
val responseObject = jsonFormatter.parse(Response.serializer(), content)
(responseObject.result ?.let {

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile
import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
import java.io.File
@Serializable(InputFileSerializer::class)
sealed class InputFile {
@ -40,7 +39,3 @@ data class MultipartFile (
) : InputFile() {
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