first try

This commit is contained in:
InsanusMokrassar 2021-02-22 21:01:08 +06:00
parent 141cdc2625
commit d1c96ee2b9
7 changed files with 75 additions and 16 deletions

View File

@ -7,7 +7,8 @@ import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.libraries.cache.admins.micro_utils.DefaultAdminsCacheAPIRepo import dev.inmo.tgbotapi.libraries.cache.admins.micro_utils.DefaultAdminsCacheAPIRepo
import dev.inmo.tgbotapi.libraries.cache.admins.micro_utils.DynamicAdminsCacheSettingsAPI import dev.inmo.tgbotapi.libraries.cache.admins.micro_utils.DynamicAdminsCacheSettingsAPI
import dev.inmo.tgbotapi.types.toChatId import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.ChatMember.abstracts.AdministratorChatMember
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.serialization.cbor.Cbor import kotlinx.serialization.cbor.Cbor
import kotlinx.serialization.decodeFromByteArray import kotlinx.serialization.decodeFromByteArray
@ -20,14 +21,16 @@ private val serializationFormat = Cbor
fun AdminsCacheAPI( fun AdminsCacheAPI(
bot: TelegramBot, bot: TelegramBot,
database: Database, database: Database,
scope: CoroutineScope, scope: CoroutineScope
repo: dev.inmo.tgbotapi.libraries.cache.admins.DefaultAdminsCacheAPIRepo = DefaultAdminsCacheAPIRepo( ) : AdminsCacheAPI = DefaultAdminsCacheAPI(
bot,
DefaultAdminsCacheAPIRepo(
ExposedOneToManyKeyValueRepo( ExposedOneToManyKeyValueRepo(
database, database,
{ long("chatId") }, { long("chatId") },
{ blob("member") }, { blob("member") },
"AdminsTable" "AdminsTable"
).withMapper( ).withMapper<ChatId, AdministratorChatMember, Identifier, ExposedBlob>(
keyFromToTo = { chatId }, keyFromToTo = { chatId },
valueFromToTo = { ExposedBlob(serializationFormat.encodeToByteArray(this)) }, valueFromToTo = { ExposedBlob(serializationFormat.encodeToByteArray(this)) },
keyToToFrom = { toChatId() }, keyToToFrom = { toChatId() },
@ -38,19 +41,21 @@ fun AdminsCacheAPI(
{ long("chatId") }, { long("chatId") },
{ long("datetime") }, { long("datetime") },
"AdminsUpdatesTimesTable" "AdminsUpdatesTimesTable"
).withMapper( ).withMapper<ChatId, Long, Identifier, Long>(
keyFromToTo = { chatId }, keyFromToTo = { chatId },
keyToToFrom = { toChatId() } valueFromToTo = { this },
keyToToFrom = { toChatId() },
valueToToFrom = { this }
), ),
scope scope
), ),
settingsAPI: AdminsCacheSettingsAPI = DynamicAdminsCacheSettingsAPI( DynamicAdminsCacheSettingsAPI(
ExposedKeyValueRepo( ExposedKeyValueRepo(
database, database,
{ long("chatId") }, { long("chatId") },
{ blob("settings") }, { blob("settings") },
"DynamicAdminsCacheSettingsAPI" "DynamicAdminsCacheSettingsAPI"
).withMapper( ).withMapper<ChatId, AdminsCacheSettings, Identifier, ExposedBlob>(
keyFromToTo = { chatId }, keyFromToTo = { chatId },
valueFromToTo = { ExposedBlob(serializationFormat.encodeToByteArray(this)) }, valueFromToTo = { ExposedBlob(serializationFormat.encodeToByteArray(this)) },
keyToToFrom = { toChatId() }, keyToToFrom = { toChatId() },
@ -58,10 +63,6 @@ fun AdminsCacheAPI(
), ),
scope scope
) )
) : AdminsCacheAPI = DefaultAdminsCacheAPI(
bot,
repo,
settingsAPI
) )
fun BehaviourContext.AdminsCacheAPI(database: Database) = AdminsCacheAPI(this, database, this) fun BehaviourContext.AdminsCacheAPI(database: Database) = AdminsCacheAPI(this, database, this)

View File

@ -19,6 +19,6 @@ allprojects {
defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle" defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle"
// publishGradlePath = "${rootProject.projectDir.absolutePath}/publish.gradle" publishGradlePath = "${rootProject.projectDir.absolutePath}/publish.gradle"
} }
} }

View File

@ -1,7 +1,7 @@
project.version = "$version" project.version = "$version"
project.group = "$group" project.group = "$group"
// apply from: "$publishGradlePath" apply from: "$publishGradlePath"
kotlin { kotlin {
android { android {

View File

@ -1,7 +1,7 @@
project.version = "$version" project.version = "$version"
project.group = "$group" project.group = "$group"
// apply from: "$publishGradlePath" apply from: "$publishGradlePath"
kotlin { kotlin {
jvm { jvm {

View File

@ -1,7 +1,7 @@
project.version = "$version" project.version = "$version"
project.group = "$group" project.group = "$group"
// apply from: "$publishGradlePath" apply from: "$publishGradlePath"
kotlin { kotlin {
jvm { jvm {

57
publish.gradle Normal file
View File

@ -0,0 +1,57 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "${project.name}"
name = "${project.name}"
url = "https://github.com/InsanusMokrassar/TelegramBotApiLibraries"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git[push=]https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git"
url = "https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "MIT License"
url = "https://opensource.org/licenses/MIT"
}
}
}
repositories {
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')
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

1
publish_config.kpsb Normal file
View File

@ -0,0 +1 @@
{"licenses":[{"id":"MIT","title":"MIT License","url":"https://opensource.org/licenses/MIT"}],"mavenConfig":{"name":"${project.name}","description":"${project.name}","url":"https://github.com/InsanusMokrassar/TelegramBotApiLibraries","vcsUrl":"https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git","includeGpgSigning":true,"publishToMavenCentral":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}