Merge pull request #4 from InsanusMokrassar/0.1.0

0.1.0
This commit is contained in:
InsanusMokrassar 2021-02-17 00:06:58 +06:00 committed by GitHub
commit 6dec930a9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 95 additions and 47 deletions

16
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,16 @@
name: Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Gradle
run: ./gradlew build

View File

@ -1,5 +1,17 @@
# Changelog
## 0.1.0
* `Versions`
* `kotlin`: `1.4.21` -> `1.4.30`
* `serialization`: `1.0.1` -> `1.1.0-RC`
* `exposed`: `0.28.1` -> `0.29.1`
* `tgbotapi`: `0.30.10` -> `0.32.5`
* `microutils`: `0.4.11` -> `0.4.25`
* `Plugin`
* New method `BehaviourContext#invoke`
* Old method `invoke` has been deprecated
## 0.0.5
* `Versions`

View File

@ -1 +1 @@
{"bintrayConfig":{"repo":"PlaguBot","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/PlaguBot","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/PlaguBot/LICENSE"}],"mavenConfig":{"name":"PlaguBot ${project.name}","description":"","url":"https://github.com/InsanusMokrassar/PlaguBot","vcsUrl":"ssh://git@github.com/InsanusMokrassar/PlaguBot.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"JVM"}
{"bintrayConfig":{"repo":"PlaguBot","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/PlaguBot","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/PlaguBot/LICENSE"}],"mavenConfig":{"name":"PlaguBot Bot","description":"Base PlaguBot project","url":"https://github.com/InsanusMokrassar/PlaguBot","vcsUrl":"ssh://git@github.com/InsanusMokrassar/PlaguBot.git","includeGpgSigning":true,"publishToMavenCentral":true,"developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"JVM"}

View File

@ -1,9 +1,6 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
@ -15,14 +12,13 @@ publishing {
maven(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
resolveStrategy = Closure.DELEGATE_FIRST
description = ""
name = "PlaguBot ${project.name}"
description = "Base PlaguBot project"
name = "PlaguBot Bot"
url = "https://github.com/InsanusMokrassar/PlaguBot"
scm {
@ -59,8 +55,23 @@ publishing {
password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
}
}
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
}

View File

@ -3,9 +3,10 @@ package dev.inmo.plagubot
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
import dev.inmo.plagubot.config.Config
import dev.inmo.plagubot.config.configSerialFormat
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
import dev.inmo.tgbotapi.extensions.api.telegramBot
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviour
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
import dev.inmo.tgbotapi.types.botCommandsLimit
import kotlinx.coroutines.*
import kotlinx.serialization.InternalSerializationApi
@ -17,9 +18,9 @@ suspend inline fun initPlaguBot(
) {
val bot = telegramBot(config.botToken)
bot.startGettingFlowsUpdatesByLongPolling(scope = scope) {
bot.buildBehaviour(scope) {
val commands = config.plugins.flatMap {
it.invoke(bot, config.database.database, this, scope)
it.apply { invoke(config.database.database) }
it.getCommands()
}.let {
val futureUnavailable = it.drop(botCommandsLimit.last)
@ -28,11 +29,7 @@ suspend inline fun initPlaguBot(
}
it.take(botCommandsLimit.last)
}
scope.launch {
safelyWithoutExceptions {
bot.setMyCommands(commands)
}
}
safelyWithoutExceptions { setMyCommands(commands) }
}
}

View File

@ -1,8 +1,6 @@
package dev.inmo.plagubot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import kotlinx.coroutines.CoroutineScope
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.jetbrains.exposed.sql.Database
@ -12,12 +10,7 @@ import org.jetbrains.exposed.sql.Database
data class HelloPlugin(
val parameter: String
) : Plugin {
override suspend fun invoke(
bot: TelegramBot,
database: Database,
updatesFilter: FlowsUpdatesFilter,
scope: CoroutineScope
) {
override suspend fun BehaviourContext.invoke(database: Database) {
println(parameter)
}
}

View File

@ -4,16 +4,16 @@ org.gradle.parallel=true
kotlin.js.generate.externals=true
kotlin.incremental=true
kotlin_version=1.4.21
kotlin_version=1.4.30
kotlin_coroutines_version=1.4.2
kotlin_serialisation_runtime_version=1.0.1
kotlin_exposed_version=0.28.1
tgbotapi_version=0.30.10
microutils_version=0.4.11
kotlin_serialisation_runtime_version=1.1.0-RC
kotlin_exposed_version=0.29.1
tgbotapi_version=0.32.5
microutils_version=0.4.25
klassindex_version=4.1.0-rc.1
sqlite_version=3.30.1
github_release_plugin_version=2.2.12
group=dev.inmo
version=0.0.5
version=0.1.0

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1 +1 @@
{"bintrayConfig":{"repo":"PlaguBot","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/PlaguBot","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/PlaguBot/LICENSE"}],"mavenConfig":{"name":"PlaguBot ${project.name}","description":"","url":"https://github.com/InsanusMokrassar/PlaguBot","vcsUrl":"ssh://git@github.com/InsanusMokrassar/PlaguBot.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"JVM"}
{"bintrayConfig":{"repo":"PlaguBot","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/PlaguBot","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/PlaguBot/LICENSE"}],"mavenConfig":{"name":"PlaguBot Plugin","description":"Base dependency for whole PlaguBot project","url":"https://github.com/InsanusMokrassar/PlaguBot","vcsUrl":"ssh://git@github.com/InsanusMokrassar/PlaguBot.git","includeGpgSigning":true,"publishToMavenCentral":true,"developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"JVM"}

View File

@ -1,9 +1,6 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
@ -15,14 +12,13 @@ publishing {
maven(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
resolveStrategy = Closure.DELEGATE_FIRST
description = ""
name = "PlaguBot ${project.name}"
description = "Base dependency for whole PlaguBot project"
name = "PlaguBot Plugin"
url = "https://github.com/InsanusMokrassar/PlaguBot"
scm {
@ -59,8 +55,23 @@ publishing {
password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
}
}
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
}

View File

@ -1,6 +1,7 @@
package dev.inmo.plagubot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.types.BotCommand
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import kotlinx.coroutines.CoroutineScope
@ -19,13 +20,20 @@ interface Plugin {
*/
suspend fun getCommands(): List<BotCommand> = emptyList()
/**
* This method (usually) will be invoked just one time in the whole application.
*/
@Deprecated("Override other method with receiver BehaviourContext")
suspend operator fun invoke(
bot: TelegramBot,
database: Database,
updatesFilter: FlowsUpdatesFilter,
scope: CoroutineScope
)
) {}
/**
* This method (usually) will be invoked just one time in the whole application.
*/
suspend operator fun BehaviourContext.invoke(
database: Database
) {
invoke(bot, database, flowsUpdatesFilter, scope)
}
}